Coverage for events/utils.py: 29%

7 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-10-11 16:16 -0500

1from django.db.models import Count, Max, Q 

2 

3 

4def scavenger_hunt_order_teams(station_checkin): 

5 challenge = station_checkin.station.challenge 

6 event = challenge.event 

7 

8 station_filter = Q( 

9 check_ins__station__challenge=challenge, check_ins__has_checkin=True 

10 ) 

11 

12 order = ( 

13 event.teams.all() 

14 .annotate( 

15 num_checkins=Count( 

16 "check_ins", 

17 filter=station_filter, 

18 ) 

19 ) 

20 .annotate( 

21 time_checkins=Max( 

22 "check_ins__updated_at", 

23 filter=station_filter, 

24 ) 

25 ) 

26 .filter(num_checkins__gt=0) 

27 .order_by("-num_checkins", "time_checkins") 

28 ) 

29 

30 return order