@@ -129,29 +129,34 @@ def dump_dose_graph_data(request, sub_id):
129
129
"""
130
130
131
131
dosage_graph_data = []
132
- # dosage_sub_id = request.POST['sub']
133
132
usages = Usage .objects .filter (sub = sub_id )[:20 ]
134
133
135
- # cntr = 0
134
+ max_dosage = 0
136
135
for use in usages :
137
- # dosage_graph_data[str(use.timestamp)] = float(use.dosage)
138
- # NOTE: switching to a standard array for now for simplicity in the
139
- # template's javascript; we can add more gravy later
140
-
141
136
# later on we can look at using use.notes as hover-over text for each
142
137
# graph bar, or something of the like
143
- dosage_graph_data .append (float (use .dosage ))
144
- # cntr += 1
138
+ # dosage_graph_data.append(float(use.dosage))
139
+
140
+ if max_dosage < use .dosage :
141
+ max_dosage = use .dosage
142
+
143
+ scale_factor = get_graph_normalization_divisor (max_dosage , 300 )
145
144
146
- return HttpResponse (json .dumps (dosage_graph_data ), content_type = 'application/json' )
145
+ # okay, yeah the 2 for loops is gross, but my brain is fried and I want to
146
+ # finish this quick; I'll fix it later
147
+ # TODO: fix the gross 2 for loops issue
148
+ for use in usages :
149
+ dosage_graph_data .append (float (use .dosage * scale_factor ))
150
+
151
+ return HttpResponse (json .dumps ({'scale_factor' : float (scale_factor ), 'dosages' : dosage_graph_data }),
152
+ content_type = 'application/json' )
147
153
148
154
149
155
def dump_interval_graph_data (request , sub_id ):
150
- # interval_graph_data = {}
151
156
usages = Usage .objects .filter (sub = sub_id )[:20 ]
152
157
153
158
timespans = []
154
- prev_time = None # would we (perhaps optionally) want timezone.now()?
159
+ prev_time = None
155
160
max_span = datetime .timedelta (0 )
156
161
for use in usages :
157
162
if prev_time is not None :
@@ -169,7 +174,7 @@ def dump_interval_graph_data(request, sub_id):
169
174
for cntr in range (0 , len (timespans )):
170
175
timespans [cntr ] = timespans [cntr ] * scale_factor
171
176
172
- return HttpResponse (json .dumps ({ 'scale_factor' : scale_factor , 'timespans' : timespans }),
177
+ return HttpResponse (json .dumps ({'scale_factor' : scale_factor , 'timespans' : timespans }),
173
178
content_type = 'application/json' )
174
179
175
180
0 commit comments