From b485bc4dfb6dce24d4594be5bc7087217efcd3e2 Mon Sep 17 00:00:00 2001 From: Steve Pike Date: Sun, 29 Sep 2013 00:27:37 +0100 Subject: [PATCH] basic tests list. pretty rough. #46 --- observations/models.py | 14 +++++++ observations/templates/test_detail.html | 55 +++++++++++++++++++++++++ observations/templates/test_list.html | 43 +++++++++++++++++++ observations/urls.py | 13 ++++++ observations/views.py | 1 + openwater/templates/base.html | 8 ++-- 6 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 observations/templates/test_detail.html create mode 100644 observations/templates/test_list.html diff --git a/observations/models.py b/observations/models.py index b5d936a..4efc878 100644 --- a/observations/models.py +++ b/observations/models.py @@ -1,5 +1,7 @@ import json +from collections import Counter + from django.contrib.gis.db import models from django_hstore import hstore @@ -75,6 +77,18 @@ def get_value(self, value): else: # maybe something more clever below... return value + def get_stats(self): + """Return some basics about this test, if possible.""" + result = {} + values = self.testvalue_set.values_list('value', flat=True) + result['usage'] = "Used {0} times".format(len(values)) + if self.test_type in ['CATEGORY', 'VALUE']: + values = map(float, values) + counter = Counter(values) + result['mode'] = "{0}, {1} times".format(*counter.most_common(1)[0]) + result['mean'] = "{0:0.2f}".format( + sum(values) / float(len(values))) + return result class Measurement(models.Model): diff --git a/observations/templates/test_detail.html b/observations/templates/test_detail.html new file mode 100644 index 0000000..4631105 --- /dev/null +++ b/observations/templates/test_detail.html @@ -0,0 +1,55 @@ +{% extends "base.html" %} +{% load static %} +{% block title %}Tests{% endblock %} +{% block header %} +

+ Test +

+

{{ test }}

+{% endblock %} +{% block content %} +
+
+
+
Measures
+
{{ test.parameter }}
+
Unit
+
{{ test.unit }}
+
+
+
+
+
Test vendor/authority
+
{{ test.vendor_or_authority }}
+
Test type
+
{{ test.get_test_type_display }}
+
+
+
+
+
+

Additional info

+
+
+ {% for key, value in test.meta.items %} +
{{ key }}
+
{{ value }}
+ {% endfor %} +
+
+
+
+

Stats

+
+
+ {% for key, value in test.get_stats.items %} +
{{ key|title }}
+
{{ value }}
+ {% endfor %} +
+
+
+
+{% endblock %} + + diff --git a/observations/templates/test_list.html b/observations/templates/test_list.html new file mode 100644 index 0000000..09babc7 --- /dev/null +++ b/observations/templates/test_list.html @@ -0,0 +1,43 @@ +{% extends "base.html" %} +{% load static %} +{% block title %}Tests{% endblock %} +{% block header %} +

+ Tests +

+

How are measurements made?

+{% endblock %} +{% block content %} +
+

Tests are what you use to get measurements of quality. Some tests + are really rigorous and give very high-accuracy values, others can + simply tell you if a chemical is present or not above a certain level. + Check below to find a test for some quality parameter.

+
+
+
+

Tests for…

+ {% regroup object_list by parameter as param_list %} + +
+
+ {% for param in param_list %} +
+

{{ param.grouper }}

+
    + {% for test in param.list %} +
  • + {{ test }} +
  • + {% endfor %} +
+
+ {% endfor %} +
+
+{% endblock %} + diff --git a/observations/urls.py b/observations/urls.py index 73dec6a..1c52049 100755 --- a/observations/urls.py +++ b/observations/urls.py @@ -1,11 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from django.conf.urls import patterns, url +from django.views.generic import ListView, DetailView from .views import ( MapView, AddView, ParamRowView, TestRowView, MeasurementView, DownloadView, ReportView, MeasurementPopupView ) +from .models import Test urlpatterns = patterns( @@ -18,4 +20,15 @@ url(r'^add/$', AddView.as_view(), name='observations-add'), url(r'^add/param/$', ParamRowView.as_view(), name='observations-add-param'), url(r'^add/test/$', TestRowView.as_view(), name='observations-add-test'), + + url(r'^tests/$', + ListView.as_view( + template_name='test_list.html', + queryset=Test.objects.order_by('parameter__name') + ), name='observations-tests'), + url(r'^tests/(?P\d+)/$', + DetailView.as_view( + model=Test, + template_name='test_detail.html' + ), name='observations-test-detail'), ) diff --git a/observations/views.py b/observations/views.py index 6f3b762..59d7fe7 100644 --- a/observations/views.py +++ b/observations/views.py @@ -33,6 +33,7 @@ def get_context_data(self, **kwargs): context.update(API_KEY=settings.CLOUDMADE_API_KEY) return context + class MeasurementPopupView(MeasurementView): template_name = 'observation-popup.html' diff --git a/openwater/templates/base.html b/openwater/templates/base.html index 3a97c29..283fc86 100644 --- a/openwater/templates/base.html +++ b/openwater/templates/base.html @@ -54,8 +54,8 @@ Home Add measurements - - Get testing kits + + Find tests {% if request.user.is_staff %}
  • Admin
  • {% endif %} @@ -93,8 +93,8 @@ Data sources, attributions How-to - - Testing kits + + Testing kits {% endwith %}