Add monthly most host to LCARS display
This commit is contained in:
parent
8baf204516
commit
4b12ea0d6d
|
@ -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]
|
||||
|
|
|
@ -34,10 +34,6 @@ export function LCARS1Display(props) {
|
|||
</p>
|
||||
}
|
||||
|
||||
<div className='display-scores'>
|
||||
<DisplayScores />
|
||||
</div>
|
||||
|
||||
<div className='display-scores'>
|
||||
<DisplayMonthlyScores />
|
||||
</div>
|
||||
|
@ -46,6 +42,10 @@ export function LCARS1Display(props) {
|
|||
<DisplayHosting />
|
||||
</div>
|
||||
|
||||
<div className='display-scores'>
|
||||
<DisplayMonthlyHosting />
|
||||
</div>
|
||||
|
||||
<div className='display-usage'>
|
||||
<DisplayUsage token={token} name={'trotec'} />
|
||||
</div>
|
||||
|
@ -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 (
|
||||
<>
|
||||
<Header size='large'>Monthly Most Host</Header>
|
||||
|
||||
{scores && scores.slice(0, 5).map((x, i) =>
|
||||
<div key={i}>
|
||||
<Header size='medium'>#{i+1} — {x.name}. {i === 0 ? '🚀' : ''}</Header>
|
||||
<p>{x.hours.toFixed(2)} hours</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user