Display pinball scores on LCARS1

This commit is contained in:
Tanner Collin 2023-01-18 01:01:27 +00:00
parent 8905735886
commit 682feeacf7
4 changed files with 79 additions and 11 deletions

View File

@ -1345,6 +1345,23 @@ class PinballViewSet(Base):
)
return Response(res)
@action(detail=False, methods=['get'])
def high_scores(self, request):
members = models.Member.objects.all()
members = members.annotate(
pinball_score=Max('user__scores__score'),
).exclude(pinball_score__isnull=True).order_by('-pinball_score')[:5]
scores = []
for member in members:
scores.append(dict(
name=member.preferred_name + ' ' + member.last_name[0],
score=member.pinball_score,
))
return Response(scores)
class RegistrationView(RegisterView):
serializer_class = serializers.MyRegisterSerializer

View File

@ -26,6 +26,8 @@ export function Debug(props) {
<p><Link to='/usage/trotec'>Trotec Usage</Link></p>
<p><Link to='/display/lcars1'>LCARS1 Display</Link></p>
</Container>
);

View File

@ -34,7 +34,9 @@ export function LCARS1Display(props) {
</p>
}
<div></div>
<div className='display-scores'>
<DisplayScores />
</div>
<div className='display-usage'>
<DisplayUsage token={token} name={'trotec'} />
@ -71,17 +73,51 @@ export function DisplayUsage(props) {
return (
<>
<Header size='large'>Trotec Usage</Header>
{showUsage ?
<TrotecUsage usage={usage} />
:
<>
<Header size='medium'>Trotec Usage</Header>
<p className='stat'>
Waiting for job
</p>
</>
<p className='stat'>
Waiting for job
</p>
}
</>
);
};
export function DisplayScores(props) {
const { token, name } = props;
const [scores, setScores] = useState(false);
const getScores = () => {
requester('/pinball/high_scores/', 'GET')
.then(res => {
setScores(res);
})
.catch(err => {
console.log(err);
setScores(false);
});
};
useEffect(() => {
getScores();
const interval = setInterval(getScores, 60000);
return () => clearInterval(interval);
}, []);
return (
<>
<Header size='large'>Pinball High Scores</Header>
{scores && scores.map((x, i) =>
<div key={i}>
<Header size='medium'>#{i+1} {x.name}.</Header>
<p>{x.score.toLocaleString()}</p>
</div>
)}
</>
);
};

View File

@ -179,15 +179,28 @@ body {
height: 100vh;
background-color: black;
color: white;
font-size: 1em;
font-size: 1.5em;
}
.display-usage {
border: 1px solid white;
padding: 0.5em;
align-self: flex-end;
width: 240px;
height: 383px;
width: 25vw;
height: 75vh;
}
.display-scores {
border: 1px solid white;
padding: 0.5em;
align-self: flex-end;
width: 25vw;
height: 75vh;
}
.display-scores p {
font-size: 1.5em;
text-align: right;
}
.usage {