added back compatibility (form report -> calculator)
This commit is contained in:
parent
1b8aa4f2c1
commit
be684ee3a6
4 changed files with 36 additions and 12 deletions
|
|
@ -379,7 +379,6 @@ class CO2Data(BaseRequestHandler):
|
|||
fig = plt.figure(figsize=(7, 4), dpi=110)
|
||||
plt.plot(form.CO2_data['times'], form.CO2_data['CO2'])
|
||||
for index, time in enumerate(transition_times[:-1]):
|
||||
print(time)
|
||||
plt.axvline(x = time, color = 'grey', linewidth=0.5, linestyle='--')
|
||||
y_location = (form.CO2_data['CO2'][min(range(len(form.CO2_data['times'])), key=lambda i: abs(form.CO2_data['times'][i]-time))])
|
||||
plt.text(x = time + 0.04, y = y_location, s=round(ventilation_values[index], 2))
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// JS file to handle manipulation on CO2 Fitting Algorithm Dialog.
|
||||
const CO2_data = [
|
||||
'CO2_data',
|
||||
'specific_breaks',
|
||||
|
|
@ -92,6 +93,7 @@ function displayJsonToHtmlTable(jsonData) {
|
|||
}
|
||||
}
|
||||
|
||||
// Method to download Excel template available on CERNBox
|
||||
function downloadTemplate(uri = 'https://caimira-resources.web.cern.ch/CO2_template.xlsx', filename = 'CO2_template.xlsx') {
|
||||
var link = document.createElement("a");
|
||||
link.download = filename;
|
||||
|
|
@ -114,15 +116,26 @@ function validate() {
|
|||
$('span.' + "error_text").remove();
|
||||
let submit = true;
|
||||
for (var i = 0; i < CO2_data.length; i++) {
|
||||
let element = $(`[name=${CO2_data[i]}]`);
|
||||
if (element[0].value === '') {
|
||||
insertErrorFor($('#CO2_input_data_div'), `'${element[0].name}' must be defined.`); // raise error for total number and room volume.
|
||||
let element = $(`[name=${CO2_data[i]}]`)[0];
|
||||
if (element.value === '') {
|
||||
insertErrorFor($('#CO2_input_data_div'), `'${element.name}' must be defined.`); // raise error for total number and room volume.
|
||||
submit = false;
|
||||
};
|
||||
}
|
||||
return submit;
|
||||
}
|
||||
|
||||
function display_fitting_data(json_response) {
|
||||
$("#DIV_CO2_fitting_result").show();
|
||||
$("#CO2_data_plot").attr("src", json_response['CO2_plot']);
|
||||
delete json_response['CO2_plot'];
|
||||
$("#CO2_fitting_result").val(JSON.stringify(json_response));
|
||||
$("#exhalation_rate_fit").html('Exhalation rate: ' + String(json_response['exhalation_rate'].toFixed(2)) + ' m³/h');
|
||||
// $("#ventilation_rate_fit").html(json_response['ventilation_values']);
|
||||
$("#generate_fitting_data").html('Fit data');
|
||||
$("#save_and_dismiss_dialog").show();
|
||||
}
|
||||
|
||||
function submit_fitting_algorithm(url) {
|
||||
if (validate()) {
|
||||
let CO2_mapping = {};
|
||||
|
|
@ -143,13 +156,7 @@ function submit_fitting_algorithm(url) {
|
|||
})
|
||||
.then((response) => response.json())
|
||||
.then((json_response) => {
|
||||
$("#DIV_CO2_fitting_result").show();
|
||||
$("#CO2_fitting_result").val(JSON.stringify(json_response));
|
||||
$("#exhalation_rate_fit").html('Exhalation rate: ' + String(json_response['exhalation_rate'].toFixed(2)) + ' m³/h');
|
||||
// $("#ventilation_rate_fit").html(json_response['ventilation_values']);
|
||||
$("#CO2_data_plot").attr("src", json_response['CO2_plot']);
|
||||
$("#generate_fitting_data").html('Fit data');
|
||||
$("#save_and_dismiss_dialog").show();
|
||||
display_fitting_data(json_response);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -946,6 +946,12 @@ $(document).ready(function () {
|
|||
// Validation after
|
||||
}
|
||||
|
||||
|
||||
// Read CO2 Fitting Algorithms result
|
||||
else if (name == 'CO2_fitting_result' || name == 'CO2_data') {
|
||||
// Validation after
|
||||
}
|
||||
|
||||
//Ignore 0 (default) values from server side
|
||||
else if (!(elemObj.classList.contains("non_zero") || elemObj.classList.contains("remove_zero")) || (value != "0.0" && value != "0")) {
|
||||
elemObj.value = value;
|
||||
|
|
@ -956,6 +962,18 @@ $(document).ready(function () {
|
|||
|
||||
// Handle default URL values if they are not explicitly defined.
|
||||
|
||||
// Populate CO2 Fitting Algorithm Dialog
|
||||
let CO2_data = url.searchParams.has('CO2_data') ? url.searchParams.get('CO2_data') : null;
|
||||
if (CO2_data) {
|
||||
let CO2_inputs = JSON.parse(CO2_data);
|
||||
let input_for_table = [];
|
||||
for (let i = 0; i < CO2_inputs['times'].length; i++) {
|
||||
input_for_table.push({'Times': CO2_inputs['times'][i], 'CO2': CO2_inputs['CO2'][i]});
|
||||
};
|
||||
displayJsonToHtmlTable(input_for_table);
|
||||
submit_fitting_algorithm(`${$('#url_prefix').data().calculator_prefix}/co2-fit`);
|
||||
}
|
||||
|
||||
// Populate primary vaccine dropdown
|
||||
$("#vaccine_type option").remove();
|
||||
let primary_vaccine = url.searchParams.has('vaccine_type') ? url.searchParams.get('vaccine_type') : null;
|
||||
|
|
|
|||
|
|
@ -708,7 +708,7 @@
|
|||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="d-flex d-row justify-content-between">
|
||||
<h5 style="margin-top: auto; margin-bottom: auto">Upload an excel file to display in HTML Table</h5>
|
||||
<h5 style="margin-top: auto; margin-bottom: auto">Upload an Excel file to preview in HTML Table</h5>
|
||||
<button type="button" class="btn btn-primary btn-sm" onclick="downloadTemplate()">Download template</button>
|
||||
</div>
|
||||
<br>
|
||||
|
|
|
|||
Loading…
Reference in a new issue