post-game update prepare
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.shortcuts import render
|
||||
from django.db.models import Avg
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from playlist.models import Session, Profile, Track, Vote
|
||||
@@ -37,4 +38,5 @@ class SessionInfoView(APIView):
|
||||
def get(self, request, session_id):
|
||||
track_count = len(Track.objects.all())
|
||||
vote_count = len(Vote.objects.all())
|
||||
return Response({'track_count': track_count, 'vote_count': vote_count})
|
||||
average_vote = Vote.objects.all().aggregate(Avg("points", default=0))['points__avg']
|
||||
return Response({'track_count': track_count, 'vote_count': vote_count, 'average_vote': average_vote})
|
||||
|
||||
@@ -7,12 +7,14 @@ export default function PostGame() {
|
||||
const { sessionId, setSessionId } = useSession();
|
||||
const [trackCount, setTrackCount] = useState(0);
|
||||
const [voteCount, setVoteCount] = useState(0);
|
||||
const [averageVote, setAverageVote] = useState(0);
|
||||
|
||||
async function getInfo() {
|
||||
const { data: info } = await api.sessions.info({ session_id: sessionId });
|
||||
console.log(info);
|
||||
setTrackCount(info["track_count"]);
|
||||
setVoteCount(info["vote_count"]);
|
||||
setAverageVote(info["average_vote"]);
|
||||
}
|
||||
useEffect(() => {
|
||||
getInfo();
|
||||
@@ -21,11 +23,9 @@ export default function PostGame() {
|
||||
return (
|
||||
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
||||
<h1>Post-game</h1>
|
||||
<p>Bedankt voor het stemmen!</p>
|
||||
<p>;)</p>
|
||||
<p>Piemels</p>
|
||||
<p>{trackCount} tracks</p>
|
||||
<p>{voteCount} votes</p>
|
||||
<p>{averageVote} average vote</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user