updated variable names and type

This commit is contained in:
Luis Aleixo 2021-08-17 15:31:32 +02:00
parent 33c948937d
commit 072c47d70a
3 changed files with 12 additions and 9 deletions

View file

@ -44,12 +44,15 @@ def calculate_report_data(model: models.ExposureModel):
er = np.array(model.concentration_model.infected.emission_rate_when_present()).mean()
exposed_occupants = model.exposed.number
expected_new_cases = np.array(model.expected_new_cases()).mean()
cumulative_dose = np.array([model.cumulated_exposure_vs_time(t) for t in times]).mean()
cumulative_doses = [
np.array(model.cumulated_exposure_vs_time(float(time))).mean()
for time in times
]
return {
"times": list(times),
"exposed_presence_intervals": [list(interval) for interval in model.exposed.presence.boundaries()],
"cumulative_dose": cumulative_dose,
"cumulative_doses": cumulative_doses,
"concentrations": concentrations,
"highest_const": highest_const,
"prob_inf": prob,

View file

@ -1,5 +1,5 @@
/* Generate the concentration plot using d3 library. */
function draw_concentration_plot(svg_id, times, concentrations, cumulative_dose, exposed_presence_intervals) {
function draw_concentration_plot(svg_id, times, concentrations, cumulative_doses, exposed_presence_intervals) {
var visBoundingBox = d3.select(svg_id)
.node()
.getBoundingClientRect();
@ -7,7 +7,7 @@ function draw_concentration_plot(svg_id, times, concentrations, cumulative_dose,
var time_format = d3.timeFormat('%H:%M');
var data = []
times.map((time, index) => data.push({ 'time': time, 'hour': new Date().setHours(Math.trunc(time), (time - Math.trunc(time)) * 60), 'concentration': concentrations[index], 'cumulative_dose': cumulative_dose[index] }))
times.map((time, index) => data.push({ 'time': time, 'hour': new Date().setHours(Math.trunc(time), (time - Math.trunc(time)) * 60), 'concentration': concentrations[index], 'cumulative_doses': cumulative_doses[index] }))
var vis = d3.select(svg_id),
width = visBoundingBox.width - 400,
@ -20,7 +20,7 @@ function draw_concentration_plot(svg_id, times, concentrations, cumulative_dose,
bisecHour = d3.bisector((d) => { return d.hour; }).left,
yRange = d3.scaleLinear().range([height - margins.bottom, margins.top]).domain([0., Math.max(...concentrations)]),
yCumulatedRange = d3.scaleLinear().range([height - margins.bottom, margins.top]).domain([0., Math.max(...cumulative_dose)]),
yCumulatedRange = d3.scaleLinear().range([height - margins.bottom, margins.top]).domain([0., Math.max(...cumulative_doses)]),
xAxis = d3.axisBottom(xRange).tickFormat(d => time_format(d)),
yAxis = d3.axisLeft(yRange),
@ -49,9 +49,9 @@ function draw_concentration_plot(svg_id, times, concentrations, cumulative_dose,
// Line representing the cumulative concentration.
var lineCumulativeFunc = d3.line()
.defined(d => !isNaN(d.cumulative_dose))
.defined(d => !isNaN(d.cumulative_doses))
.x(d => xTimeRange(d.time))
.y(d => yCumulatedRange(d.cumulative_dose))
.y(d => yCumulatedRange(d.cumulative_doses))
.curve(d3.curveBasis);
vis.append('svg:path')

View file

@ -224,9 +224,9 @@
<script type="application/javascript">
var times = {{times}}
var concentrations = {{concentrations}}
var cumulative_dose = {{cumulative_dose}}
var cumulative_doses = {{cumulative_doses}}
var exposed_presence_intervals = {{exposed_presence_intervals}}
draw_concentration_plot("#result_plot", times, concentrations, cumulative_dose, exposed_presence_intervals);
draw_concentration_plot("#result_plot", times, concentrations, cumulative_doses, exposed_presence_intervals);
</script>
<p class="data_title">Alternative scenarios:</p>