Skip to content

Commit

Permalink
Add some commented code for a leaderboards view
Browse files Browse the repository at this point in the history
  • Loading branch information
jvacek committed May 7, 2023
1 parent 696a057 commit dc4a1f8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions flamerelay/backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,33 @@ class Meta:

context = {"form": form}
return render(request, "backend/checkin_create.html", context)


# TODO see if this could be fun
# def leaderboards_view(request):
# from django.utils import timezone
# units = Unit.objects.all()
# # 10 units with most checkins
# units_top_checkins = sorted(units, key=lambda x: len(x.checkin_set.all()), reverse=True)[:10]
# # 10 units with most subscribers
# units_top_subscribers = sorted(units, key=lambda x: len(x.subscribers.all()), reverse=True)[:10]
# # 10 units with most checkins in the last month
# units_top_checkins_last_month = sorted(
# units,
# key=lambda x: len(x.checkin_set.filter(date_created__gte=timezone.now() - timezone.timedelta(days=30))),
# reverse=True,
# )[:10]
# # 10 units with the longest duistance travelled based on checkin location
# units_top_distance = sorted(
# units,
# key=lambda x: sum([x.location.distance(y.location) for y in x.checkin_set.all() if y.location]),
# reverse=True,
# )[:10]

# context = {
# "units_top_checkins": units_top_checkins,
# "units_top_subscribers": units_top_subscribers,
# "units_top_checkins_last_month": units_top_checkins_last_month,
# "units_top_distance": units_top_distance,
# }
# return render(request, "backend/leaderboards.html", context=context)

0 comments on commit dc4a1f8

Please sign in to comment.