Add next and last class to home stats
This commit is contained in:
parent
093ce1747c
commit
64cf1eeaa0
|
@ -18,6 +18,8 @@ DEFAULTS = {
|
||||||
'last_card_change': time.time(),
|
'last_card_change': time.time(),
|
||||||
'next_meeting': None,
|
'next_meeting': None,
|
||||||
'next_clean': None,
|
'next_clean': None,
|
||||||
|
'next_class': None,
|
||||||
|
'prev_class': None,
|
||||||
'member_count': None,
|
'member_count': None,
|
||||||
'paused_count': None,
|
'paused_count': None,
|
||||||
'green_count': None,
|
'green_count': None,
|
||||||
|
@ -44,8 +46,11 @@ def changed_card():
|
||||||
def calc_next_events():
|
def calc_next_events():
|
||||||
sessions = models.Session.objects
|
sessions = models.Session.objects
|
||||||
|
|
||||||
|
# TODO, go by tag?
|
||||||
member_meeting = sessions.filter(is_cancelled=False, course__in=[317, 413], datetime__gte=now()).first()
|
member_meeting = sessions.filter(is_cancelled=False, course__in=[317, 413], datetime__gte=now()).first()
|
||||||
monthly_clean = sessions.filter(is_cancelled=False, course=273, datetime__gte=now()).first()
|
monthly_clean = sessions.filter(is_cancelled=False, course=273, datetime__gte=now()).first()
|
||||||
|
next_class = sessions.exclude(course__in=[317, 413]).filter(is_cancelled=False, datetime__gte=now()).order_by('datetime').first()
|
||||||
|
prev_class = sessions.exclude(course__in=[317, 413]).filter(is_cancelled=False, datetime__lte=now()).order_by('datetime').last()
|
||||||
|
|
||||||
if member_meeting:
|
if member_meeting:
|
||||||
cache.set('next_meeting', member_meeting.datetime)
|
cache.set('next_meeting', member_meeting.datetime)
|
||||||
|
@ -57,6 +62,17 @@ def calc_next_events():
|
||||||
else:
|
else:
|
||||||
cache.set('next_clean', None)
|
cache.set('next_clean', None)
|
||||||
|
|
||||||
|
if next_class:
|
||||||
|
cache.set('next_class', dict(datetime=next_class.datetime, id=next_class.id, name=next_class.course.name))
|
||||||
|
else:
|
||||||
|
cache.set('next_class', None)
|
||||||
|
|
||||||
|
if prev_class:
|
||||||
|
cache.set('prev_class', dict(datetime=prev_class.datetime, id=prev_class.id, name=prev_class.course.name))
|
||||||
|
else:
|
||||||
|
cache.set('prev_class', None)
|
||||||
|
|
||||||
|
|
||||||
def calc_member_counts():
|
def calc_member_counts():
|
||||||
members = models.Member.objects
|
members = models.Member.objects
|
||||||
not_paused = members.filter(paused_date__isnull=True)
|
not_paused = members.filter(paused_date__isnull=True)
|
||||||
|
|
|
@ -189,6 +189,19 @@ export function Home(props) {
|
||||||
const getZeroStat = (x) => stats && stats[x] ? stats[x] : '0';
|
const getZeroStat = (x) => stats && stats[x] ? stats[x] : '0';
|
||||||
const getDateStat = (x) => stats && stats[x] ? moment.utc(stats[x]).tz('America/Edmonton').format('MMM Do @ LT') : 'Unknown';
|
const getDateStat = (x) => stats && stats[x] ? moment.utc(stats[x]).tz('America/Edmonton').format('MMM Do @ LT') : 'Unknown';
|
||||||
|
|
||||||
|
const getNextStat = (x) => {
|
||||||
|
if (stats && stats[x]) {
|
||||||
|
const datetime = moment.utc(stats[x].datetime).tz('America/Edmonton');
|
||||||
|
if (datetime.isSame(moment().tz('America/Edmonton'), 'day') ) {
|
||||||
|
return <>{datetime.format('LT')} | <Link to={'/classes/' + stats[x].id}>{stats[x].name}</Link></>;
|
||||||
|
} else {
|
||||||
|
return <>{datetime.format('MMM Do')} | <Link to={'/classes/' + stats[x].id}>{stats[x].name}</Link></>;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const mcPlayers = stats && stats['minecraft_players'] ? stats['minecraft_players'] : [];
|
const mcPlayers = stats && stats['minecraft_players'] ? stats['minecraft_players'] : [];
|
||||||
const mumbleUsers = stats && stats['mumble_users'] ? stats['mumble_users'] : [];
|
const mumbleUsers = stats && stats['mumble_users'] ? stats['mumble_users'] : [];
|
||||||
|
|
||||||
|
@ -239,8 +252,9 @@ export function Home(props) {
|
||||||
<Header size='medium'>Protospace Stats</Header>
|
<Header size='medium'>Protospace Stats</Header>
|
||||||
<p>Next member meeting: {getDateStat('next_meeting')}</p>
|
<p>Next member meeting: {getDateStat('next_meeting')}</p>
|
||||||
<p>Next monthly clean: {getDateStat('next_clean')}</p>
|
<p>Next monthly clean: {getDateStat('next_clean')}</p>
|
||||||
|
<p className='nowrap-stat'>Next class: {getNextStat('next_class')}</p>
|
||||||
|
<p className='nowrap-stat'>Last class: {getNextStat('prev_class')}</p>
|
||||||
<p>Member count: {getStat('member_count')} <Link to='/charts'>[more]</Link></p>
|
<p>Member count: {getStat('member_count')} <Link to='/charts'>[more]</Link></p>
|
||||||
<p>Green members: {getStat('green_count')}</p>
|
|
||||||
<p>Card scans today: {getZeroStat('card_scans')}</p>
|
<p>Card scans today: {getZeroStat('card_scans')}</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -151,6 +151,12 @@ body {
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nowrap-stat {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
margin-top: -20rem;
|
margin-top: -20rem;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user