Skip to content

Commit

Permalink
Fixed interval error divide by 0 en route to #126 (this in class base…
Browse files Browse the repository at this point in the history
…d tabulation only). Note that the template still displays superfluous table elements at this point.
  • Loading branch information
dgets committed May 11, 2019
1 parent 2944785 commit 2a70051
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 38 deletions.
4 changes: 4 additions & 0 deletions dataview/templates/dataview/class_data_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ <h2>Usages Per Substance in Classification</h2>
{% for use_group in usages %}
<a name="{{ use_group.0 }}"><h4>{{ use_group.0 }}</h4></a>

{% if not interval_error %}
<table summary="{{ use_group.0 }} Data Summary">
<tr><td>
{% endif %}
<table summary="Administration Stats">
<tr>
<td>Total Usages:</td>
Expand All @@ -41,6 +43,7 @@ <h2>Usages Per Substance in Classification</h2>
<td>{{ use_group.6 }}</td>
</tr>
</table>
{% if not interval_error %}
</td>
<td>
<table summary="Interval Stats">
Expand All @@ -63,6 +66,7 @@ <h2>Usages Per Substance in Classification</h2>
</table>
</td></tr>
</table>
{% endif %}

<ul>
{% for use in use_group.1 %}
Expand Down
59 changes: 21 additions & 38 deletions dataview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,51 +412,34 @@ def class_data_summary(request, class_id):
sub_usage_stats_tuple = []
sub_interval_stats = []
cntr = 0
interval_cntr = 0
for usages in usages_list:
if len(usages) < 2:
interval_error = True
else:
interval_error = False

sub_usage_stats.append(dataview_support.get_usage_stats(usages))
sub_interval_stats.append(dataview_support.get_interval_stats(usages))
if not interval_error:
sub_interval_stats.append(dataview_support.get_interval_stats(usages))

# now we'll stuff that data into our pre-existing data structure, at least until we've got time to rework
# the template for what's here now
sub_usage_stats_tuple.append((subs[cntr], usages_list[cntr], sub_usage_stats[cntr]['total'],
len(usages_list[cntr]), sub_usage_stats[cntr]['average'],
sub_usage_stats[cntr]['highest'], sub_usage_stats[cntr]['lowest'],
sub_interval_stats[cntr]))
if not interval_error:
sub_usage_stats_tuple.append((subs[cntr], usages_list[cntr], sub_usage_stats[cntr]['total'],
len(usages_list[cntr]), sub_usage_stats[cntr]['average'],
sub_usage_stats[cntr]['highest'], sub_usage_stats[cntr]['lowest'],
sub_interval_stats[interval_cntr]))
interval_cntr += 1
else:
sub_usage_stats_tuple.append((subs[cntr], usages_list[cntr], sub_usage_stats[cntr]['total'],
len(usages_list[cntr]), sub_usage_stats[cntr]['average'],
sub_usage_stats[cntr]['highest'], sub_usage_stats[cntr]['lowest']))

cntr += 1

# sub_usages = []
# tmp_usages = []
#
# # get the usages for each sub
# for sub in subs:
# usage_count = 0
# total_dosage = 0
# highest_dosage = 0
# lowest_dosage = 10000
#
# for usage in Usage.objects.filter(sub=sub.id, user=request.user):
# total_dosage += usage.dosage
#
# usage_count += 1
# if usage.dosage > highest_dosage:
# highest_dosage = usage.dosage
#
# if usage.dosage < lowest_dosage:
# lowest_dosage = usage.dosage
#
# tmp_usages.append(usage)
#
# if lowest_dosage == 10000:
# lowest_dosage = highest_dosage
#
# # sub, usages, total administered, number of usages, avg per usage, highest dose, lowest dose
# sub_usages.append((sub, tmp_usages, total_dosage, usage_count, total_dosage / usage_count, highest_dosage,
# lowest_dosage))
#
# tmp_usages = []

context = {'subs': subs, 'usages': sub_usage_stats_tuple,} # subs isn't really necessary here any more, but does
# simplify the template a bit
# subs isn't really necessary here any more, but does simplify the template a bit
context = {'subs': subs, 'usages': sub_usage_stats_tuple,}

return render(request, 'dataview/class_data_summary.html', MiscMethods.add_header_info(context))

Expand Down

0 comments on commit 2a70051

Please sign in to comment.