Display who used the lasers last

This commit is contained in:
Tanner Collin 2020-09-20 00:23:27 +00:00
parent 1cdb236a7e
commit 3bf8743e9a
2 changed files with 14 additions and 6 deletions

View File

@ -472,7 +472,12 @@ class StatsViewSet(viewsets.ViewSet, List):
def track(self, request):
if 'name' in request.data:
track = cache.get('track', {})
track[request.data['name']] = time.time()
name = request.data['name']
username = request.data.get('username', '')
username = username.split('.')[0]
track[name] = dict(time=time.time(), username=username)
cache.set('track', track)
return Response(200)
else:

View File

@ -153,9 +153,10 @@ export function Home(props) {
const mcPlayers = stats && stats['minecraft_players'] ? stats['minecraft_players'] : [];
const getTrackStat = (x) => stats && stats.track && stats.track[x] ? moment().unix() - stats.track[x] > 60 ? 'Free' : 'In Use' : '?';
const getTrackLast = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]).tz('America/Edmonton').format('llll') : 'Unknown';
const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]).tz('America/Edmonton').fromNow() : '';
const getTrackStat = (x) => stats && stats.track && stats.track[x] ? moment().unix() - stats.track[x]['time'] > 60 ? 'Free' : 'In Use' : '?';
const getTrackLast = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').format('llll') : 'Unknown';
const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').fromNow() : '';
const getTrackName = (x) => stats && stats.track && stats.track[x] && stats.track[x]['username'] ? stats.track[x]['username'] : 'Unknown';
return (
<Container>
@ -238,7 +239,8 @@ export function Home(props) {
<p>
Last use:<br />
{getTrackLast('TROTECS300')}<br />
{getTrackAgo('TROTECS300')}
{getTrackAgo('TROTECS300')}<br />
by {getTrackName('TROTECS300')}
</p>
</React.Fragment>
} trigger={<a>[more]</a>} />
@ -250,7 +252,8 @@ export function Home(props) {
<p>
Last use:<br />
{getTrackLast('FRICKIN-LASER')}<br />
{getTrackAgo('FRICKIN-LASER')}
{getTrackAgo('FRICKIN-LASER')}<br />
by {getTrackName('TROTECS300')}
</p>
</React.Fragment>
} trigger={<a>[more]</a>} />