Merge branch 'feature/general_fixes' into 'master'

General fixes

See merge request caimira/caimira!498
This commit is contained in:
Andre Henriques 2024-08-05 15:57:18 +02:00
commit 0624697f49
6 changed files with 42 additions and 95 deletions

View file

@ -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',

View file

@ -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")

View file

@ -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']);
}
});

View file

@ -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)) {

View file

@ -477,9 +477,6 @@
<div class="col-sm-4"><label class="col-form-label pt-0">New confirmed cases (weekly):</label></div>
<div class="col-sm-6 pl-0 align-self-center">
<input type="number" step="any" id="geographic_cases" class="non_zero form-control" name="geographic_cases" placeholder="Cases (#7-day rolling avg)" min="0">
<small id="source_geographic_cases" class="form-text text-muted" style="display: none">
Source: World Health Organization.
</small>
</div>
</div>
<div class="form-group row">

View file

@ -5,28 +5,30 @@
<span class="tooltip_text">?</span>
</div>
<div class="split">
<div>Use data from ARVE sensors:</div>
<div>
<input class="ml-2" type="radio" id="arve_sensor_no" name="arve_sensors_option" value=0 checked="checked">
<label for="arve_sensor_no">No</label>
<input class="ml-2" type="radio" id="arve_sensor_yes" name="arve_sensors_option" value=1 data-enables="#DIVsensors_data">
<label for="arve_sensor_yes">Yes</label>
</div>
</div>
<p id="offline_sensors" class="red_text mb-2" style="display: none">All sensors are offline.</p>
<p id="arve_api_error_message" class="red_text mb-2" style="display:none; max-width: 85%;">Unauthorized - Something went wrong during the ARVE API authentication process.</p>
<div id="DIVsensors_data" class="mb-1" style="display:none">
<div class="form-group row mb-0">
<div class="col-sm-4"><label class="col-form-label">Sensor:</label></div>
<div class="col-sm-6">
<select id="sensors" name="sensor_in_use" class="form-control">
</select>
<div class="d-none">
<div class="split">
<div>Use data from ARVE sensors:</div>
<div>
<input class="ml-2" type="radio" id="arve_sensor_no" name="arve_sensors_option" value=0 checked="checked">
<label for="arve_sensor_no">No</label>
<input class="ml-2" type="radio" id="arve_sensor_yes" name="arve_sensors_option" value=1 data-enables="#DIVsensors_data">
<label for="arve_sensor_yes">Yes</label>
</div>
</div>
<div>
<div><label>Temperature: </label><span class="ml-3 font-weight-bold" id="sensor_temperature"></span></div>
<div><label>Relative Humidity: </label><span class="ml-3 font-weight-bold" id="sensor_humidity"></span></div>
<p id="offline_sensors" class="red_text mb-2" style="display: none">All sensors are offline.</p>
<p id="arve_api_error_message" class="red_text mb-2" style="display:none; max-width: 85%;">Unauthorized - Something went wrong during the ARVE API authentication process.</p>
<div id="DIVsensors_data" class="mb-1" style="display:none">
<div class="form-group row mb-0">
<div class="col-sm-4"><label class="col-form-label">Sensor:</label></div>
<div class="col-sm-6">
<select id="sensors" name="sensor_in_use" class="form-control">
</select>
</div>
</div>
<div>
<div><label>Temperature: </label><span class="ml-3 font-weight-bold" id="sensor_temperature"></span></div>
<div><label>Relative Humidity: </label><span class="ml-3 font-weight-bold" id="sensor_humidity"></span></div>
</div>
</div>
</div>
{% endblock room_data %}