summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-10 22:46:17 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:28 +0200
commit014eddee87b0e6e871cf4a201884cf60a41cc63e (patch)
tree614ce9bbf5b1982977ff55e17e4d21520959e3aa /archaeological_operations
parent62f7ee65b2cdc8e9f543df9a197e89e4a3845f74 (diff)
downloadIshtar-014eddee87b0e6e871cf4a201884cf60a41cc63e.tar.bz2
Ishtar-014eddee87b0e6e871cf4a201884cf60a41cc63e.zip
Statistics - manage queries
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/models.py3
-rw-r--r--archaeological_operations/tests.py29
2 files changed, 32 insertions, 0 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index b3e137399..4f180c3d5 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -527,6 +527,9 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,
TABLE_COLS = ['code_patriarche', 'year', 'towns_label', 'common_name',
'operation_type', 'start_date', 'excavation_end_date',
'remains']
+ # statistics
+ STATISTIC_MODALITIES = ["year", "operation_type__label",
+ "towns__cached_label"]
# search parameters
BOOL_FIELDS = ['end_date__isnull', 'virtual_operation',
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 10afc61f2..42ceea292 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -2006,6 +2006,35 @@ class OperationSearchTest(TestCase, OperationInitTest):
self.assertEqual(json.loads(response.content.decode())['recordsTotal'],
1)
+ def test_statistics(self):
+ c = Client()
+ c.login(username=self.username, password=self.password)
+ q = {"stats_modality_1": "year",
+ "stats_modality_2": "operation_type__label"}
+ response = c.get(reverse('get-operation', args=['json-stats']), q)
+ self.assertEqual(response.status_code, 200)
+
+ expected_result = []
+ for ope in models.Operation.objects.all():
+ years = [y for y, res in expected_result]
+ if ope.year in years:
+ year_idx = years.index(ope.year)
+ else:
+ expected_result.append([ope.year, []])
+ year_idx = len(expected_result) - 1
+ current_values = expected_result[year_idx][1]
+ values = [v for v, cnt in current_values]
+ val = ope.operation_type.label
+ if val in values:
+ val_idx = values.index(val)
+ else:
+ current_values.append([val, 0])
+ val_idx = len(current_values) - 1
+ current_values[val_idx][1] += 1
+
+ values = json.loads(response.content.decode())
+ self.assertEqual(values['data'], expected_result)
+
class OperationPermissionTest(TestCase, OperationInitTest):
fixtures = FILE_FIXTURES