From 1a9343998462dea4ab63d86732a0c7cd79197945 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Wed, 12 Oct 2022 16:49:42 +0200 Subject: [PATCH] added incidence rate from API to UI --- caimira/apps/calculator/static/js/form.js | 19 +++++++++++++++++++ .../templates/base/calculator.form.html.j2 | 9 +++++++-- setup.py | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/caimira/apps/calculator/static/js/form.js b/caimira/apps/calculator/static/js/form.js index 86c23880..300f54ce 100644 --- a/caimira/apps/calculator/static/js/form.js +++ b/caimira/apps/calculator/static/js/form.js @@ -418,6 +418,19 @@ function show_sensors_data(url) { } }; +function geographic_cases(location_country_name) { + $.ajax({ + url: `${$('#url_prefix').data().calculator_prefix}/cases/${location_country_name}`, + type: 'GET', + success: function (result) { + $('#geographic_cases').val(result); + }, + error: function(_, _, errorThrown) { + console.log(errorThrown); + } + }); +} + $("#sensors").change(function (el) { sensor_id = DATA_FROM_SENSORS.findIndex(function(sensor) { return sensor.RoomId == el.target.value @@ -930,6 +943,9 @@ $(document).ready(function () { } } + // Update geographic_cases + geographic_cases('CHE'); + // When the document is ready, deal with the fact that we may be here // as a result of a forward/back browser action. If that is the case, update // the visibility of some of our inputs. @@ -1120,9 +1136,12 @@ $(document).ready(function () { success: function (locations) { // If there isn't precisely one result something is very wrong. geocoded_loc = locations.candidates[0]; + $('input[name="location_name"]').val(selectedSuggestion.text); $('input[name="location_latitude"]').val(geocoded_loc.location.y.toPrecision(7)); $('input[name="location_longitude"]').val(geocoded_loc.location.x.toPrecision(7)); + // Update geographic_cases + geographic_cases(geocoded_loc.attributes['country']); } }); diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2 index 5959d555..711736bd 100644 --- a/caimira/apps/templates/base/calculator.form.html.j2 +++ b/caimira/apps/templates/base/calculator.form.html.j2 @@ -386,8 +386,13 @@
-
-
+
+
+ + + Source: World Health Organization. + +
diff --git a/setup.py b/setup.py index c0f292d6..242d662d 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ REQUIREMENTS: dict = { 'memoization', 'mistune', 'numpy', + 'pandas', 'psutil', 'python-dateutil', 'retry',