From 4b12ea0d6dd2a3a048e5ad7d4232628bc6a54ea6 Mon Sep 17 00:00:00 2001
From: Tanner Collin
Date: Sat, 15 Jul 2023 19:04:14 +0000
Subject: [PATCH] Add monthly most host to LCARS display
---
apiserver/apiserver/api/views.py | 21 +++++++++++++++
webclient/src/Display.js | 44 +++++++++++++++++++++++++++++---
2 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py
index 1729c6c..8719205 100644
--- a/apiserver/apiserver/api/views.py
+++ b/apiserver/apiserver/api/views.py
@@ -1823,6 +1823,27 @@ class HostingViewSet(Base):
return Response(hours)
+ @action(detail=False, methods=['get'])
+ def monthly_high_scores(self, request):
+ now = utils.now_alberta_tz()
+ current_month_start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
+
+ members = models.Member.objects.all()
+ members = members.annotate(
+ hosting_hours=Max('user__hosting__hours', filter=Q(user__hosting__finished_at__gte=current_month_start)),
+ ).exclude(hosting_hours__isnull=True).order_by('-hosting_hours')
+
+ scores = []
+
+ for member in members:
+ scores.append(dict(
+ name=member.preferred_name + ' ' + member.last_name[0],
+ hours=member.hosting_hours,
+ member_id=member.id,
+ ))
+
+ return Response(scores)
+
class StorageSpaceViewSet(Base, List, Retrieve, Update):
permission_classes = [AllowMetadata | IsAuthenticated, IsAdminOrReadOnly]
diff --git a/webclient/src/Display.js b/webclient/src/Display.js
index a4388f9..b51f2d0 100644
--- a/webclient/src/Display.js
+++ b/webclient/src/Display.js
@@ -34,10 +34,6 @@ export function LCARS1Display(props) {
}
-
-
-
-
@@ -46,6 +42,10 @@ export function LCARS1Display(props) {
+
+
+
+
@@ -239,3 +239,39 @@ export function DisplayHosting(props) {
>
);
};
+
+export function DisplayMonthlyHosting(props) {
+ const { token, name } = props;
+ const [scores, setScores] = useState(false);
+
+ const getScores = () => {
+ requester('/hosting/monthly_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 (
+ <>
+
+
+ {scores && scores.slice(0, 5).map((x, i) =>
+
+
#{i+1} — {x.name}. {i === 0 ? '🚀' : ''}
+
{x.hours.toFixed(2)} hours
+
+ )}
+
+ >
+ );
+};