|
@@ -42,7 +42,7 @@ def slots2grid( event : Event ) -> dict :
|
|
data = {
|
|
data = {
|
|
'rows': [],
|
|
'rows': [],
|
|
'days': [],
|
|
'days': [],
|
|
- 'slot_height': 30 * (event.slot_interval.total_seconds() / 3600),
|
|
|
|
|
|
+ 'colors': [],
|
|
'n_days': event.date_set.count(),
|
|
'n_days': event.date_set.count(),
|
|
}
|
|
}
|
|
# Get the timespan of the event
|
|
# Get the timespan of the event
|
|
@@ -67,16 +67,24 @@ def slots2grid( event : Event ) -> dict :
|
|
slot_participants[j].append(participant)
|
|
slot_participants[j].append(participant)
|
|
# Fill the slots of the day
|
|
# Fill the slots of the day
|
|
slots = []
|
|
slots = []
|
|
|
|
+ last_hour = None
|
|
|
|
+ last_half_hour = None
|
|
for j, ps in enumerate(slot_participants):
|
|
for j, ps in enumerate(slot_participants):
|
|
slot_begin = (start_time + j * event.slot_interval).strftime('%H:%M')
|
|
slot_begin = (start_time + j * event.slot_interval).strftime('%H:%M')
|
|
slot_end = (start_time + (j+1) * event.slot_interval).strftime('%H:%M')
|
|
slot_end = (start_time + (j+1) * event.slot_interval).strftime('%H:%M')
|
|
|
|
+ current_time = start_time + j * event.slot_interval
|
|
slots.append({
|
|
slots.append({
|
|
'tooltip': f"{slot_begin} - {slot_end} \n{', '.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),
|
|
|
|
'offset': n*slots_per_day + j,
|
|
'offset': n*slots_per_day + j,
|
|
'date': date.date,
|
|
'date': date.date,
|
|
|
|
+ 'time': current_time,
|
|
|
|
+ 'class': f'color_{len(ps)}',
|
|
|
|
+ 'is_full_hour': current_time.hour != last_hour,
|
|
|
|
+ 'is_half_hour': current_time.minute // 30 != last_half_hour,
|
|
})
|
|
})
|
|
max_occupancy = max(max_occupancy, len(ps))
|
|
max_occupancy = max(max_occupancy, len(ps))
|
|
|
|
+ last_hour = current_time.hour
|
|
|
|
+ last_half_hour = current_time.minute // 30
|
|
|
|
|
|
day = {
|
|
day = {
|
|
'date': date.date,
|
|
'date': date.date,
|
|
@@ -89,21 +97,20 @@ def slots2grid( event : Event ) -> dict :
|
|
for i in range(slots_per_day):
|
|
for i in range(slots_per_day):
|
|
current_time = start_time + i * event.slot_interval
|
|
current_time = start_time + i * event.slot_interval
|
|
data['rows'].append({
|
|
data['rows'].append({
|
|
- 'days': [day['slots'][i] for day in data['days']],
|
|
|
|
'time': current_time,
|
|
'time': current_time,
|
|
'is_full_hour': current_time.hour != last_hour,
|
|
'is_full_hour': current_time.hour != last_hour,
|
|
})
|
|
})
|
|
last_hour = current_time.hour
|
|
last_hour = current_time.hour
|
|
|
|
+
|
|
data['rows'].append({
|
|
data['rows'].append({
|
|
- 'days': [None for day in data['days']],
|
|
|
|
'time': end_time,
|
|
'time': end_time,
|
|
'is_full_hour': True,
|
|
'is_full_hour': True,
|
|
})
|
|
})
|
|
- data['max_value'] = max_occupancy
|
|
|
|
|
|
|
|
# create a color for each slot from white to dark green
|
|
# 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}%)"
|
|
|
|
|
|
+ for i in range(max_occupancy+1):
|
|
|
|
+ data['colors'].append({
|
|
|
|
+ 'color': f"hsl(120, 100%, {100 - 70 * i / max_occupancy}%)",
|
|
|
|
+ 'name': f'color_{i}'
|
|
|
|
+ })
|
|
return data
|
|
return data
|