def on_get(self, req, resp, field, value): resp.status = falcon.HTTP_503 resp.body = "Individual stats are not currently available" resp.content_type = "text/html" return if not field in Aggregate.field_map.keys(): resp.status = falcon.HTTP_404 resp.content_type = "text/plain" resp.body = "Not Found" return valuemap = { 'model': ['version', 'country'], 'carrier': ['model', 'country'], 'version': ['model', 'country'], 'country': ['model', 'carrier'] } stats = Aggregate.get_info_by_field(field, value, left=valuemap[field][0], right=valuemap[field][1]) template = load_template('index.html').render( stats=stats, columns=valuemap[field], value=value, date=datetime.utcnow().strftime("%Y-%m-%d %H:%M")) resp.content_type = "text/html" resp.body = template
def test_field_stats(client): create_statistics() by_field = Aggregate.get_info_by_field("model", "cucumber", "model", "country") assert len(by_field.keys()) == 3 assert by_field['total'] == 1 print(by_field) Statistic.objects().delete() Aggregate.objects().delete()