Skip to content

Commit c8ad75b

Browse files
committed
add assessment name and descr in export, add LRV tresholds for irrigation in treatment plot, disable reset-password view
1 parent 14d7026 commit c8ad75b

File tree

7 files changed

+70
-54
lines changed

7 files changed

+70
-54
lines changed

Diff for: qmra/risk_assessment/exports.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def results_as_df(results: dict[str, RiskAssessmentResult]) -> pd.DataFrame:
7676
return pd.concat(dfs)
7777

7878

79+
def risk_assessment_summary(assessment: RiskAssessment) -> str:
80+
return f'"Risk Assessment\'s Name:","{assessment.name}"\n"Description:","{assessment.description}"\n\n"Result\'s Summary:"\n'
81+
82+
7983
def risk_assessment_as_zip(buffer, risk_assessment: RiskAssessment):
8084
inflows = inflows_as_df(risk_assessment.inflows)
8185
treatments = treatments_as_df(risk_assessment.treatments)
@@ -91,7 +95,8 @@ def risk_assessment_as_zip(buffer, risk_assessment: RiskAssessment):
9195
archive.mkdir("results-plots")
9296
archive.writestr("exposure-assessment/inflows.csv", inflows.to_csv(sep=",", decimal=".", index=False))
9397
archive.writestr("exposure-assessment/treatments.csv", treatments.to_csv(sep=",", decimal=".", index=False))
94-
archive.writestr(f"{risk_assessment.name}-result.csv", results.to_csv(sep=",", decimal=".", index=False))
98+
archive.writestr(f"{risk_assessment.name}-result.csv",
99+
risk_assessment_summary(risk_assessment) + results.to_csv(sep=",", decimal=".", index=False))
95100
archive.writestr(f"{risk_assessment.name}-report.html", report)
96101
archive.writestr("results-plots/infection-probability.png", plots[0])
97102
archive.writestr("results-plots/dalys-pppy.png", plots[1])

Diff for: qmra/risk_assessment/plots.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ def risk_plots(risk_assessment_results, output_type="div"):
127127
marker_size=8
128128
)
129129
if output_type == "div":
130-
return plot(infection_prob_fig, output_type="div", config={'displayModeBar': False}, include_plotlyjs=False), \
131-
plot(dalys_fig, output_type="div", config={'displayModeBar': False}, include_plotlyjs=False)
130+
return plot(infection_prob_fig, output_type="div", config={"displaylogo": False, "modeBarButtonsToRemove": ['zoom2d', 'pan2d', 'select2d', 'lasso2d', 'zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d']}, include_plotlyjs=False), \
131+
plot(dalys_fig, output_type="div", config={"displaylogo": False, "modeBarButtonsToRemove": ['zoom2d', 'pan2d', 'select2d', 'lasso2d', 'zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d']}, include_plotlyjs=False)
132132
return infection_prob_fig.to_image(format=output_type), dalys_fig.to_image(format=output_type)

