Skip to content

Commit

Permalink
basic tests list. pretty rough. #46
Browse files Browse the repository at this point in the history
  • Loading branch information
stringfellow committed Sep 28, 2013
1 parent a408e74 commit b485bc4
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 4 deletions.
14 changes: 14 additions & 0 deletions observations/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from collections import Counter

from django.contrib.gis.db import models
from django_hstore import hstore

Expand Down Expand Up @@ -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):
Expand Down
55 changes: 55 additions & 0 deletions observations/templates/test_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% extends "base.html" %}
{% load static %}
{% block title %}Tests{% endblock %}
{% block header %}
<h2>
Test
</h2>
<h3>{{ test }}</h3>
{% endblock %}
{% block content %}
<div class="row-fluid">
<div class="span6">
<dl>
<dt>Measures</dt>
<dd>{{ test.parameter }}</dd>
<dt>Unit</dt>
<dd>{{ test.unit }}</dd>
</dl>
</div>
<div class="span6">
<dl>
<dt>Test vendor/authority</dt>
<dd>{{ test.vendor_or_authority }}</dd>
<dt>Test type</dt>
<dd>{{ test.get_test_type_display }}</dd>
</dl>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<h4>Additional info</h4>
<div class="well">
<dl>
{% for key, value in test.meta.items %}
<dt>{{ key }}</dt>
<dd>{{ value }}</dd>
{% endfor %}
</dl>
</div>
</div>
<div class="span6">
<h4>Stats</h4>
<div class="well">
<dl>
{% for key, value in test.get_stats.items %}
<dt>{{ key|title }}</dt>
<dd>{{ value }}</dd>
{% endfor %}
</dl>
</div>
</div>
</div>
{% endblock %}


43 changes: 43 additions & 0 deletions observations/templates/test_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% extends "base.html" %}
{% load static %}
{% block title %}Tests{% endblock %}
{% block header %}
<h2>
Tests
</h2>
<h3>How are measurements made?</h3>
{% endblock %}
{% block content %}
<div class="row-fluid">
<p>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.</p>
</div>
<div class="row-fluid">
<div class="span6">
<h4>Tests for&hellip;</h4>
{% regroup object_list by parameter as param_list %}
<ul>
{% for param in param_list %}
<li><a href="#test{{ param.grouper.id }}">{{ param.grouper }}</a></li>
{% endfor %}
</ul>
</div>
<div class="span6">
{% for param in param_list %}
<div id="test{{ param.grouper.id }}" data-param="{{ param.grouper.id }}">
<h3>{{ param.grouper }}</h3>
<ul>
{% for test in param.list %}
<li><a href="{% url "observations-test-detail" test.id %}">
{{ test }}</a>
</li>
{% endfor %}
</ul>
</div>
{% endfor %}
</div>
</div>
{% endblock %}

13 changes: 13 additions & 0 deletions observations/urls.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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<pk>\d+)/$',
DetailView.as_view(
model=Test,
template_name='test_detail.html'
), name='observations-test-detail'),
)
1 change: 1 addition & 0 deletions observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
8 changes: 4 additions & 4 deletions openwater/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<a href="{% url 'home' %}">Home</a></li>
<li{% if name == "observations-add" %} class="active"{% endif %}>
<a href="{% url "observations-add" %}">Add measurements</a></li>
<li{% if name == "sample-kits" %} class="active"{% endif %}>
<a href="{% url "sample-kits" %}">Get testing kits</a></li>
<li{% if name == "observations-tests" %} class="active"{% endif %}>
<a href="{% url "observations-tests" %}">Find tests</a></li>
{% if request.user.is_staff %}
<li><a href="{% url 'admin:index' %}">Admin</a></li>
{% endif %}
Expand Down Expand Up @@ -93,8 +93,8 @@
Data sources, attributions</a></li>
<li{% if name == "how-to" %} class="active"{% endif %}>
<a href="#">How-to</a></li>
<li{% if name == "sample-kits" %} class="active"{% endif %}>
<a href="{% url "sample-kits" %}">Testing kits</a></li>
<li{% if name == "observations-tests" %} class="active"{% endif %}>
<a href="{% url "observations-tests" %}">Testing kits</a></li>
</ul>
{% endwith %}
</div><!--/.well -->
Expand Down

0 comments on commit b485bc4

Please sign in to comment.