Add next and last class to home stats

This commit is contained in:
Tanner Collin 2022-03-17 19:50:57 +00:00
parent 093ce1747c
commit 64cf1eeaa0
3 changed files with 37 additions and 1 deletions

View File

@ -18,6 +18,8 @@ DEFAULTS = {
'last_card_change': time.time(),
'next_meeting': None,
'next_clean': None,
'next_class': None,
'prev_class': None,
'member_count': None,
'paused_count': None,
'green_count': None,
@ -44,8 +46,11 @@ def changed_card():
def calc_next_events():
sessions = models.Session.objects
# TODO, go by tag?
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()
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:
cache.set('next_meeting', member_meeting.datetime)
@ -57,6 +62,17 @@ def calc_next_events():
else:
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():
members = models.Member.objects
not_paused = members.filter(paused_date__isnull=True)

View File

@ -189,6 +189,19 @@ export function Home(props) {
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 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 mumbleUsers = stats && stats['mumble_users'] ? stats['mumble_users'] : [];
@ -239,8 +252,9 @@ export function Home(props) {
<Header size='medium'>Protospace Stats</Header>
<p>Next member meeting: {getDateStat('next_meeting')}</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>Green members: {getStat('green_count')}</p>
<p>Card scans today: {getZeroStat('card_scans')}</p>
<p>

View File

@ -151,6 +151,12 @@ body {
margin-bottom: 0.5em;
}
.nowrap-stat {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.footer {
margin-top: -20rem;