|
@@ -33,21 +33,26 @@ def get_num_machines_per_status(status, records):
|
33
|
33
|
len(filter(lambda r: r.machine.type == DRYER and
|
34
|
34
|
r.availability == status, records))]
|
35
|
35
|
|
36
|
|
-def generate_current_chart(filepath, records, hall):
|
|
36
|
+def generate_current_chart(records, hall, filepath=None):
|
37
|
37
|
"""
|
38
|
38
|
Generate stacked bar chart of current laundry usage for specified hall and
|
39
|
39
|
save svg at filepath.
|
40
|
40
|
"""
|
41
|
41
|
custom_style = Style(colors=('#B6E354', '#FF5995', '#FEED6C', '#E41B17'))
|
42
|
|
- chart = pygal.StackedBar(style=custom_style, width=800, height=512, explicit_size=True)
|
|
42
|
+ chart = pygal.StackedBar(style=custom_style, width=800, height=512,
|
|
43
|
+ explicit_size=True)
|
43
|
44
|
chart.title = 'Current laundry machine usage in ' + hall.name
|
44
|
45
|
chart.x_labels = ['Washers', 'Dryers']
|
|
46
|
+ print records
|
45
|
47
|
chart.add('Available', get_num_machines_per_status(AVAILABLE, records))
|
46
|
48
|
chart.add('In Use', get_num_machines_per_status(IN_USE, records))
|
47
|
49
|
chart.add('Cycle Complete', get_num_machines_per_status(CYCLE_COMPLETE, records))
|
48
|
50
|
chart.add('Unavailable', get_num_machines_per_status(UNAVAILABLE, records))
|
49
|
51
|
chart.range = [0, 11]
|
50
|
|
- chart.render_to_file(filepath)
|
|
52
|
+ if filepath:
|
|
53
|
+ chart.render_to_file(filepath)
|
|
54
|
+ else:
|
|
55
|
+ return chart.render()
|
51
|
56
|
|
52
|
57
|
# NOTE: Abandoning generating the weekly chart via mysql and Django for now.
|
53
|
58
|
# (cron script and csv file is just easier) Sorry if there are a lot of
|
|
@@ -112,9 +117,8 @@ def update(hall, filepath=None):
|
112
|
117
|
machine = LaundryMachine.objects.get(number=number, hall=hall)
|
113
|
118
|
record = LaundryRecord(machine=machine, availability=availability,
|
114
|
119
|
time_remaining=time_remaining)
|
115
|
|
- if filepath:
|
116
|
|
- records.append(record)
|
117
|
|
- else:
|
118
|
|
- record.save()
|
|
120
|
+ records.append(record)
|
119
|
121
|
if filepath:
|
120
|
|
- generate_current_chart(filepath, records, hall)
|
|
122
|
+ generate_current_chart(records, hall, filepath=filepath)
|
|
123
|
+ else:
|
|
124
|
+ return generate_current_chart(records, hall)
|