Diff for: qmra/risk_assessment/templates/inflows-form-js.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
plot_bgcolor:"#F6F6FF",
105105
paper_bgcolor:"#F6F6FF"
106106
};
107-
this.config = {displayModeBar: false, responsive: true};
107+
this.config = {displaylogo: false, modeBarButtonsToRemove: ['zoom2d', 'pan2d', 'select2d', 'lasso2d', 'zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d'], responsive: true};
108108
this.plot = Plotly.newPlot(divId, this.data, this.layout, this.config);
109109
window.addEventListener("resize", () => {
110110
Plotly.relayout(divId, {

Diff for: qmra/risk_assessment/templates/risk-assessment-list.html

+9-42
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,12 @@ <h5>Enhanced Features for Registered Users</h5>
161161
}
162162
document.addEventListener("DOMContentLoaded", function(){ toggleText()});
163163

164-
const colors = [['hsl(239, 100, 44)'], ['hsl(149, 90, 33)'], ['hsl(330, 100, 45)']];
165-
var [l1, l2, l3] = [44, 33, 45];
166-
for (let i of Array(6).keys()) {
167-
[l1, l2, l3] = [(l1 + 15) % 100, (l2 + 15) % 100, (l3 + 15) % 100]
168-
colors[0].push(`hsl(239, 100, ${l1})`)
169-
colors[1].push(`hsl(129, 50, ${l2})`)
170-
colors[2].push(`hsl(329, 100, ${l3})`)
164+
const colors = [['hsl(332, 100, 49)'], [], ['hsl(188, 100, 45)']];
165+
var [l1, l2, l3] = [49, 0, 45];
166+
for (let i of Array(3).keys()) {
167+
[l1, l2, l3] = [(l1 + 10) % 100, (l2 + 15) % 100, (l3 + 10) % 100]
168+
colors[0].push(`hsl(332, 100, ${l1})`)
169+
colors[2].push(`hsl(188, 100, ${l3})`)
171170
}
172171
function getResults(id) {
173172
const content = fetch(`{% url 'assessment-result' %}?id=${id}`, {
@@ -213,15 +212,6 @@ <h5>Enhanced Features for Registered Users</h5>
213212
dash: 'dashdot'
214213
}
215214
}],
216-
// annotations: [{
217-
// text: "tolerable level",
218-
// x: 0,
219-
// y: Math.log10(.0002),
220-
// xref: "paper", yref: "y", showarrow: false,
221-
// font: {
222-
// color: 'rgb(0, 3, 229)',
223-
// }
224-
// }],
225215
xaxis: {
226216
autorange: true,
227217
automargin: true
@@ -237,7 +227,7 @@ <h5>Enhanced Features for Registered Users</h5>
237227
},
238228
bargroupgap: .1, bargap: .1
239229
};
240-
this.config = { displayModeBar: false, responsive: true };
230+
this.config = { displaylogo: false, modeBarButtonsToRemove: ['zoom2d', 'pan2d', 'select2d', 'lasso2d', 'zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d'], responsive: true };
241231
Plotly.newPlot(divId, this.data, this.layout, this.config);
242232
window.addEventListener("resize", () => {
243233
Plotly.relayout(divId, {
@@ -250,13 +240,6 @@ <h5>Enhanced Features for Registered Users</h5>
250240
setTraces(allResults) {
251241
const data = allResults.map((ra, i) => ra.map((x, j) => asTraces(x, i, j)).flat());
252242
const layout = { ...this.layout }
253-
// for (var i of [...Array(data.length).keys()]) {
254-
// if (i >= 0) {
255-
// layout[`xaxis${i> 0 ? i + 1 : ''}`] = { domain: [i*(1/data.length), (i+1)*(1/data.length)], autorange: true, anchor: 'y' }
256-
// }
257-
// }
258-
// layout.grid = { rows: 2, columns: allResults.length,
259-
// subplots: [['xy', 'x2y', 'x3y']], pattern: 'independent' }
260243
layout.width = this.$div.getBoundingClientRect().width * .95;
261244
layout.height = window.innerHeight * .75;
262245
Plotly.react(this.divId, data.flat(), layout, this.config)
@@ -266,45 +249,29 @@ <h5>Enhanced Features for Registered Users</h5>
266249
function asTraces(r, i, j) {
267250
return [{
268251
x: [r.ra_name],
269-
// x0: (i + 1) * j,
270-
// y: [r.infection_minimum_lrv_min, r.infection_maximum_lrv_max],
271252
base: [r.infection_maximum_lrv_min],
272253
y: [r.infection_minimum_lrv_max],
273-
// q3: [r.infection_minimum_lrv_max],
274-
// q1: [r.infection_maximum_lrv_min],
275-
// median: [(r.infection_minimum_lrv_max + r.infection_maximum_lrv_min)/2],
276254
name: r.pathogen,
277255
type: "bar",
278256
xaxis: "x",
279257
yaxis: "y",
280-
marker: { color: colors[0][j], opacity: .75, fillmode: "overlay" },
258+
marker: { color: colors[0][j], opacity: .75, fillmode: "overlay", pattern: {shape: "/"} },
281259

282260
showlegend: i === 0,
283261
offsetgroup: r.pathogen,
284262
legendgroup: "min - max range",
285263
legendgrouptitle: { text: "min - max range" },
286-
// width: .5,
287-
// hoverinfo: "x+y",
288264
hovertemplate: `max=%{y}, min=%{base}`
289265
},
290266
{
291267
x: [r.ra_name],
292-
// x0: (i + 1) * j,
293268
base: [r.infection_maximum_lrv_median],
294269
y: [r.infection_minimum_lrv_median],
295-
// q3: [r.infection_minimum_lrv_median],
296-
// q1: [r.infection_maximum_lrv_median],
297-
// median: [(r.infection_minimum_lrv_median + r.infection_maximum_lrv_median)/2],
298-
// lowerfence: [r.infection_minimum_lrv_min, r.infection_maximum_lrv_min],
299-
// upperfence: [r.infection_minimum_lrv_max, r.infection_maximum_lrv_max],
300-
// q1: [r.infection_minimum_lrv_q1, r.infection_maximum_lrv_q1],
301-
// q3: [r.infection_minimum_lrv_q3, r.infection_maximum_lrv_q3],
302-
// median: [r.infection_minimum_lrv_median, r.infection_maximum_lrv_median],
303270
name: r.pathogen,
304271
type: "bar",
305272
xaxis: "x",
306273
yaxis: "y",
307-
marker: { color: colors[2][j], opacity: .5, fillmode: "overlay" },
274+
marker: { color: colors[2][j], opacity: .85, fillmode: "replace" },
308275
offsetgroup: r.pathogen,
309276
showlegend: i === 0,
310277
legendgroup: "mean range",

Diff for: qmra/risk_assessment/templates/treatments-form-js.html

+48-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
let defaultTreatments = null;
55
let focusedTreatment = null;
66
let treatmentsFormset = null;
7+
let treatmentsPlots = null;
78
class TreatmentForm {
89
fields = {
910
id: {
@@ -188,6 +189,7 @@
188189
constructor(divId) {
189190
this.divId = divId;
190191
this.$div = document.querySelector(`#${divId}`)
192+
this.withIrrigationThresholds = false;
191193
this.traces = {}
192194
this.data = [];
193195
this.layout = {
@@ -200,7 +202,7 @@
200202
type: 'log',
201203
exponentformat: "power",
202204
autorange: true,
203-
title: "Logremoval of individual treatment steps",
205+
title: "Logremoval of individual<br>treatment steps",
204206
},
205207
xaxis: {
206208
autorange: true, domain: [0., 0.33333]
@@ -263,7 +265,7 @@
263265
}
264266
]
265267
};
266-
this.config = { displayModeBar: false, responsive: true };
268+
this.config = { displaylogo: false, modeBarButtonsToRemove: ['zoom2d', 'pan2d', 'select2d', 'lasso2d', 'zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d'], responsive: true };
267269
this.plot = Plotly.newPlot(divId, this.data, this.layout, this.config);
268270
window.addEventListener("resize", () => {
269271
Plotly.relayout(divId, {
@@ -274,7 +276,37 @@
274276
}
275277
update() {
276278
this.layout.datarevision += 1;
277-
Plotly.react(this.divId, this.data, this.layout, this.config);
279+
const data = [...this.data, ...(this.withIrrigationThresholds ? this.irrigationThresholds : [])];
280+
Plotly.react(this.divId, data, this.layout, this.config);
281+
}
282+
get irrigationThresholds(){
283+
const name = "Legally Required LRVs<br>for Class A irrigation<br>according to the EU Water<br>Reuse Reg. 2020/74";
284+
return [{
285+
x: ["min", "max"], y: [5, 5], type: 'scatter',
286+
mode: "lines", fill: "tonexty",
287+
marker: {color: "hsl(332, 100, 49)"},
288+
xaxis: "x", yaxis: "y", name: name, showlegend: true
289+
},
290+
{
291+
x: ['min', 'max'], y: [4, 4], type: 'scatter',
292+
mode: "lines", fill: "tonexty",
293+
marker: {color: "hsl(332, 100, 49)"},
294+
xaxis: "x2", yaxis: "y", name: name, showlegend: false
295+
},
296+
{
297+
x: ['min', 'max'], y: [6, 6], type: 'scatter',
298+
mode: "lines", fill: "tonexty",
299+
marker: {color: "hsl(332, 100, 49)"},
300+
xaxis: "x3", yaxis: "y", name: name, showlegend: false
301+
}]
302+
}
303+
displayLRVThresholdForIrrigation() {
304+
this.withIrrigationThresholds = true;
305+
this.update();
306+
}
307+
removeLRVThresholdForIrrigation() {
308+
this.withIrrigationThresholds = false;
309+
this.update();
278310
}
279311
}
280312
class TreatmentController {
@@ -380,7 +412,7 @@ <h5>${treatment.name}</h5>
380412
defaultReferences = await fetch("{% static 'data/default-references.json' %}").then(resp => resp.json());
381413
const formset = new TreatmentFormset();
382414
const list = new TreatmentsList("selected-treatments");
383-
const treatmentsPlots = new TreatmentPlot("treatments-plot");
415+
treatmentsPlots = new TreatmentPlot("treatments-plot");
384416
const treatmentController = new TreatmentController(list, formset, treatmentsPlots, document.querySelector("#treatment-info"), defaultReferences);
385417
var lastForm = null
386418
for (let form of Object.values(formset.forms)) {
@@ -395,6 +427,18 @@ <h5>${treatment.name}</h5>
395427
form.setValues(values);
396428
treatmentController.addTreatment(form, values)
397429
})
430+
// callback to display legal LRV threshold for irrigation exposures
431+
const selectedExposure = document.querySelector("#id_ra-exposure_name");
432+
selectedExposure.addEventListener("change", ev => {
433+
if (ev.target.value.includes("irrigation")) {
434+
treatmentsPlots.displayLRVThresholdForIrrigation();
435+
} else {
436+
treatmentsPlots.removeLRVThresholdForIrrigation();
437+
}
438+
})
439+
if (selectedExposure.value.includes("irrigation")) {
440+
treatmentsPlots.displayLRVThresholdForIrrigation();
441+
}
398442
})
399443

400444
</script>

Diff for: qmra/templates/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ <h5>Login</h5>
4040
</form>
4141
<div class="my-1">Don't have an account? <a class="text_link_kwb" href="{% url 'register' %}">Register
4242
here.</a></div>
43-
<div class="my-1">Forgot password? <a class="text_link_kwb" href="{% url 'password_reset' %}">Reset
44-
here</a>
45-
</div>
43+
<!-- <div class="my-1">Forgot password? <a class="text_link_kwb" href="{% url 'password_reset' %}">Reset-->
44+
<!-- here</a>-->
45+
<!-- </div>-->
4646
</div>
4747
</div>
4848

Diff for: qmra/user/templates/login.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h5>Login</h5>
2222
<input class="btn btn-primary" type="submit" value="Login">
2323
</form>
2424
<div class="my-1">Don't have an account? <a class = "text_link_kwb" href="{% url 'register' %}">Register here.</a></div>
25-
<div class="my-1">Forgot password? <a class = "text_link_kwb" href="{% url 'password_reset' %}">Reset here</a></div>
25+
<!-- <div class="my-1">Forgot password? <a class = "text_link_kwb" href="{% url 'password_reset' %}">Reset here</a></div>-->
2626
</div>
2727
</div>
2828
</div>

0 commit comments

Comments
 (0)