-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_assignments.py
executable file
·46 lines (37 loc) · 1.52 KB
/
update_assignments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3.6
"""Updates assignments when the cycle number is changed."""
# External imports
import json
import sys
# Internal imports
import firebase_communicator
import utils
# Uses default firebase URL
# DB stands for database
DB = firebase_communicator.configure_firebase()
if len(sys.argv) == 2:
CYCLE_NUMBER = sys.argv[1]
else:
print('Error: Cycle number not being passed as an argument. Exiting...')
sys.exit(0)
# Each scout name is associated with a letter (for compression).
# This opens the JSON file that stores the letters and loads the dict
# that is used to swap names with letters.
with open(utils.create_file_path('data/assignments/assignments.json'), 'r') as file:
LETTERS = json.load(file)['letters']
AVAILABILITY = DB.child('scoutManagement/availability').get().val()
AVAILABLE_SCOUTS = [scout for scout, availability in AVAILABILITY.items()
if availability == 1]
# The base assignment string
ASSIGNMENT_STRING = f'{CYCLE_NUMBER}_{firebase_communicator.URL}|'
with open(utils.create_file_path('data/sprs/sprs.json'), 'r') as file:
SPRS = json.load(file)
# Sorts scouts from best SPR to worst SPR
# Scouts without SPRs default to 0.0, since we want them to be placed
# with other scouts. (Scouts with a lower SPR are more likely to be in
# groups of 3)
AVAILABLE_SCOUTS.sort(key=lambda scout: SPRS.get(scout, {}).get(
'overall', 0.0), reverse=True)
for scout in AVAILABLE_SCOUTS:
ASSIGNMENT_STRING += LETTERS[scout]
DB.child('scoutManagement/QRcode').set(ASSIGNMENT_STRING)