|
@@ -24,8 +24,8 @@ def get_slot_count( event ) -> int :
|
|
""" Get the number of slots in an event. """
|
|
""" Get the number of slots in an event. """
|
|
|
|
|
|
# Get the timespan of the event
|
|
# Get the timespan of the event
|
|
- start_time = datetime.datetime.combine(datetime.date.today(), event.end_time)
|
|
|
|
- end_time = datetime.datetime.combine(datetime.date.today(), event.start_time)
|
|
|
|
|
|
+ start_time = datetime.datetime.combine(datetime.date.today(), event.start_time)
|
|
|
|
+ end_time = datetime.datetime.combine(datetime.date.today(), event.end_time)
|
|
timespan = abs(end_time - start_time)
|
|
timespan = abs(end_time - start_time)
|
|
|
|
|
|
# Get the number of slots in the event
|
|
# Get the number of slots in the event
|
|
@@ -40,45 +40,41 @@ def slots2grid( event : Event ) -> dict :
|
|
n_slots = get_slot_count(event)
|
|
n_slots = get_slot_count(event)
|
|
|
|
|
|
data = {
|
|
data = {
|
|
- 'days': [],
|
|
|
|
'rows': [],
|
|
'rows': [],
|
|
|
|
+ 'days': [],
|
|
|
|
+ 'slot_height': 30 * (event.slot_interval.total_seconds() / 3600),
|
|
|
|
+ 'n_days': event.date_set.count(),
|
|
}
|
|
}
|
|
# Get the timespan of the event
|
|
# Get the timespan of the event
|
|
- start_time = datetime.datetime.combine(datetime.date.today(), event.end_time)
|
|
|
|
- end_time = datetime.datetime.combine(datetime.date.today(), event.start_time)
|
|
|
|
|
|
+ start_time = datetime.datetime.combine(datetime.date.today(), event.start_time)
|
|
|
|
+ end_time = datetime.datetime.combine(datetime.date.today(), event.end_time)
|
|
timespan = abs(end_time - start_time)
|
|
timespan = abs(end_time - start_time)
|
|
|
|
|
|
# Get the slots in a day
|
|
# Get the slots in a day
|
|
- slots_per_day = timespan.total_seconds() // event.slot_interval.total_seconds()
|
|
|
|
-
|
|
|
|
- # Fill the rows of the grid
|
|
|
|
- last_hour = None
|
|
|
|
- for i in range(slots_per_day):
|
|
|
|
- current_time = start_time + i * event.slot_interval
|
|
|
|
- data['rows'].append({
|
|
|
|
- 'time': current_time,
|
|
|
|
- 'is_full_hour': current_time.hour != last_hour,
|
|
|
|
- })
|
|
|
|
- last_hour = current_time.hour
|
|
|
|
|
|
+ slots_per_day = int(timespan.total_seconds() // event.slot_interval.total_seconds())
|
|
|
|
|
|
# Get the slots of each day
|
|
# Get the slots of each day
|
|
participants = event.participant_set.all()
|
|
participants = event.participant_set.all()
|
|
participant_slot_strings = [slots2string(participant, n_slots) for participant in participants]
|
|
participant_slot_strings = [slots2string(participant, n_slots) for participant in participants]
|
|
- max_occupancy = 0
|
|
|
|
|
|
+ max_occupancy = 1
|
|
|
|
|
|
- for date in event.date_set.all():
|
|
|
|
|
|
+ for n, date in enumerate(event.date_set.all()):
|
|
# Get participants for each slot
|
|
# Get participants for each slot
|
|
slot_participants = [[] for i in range(slots_per_day)]
|
|
slot_participants = [[] for i in range(slots_per_day)]
|
|
for i, participant in enumerate(participants):
|
|
for i, participant in enumerate(participants):
|
|
for j in range(slots_per_day):
|
|
for j in range(slots_per_day):
|
|
- if participant_slot_strings[i][j] == '1':
|
|
|
|
|
|
+ if participant_slot_strings[i][n*slots_per_day + j] == '1':
|
|
slot_participants[j].append(participant)
|
|
slot_participants[j].append(participant)
|
|
# Fill the slots of the day
|
|
# Fill the slots of the day
|
|
slots = []
|
|
slots = []
|
|
- for ps in slot_participants:
|
|
|
|
|
|
+ for j, ps in enumerate(slot_participants):
|
|
|
|
+ slot_begin = (start_time + j * event.slot_interval).strftime('%H:%M')
|
|
|
|
+ slot_end = (start_time + (j+1) * event.slot_interval).strftime('%H:%M')
|
|
slots.append({
|
|
slots.append({
|
|
- 'tooltip': ', '.join([p.user.username for p in ps]),
|
|
|
|
|
|
+ 'tooltip': f"{slot_begin} - {slot_end} \n{', '.join([p.user.username for p in ps])}",
|
|
'occupancy': len(ps),
|
|
'occupancy': len(ps),
|
|
|
|
+ 'offset': n*slots_per_day + j,
|
|
|
|
+ 'date': date.date,
|
|
})
|
|
})
|
|
max_occupancy = max(max_occupancy, len(ps))
|
|
max_occupancy = max(max_occupancy, len(ps))
|
|
|
|
|
|
@@ -87,3 +83,27 @@ def slots2grid( event : Event ) -> dict :
|
|
'slots': slots,
|
|
'slots': slots,
|
|
}
|
|
}
|
|
data['days'].append(day)
|
|
data['days'].append(day)
|
|
|
|
+
|
|
|
|
+ # Fill the rows of the grid
|
|
|
|
+ last_hour = None
|
|
|
|
+ for i in range(slots_per_day):
|
|
|
|
+ current_time = start_time + i * event.slot_interval
|
|
|
|
+ data['rows'].append({
|
|
|
|
+ 'days': [day['slots'][i] for day in data['days']],
|
|
|
|
+ 'time': current_time,
|
|
|
|
+ 'is_full_hour': current_time.hour != last_hour,
|
|
|
|
+ })
|
|
|
|
+ last_hour = current_time.hour
|
|
|
|
+ data['rows'].append({
|
|
|
|
+ 'days': [None for day in data['days']],
|
|
|
|
+ 'time': end_time,
|
|
|
|
+ 'is_full_hour': True,
|
|
|
|
+ })
|
|
|
|
+ data['max_value'] = max_occupancy
|
|
|
|
+
|
|
|
|
+ # create a color for each slot from white to dark green
|
|
|
|
+ for row in data['rows']:
|
|
|
|
+ for day in row['days']:
|
|
|
|
+ if day is not None:
|
|
|
|
+ day['color'] = f"hsl(120, 100%, {100 - 70 * day['occupancy'] / max_occupancy}%)"
|
|
|
|
+ return data
|