diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index 98df93a5..5a746648 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -376,44 +376,6 @@ class ArveData(BaseRequestHandler): return self.finish(response.body) -class CasesData(BaseRequestHandler): - async def get(self, country): - http_client = AsyncHTTPClient() - # First we need the country to fetch the data - URL = f'https://restcountries.com/v3.1/alpha/{country}?fields=name' - try: - response = await http_client.fetch(HTTPRequest( - url=URL, - method='GET', - ), - raise_error=True) - except Exception as e: - print("Something went wrong: %s" % e) - - country_name = json.loads(response.body)['name']['common'] - - # Get global incident rates - URL = 'https://covid19.who.int/WHO-COVID-19-global-data.csv' - try: - response = await http_client.fetch(HTTPRequest( - url=URL, - method='GET', - ), - raise_error=True) - except Exception as e: - print("Something went wrong: %s" % e) - - df = pd.read_csv(StringIO(response.body.decode('utf-8')), index_col=False) - cases = df.loc[df['Country'] == country_name] - # 7-day rolling average - current_date = str(datetime.datetime.now()).split(' ')[0] - eight_days_ago = str(datetime.datetime.now() - datetime.timedelta(days=7)).split(' ')[0] - cases = cases.set_index(['Date_reported']) - # If any of the 'New_cases' is 0, it means the data is not updated. - if (cases.loc[eight_days_ago:current_date]['New_cases'] == 0).any(): return self.finish('') - return self.finish(str(round(cases.loc[eight_days_ago:current_date]['New_cases'].mean()))) - - class GenericExtraPage(BaseRequestHandler): def initialize(self, active_page: str, filename: str): @@ -509,7 +471,6 @@ def make_app( (get_root_calculator_url(r'/report-json'), ConcentrationModelJsonResponse), (get_root_calculator_url(r'/baseline-model/result'), StaticModel), (get_root_calculator_url(r'/api/arve/v1/(.*)/(.*)'), ArveData), - (get_root_calculator_url(r'/cases/(.*)'), CasesData), # Generic Pages (get_root_url(r'/about'), GenericExtraPage, { 'active_page': 'about', diff --git a/caimira/apps/calculator/static/js/co2_form.js b/caimira/apps/calculator/static/js/co2_form.js index e846bbcf..6b69c7f2 100644 --- a/caimira/apps/calculator/static/js/co2_form.js +++ b/caimira/apps/calculator/static/js/co2_form.js @@ -74,7 +74,7 @@ function uploadFile(endpoint) { } } - const data = XLSX.utils.sheet_to_json(worksheet, { header: 1, raw: false }); + const data = XLSX.utils.sheet_to_json(worksheet, { header: 1, raw: true }); // Check if there is any data below the header row if (data.length <= 1) { $("#upload-error") diff --git a/caimira/apps/calculator/static/js/form.js b/caimira/apps/calculator/static/js/form.js index 71023c2a..e63bbb45 100644 --- a/caimira/apps/calculator/static/js/form.js +++ b/caimira/apps/calculator/static/js/form.js @@ -418,20 +418,6 @@ 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); - result != '' ? $('#source_geographic_cases').show() : $('#source_geographic_cases').hide(); - }, - error: function(_, _, errorThrown) { - console.log(errorThrown); - } - }); -} - $("#sensors").change(function (el) { sensor_id = DATA_FROM_SENSORS.findIndex(function(sensor) { return sensor.RoomId == el.target.value @@ -983,8 +969,8 @@ $(document).ready(function () { // Handle geographic location input if (Array.from(url.searchParams).length > 0) { if (!url.searchParams.has('location_name')) { - $('[name="location_name"]').val('Geneva') - $('[name="location_select"]').val('Geneva') + $('[name="location_name"]').val('Geneva, CHE') + $('[name="location_select"]').val('Geneva, CHE') } if (!url.searchParams.has('location_latitude')) { $('[name="location_latitude"]').val('46.20833') @@ -993,12 +979,6 @@ $(document).ready(function () { $('[name="location_longitude"]').val('6.14275') } } - - // Update geographic_cases - geographic_cases('CHE'); - - // Handle WHO source message if geographic_cases pre-defined value is modified by user - $('#geographic_cases').change(() => $('#source_geographic_cases').hide()); // 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 @@ -1014,13 +994,14 @@ $(document).ready(function () { //Check all radio buttons previously selected $("input[type=radio]:checked").each(function() {require_fields(this)}); + // TEMPORARILY DISABLED // On CERN theme, when the arve_sensors_option changes we want to make its respective // children show/hide. - if ($("input[type=radio][name=arve_sensors_option]").length > 0) { - $("input[type=radio][name=arve_sensors_option]").change(on_use_sensors_data_change); - // Call the function now to handle forward/back button presses in the browser. - on_use_sensors_data_change(url); - } + // if ($("input[type=radio][name=arve_sensors_option]").length > 0) { + // $("input[type=radio][name=arve_sensors_option]").change(on_use_sensors_data_change); + // // Call the function now to handle forward/back button presses in the browser. + // on_use_sensors_data_change(url); + // } // When the ventilation_type changes we want to make its respective // children show/hide. @@ -1199,8 +1180,6 @@ $(document).ready(function () { $('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/calculator/static/js/report.js b/caimira/apps/calculator/static/js/report.js index 7c804dd9..786794d0 100644 --- a/caimira/apps/calculator/static/js/report.js +++ b/caimira/apps/calculator/static/js/report.js @@ -541,7 +541,15 @@ function draw_generic_concentration_plot( h_lines, ) { - list_of_scenarios = (plot_svg_id === 'CO2_concentration_graph') ? CO2_concentrations : alternative_scenarios + if (plot_svg_id === 'CO2_concentration_graph') { + list_of_scenarios = {'CO₂ concentration': {'concentrations': CO2_concentrations}}; + min_y_axis_domain = 400; + } + else { + list_of_scenarios = alternative_scenarios; + min_y_axis_domain = 0; + } + // H:M format var time_format = d3.timeFormat('%H:%M'); // D3 array of ten categorical colors represented as RGB hexadecimal strings. @@ -698,7 +706,7 @@ function draw_generic_concentration_plot( } function update_concentration_plot(concentration_data) { - list_of_scenarios = (plot_svg_id === 'CO2_concentration_graph') ? CO2_concentrations : alternative_scenarios + list_of_scenarios = (plot_svg_id === 'CO2_concentration_graph') ? {'CO₂ concentration': {'concentrations': CO2_concentrations}} : alternative_scenarios var highest_concentration = 0. for (scenario in list_of_scenarios) { @@ -706,7 +714,7 @@ function draw_generic_concentration_plot( highest_concentration = Math.max(highest_concentration, Math.max(...scenario_concentrations)); } - yRange.domain([0., highest_concentration*1.1]); + yRange.domain([min_y_axis_domain, highest_concentration*1.1]); yAxisEl.transition().duration(1000).call(yAxis); for (const [scenario_name, data] of Object.entries(data_for_scenarios)) { diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2 index aa6271bf..1d444a5d 100644 --- a/caimira/apps/templates/base/calculator.form.html.j2 +++ b/caimira/apps/templates/base/calculator.form.html.j2 @@ -477,9 +477,6 @@
-
diff --git a/caimira/apps/templates/cern/calculator.form.html.j2 b/caimira/apps/templates/cern/calculator.form.html.j2 index 4e5ae90a..2bab2783 100644 --- a/caimira/apps/templates/cern/calculator.form.html.j2 +++ b/caimira/apps/templates/cern/calculator.form.html.j2 @@ -5,28 +5,30 @@ ?
-
-
Use data from ARVE sensors:
-
- - - - -
-
- - -