short range breathing activity as default for visualisation; handled toggle button

This commit is contained in:
Luis Aleixo 2022-03-14 21:35:23 +00:00
parent bfbae7b982
commit 2fe013a855
11 changed files with 43 additions and 23 deletions

View file

@ -259,6 +259,7 @@ class FormData:
evaporation_factor=0.3,
),
short_range = mc.ShortRangeModel(
activities=sr_activities,
presence=sr_presence,
expirations=short_range_expirations,
dilutions=dilution_factor(activities=sr_activities, distance=np.random.uniform(0.5, 1.5, 250000)),

View file

@ -106,10 +106,16 @@ def calculate_report_data(model: models.ExposureModel):
np.array(model.concentration(float(time))).mean()
for time in times
]
concentrations = [
np.array(model.concentration_model.concentration(float(time))).mean()
for time in times
]
concentrations = []
for time in times:
for index, (start, stop) in enumerate(short_range_intervals):
# For visualization issues, add short range breathing activity to the initial long range concentrations
if start <= time <= stop and model.short_range.activities[index] == 'Breathing':
concentrations.append(np.array(model.concentration(float(time))).mean())
break
concentrations.append(np.array(model.concentration_model.concentration(float(time))).mean())
highest_const = max(short_range_concentrations)
prob = np.array(model.infection_probability()).mean()
er = np.array(model.concentration_model.infected.emission_rate_when_present()).mean()

View file

@ -639,14 +639,14 @@ function draw_plot(svg_id, times, concentrations, short_range_concentrations, cu
.select('.line')
.transition()
.duration(1000)
.attr("d", lineFunc(data_for_graphs));
.attr("d", lineFunc(long_range_data));
// Area.
exposed_presence_intervals.forEach((b, index) => {
exposedArea[index].x(d => xTimeRange(d.time))
.y0(graph_height - 50)
.y1(d => yRange(d.concentration));
drawArea[index].transition().duration(1000).attr('d', exposedArea[index](data_for_graphs.filter(d => {
drawArea[index].transition().duration(1000).attr('d', exposedArea[index](long_range_data.filter(d => {
return d.time >= b[0] && d.time <= b[1]
})));
});
@ -657,7 +657,7 @@ function draw_plot(svg_id, times, concentrations, short_range_concentrations, cu
.y0(graph_height - 50)
.y1(d => yRange(d.concentration));
drawShortRangeArea[index].transition().duration(1000).attr('d', shortRangeArea[index](data_for_graphs.filter(d => {
drawShortRangeArea[index].transition().duration(1000).attr('d', shortRangeArea[index](long_range_data.filter(d => {
return d.time >= b[0] && d.time <= b[1]
})));
});
@ -805,16 +805,22 @@ function draw_plot(svg_id, times, concentrations, short_range_concentrations, cu
if (button_full_exposure) {
button_full_exposure.addEventListener("click", () => {
update_concentration_plot(short_range_concentrations, data_for_graphs.short_range_concentrations, data_for_graphs.short_range_concentrations);
button_full_exposure.disabled = true;
button_long_exposure.disabled = false;
});
}
if (button_long_exposure) {
button_long_exposure.addEventListener("click", () => {
update_concentration_plot(concentrations, data_for_graphs.short_range_concentrations, data_for_graphs.concentrations);
button_full_exposure.disabled = false;
button_long_exposure.disabled = true;
});
}
// If user double click, reinitialize the chart
vis.on("dblclick",function(){
button_full_exposure.disabled = true;
button_long_exposure.disabled = false;
yRange.domain([0., Math.max(...short_range_concentrations)])
yAxisEl.transition().call(d3.axisLeft(yRange))
lineFunc.defined(d => !isNaN(d.concentration))

View file

@ -504,6 +504,7 @@ baseline_model = models.ExposureModel(
evaporation_factor=0.3,
),
short_range=models.ShortRangeModel(
activities=(),
presence=(),
expirations=(),
dilutions=(),

View file

@ -90,8 +90,7 @@
</div>
<p id="section1">* The results are based on the parameters and assumptions published in the CERN Open Report <a href="https://cds.cern.ch/record/2756083"> CERN-OPEN-2021-004</a>.</p>
{% if form.short_range_option == "short_range_yes" %}
<button class="btn btn-sm btn-primary" id="button_full_exposure">Full exposure</button>
<button class="btn btn-sm btn-primary" id="button_long_exposure">Background concentration</button>
<button class="btn btn-sm btn-primary" id="button_full_exposure" disabled>Show full exposure</button><button class="btn btn-sm btn-primary ml-0" id="button_long_exposure">Hide high concentration</button>
{% endif %}
<div id="concentration_plot" style="height: 400px"></div>
<script type="application/javascript">

View file

@ -1075,6 +1075,9 @@ class ConcentrationModel:
@dataclass(frozen=True)
class ShortRangeModel:
#: Short range activities
activities: typing.Tuple[str, ...]
#: Short range interactions
presence: typing.Tuple[SpecificInterval, ...]

View file

@ -32,9 +32,10 @@ def baseline_concentration_model():
@pytest.fixture
def baseline_sr_model():
return models.ShortRangeModel(
presence=[],
expirations=[],
dilutions=[],
activities=(),
presence=(),
expirations=(),
dilutions=(),
)

View file

@ -172,9 +172,10 @@ def conc_model():
@pytest.fixture
def sr_model():
return models.ShortRangeModel(
presence=[],
expirations=[],
dilutions=[],
activities=(),
presence=(),
expirations=(),
dilutions=(),
)
# Expected deposited exposure were computed with a trapezoidal integration, using

View file

@ -58,7 +58,7 @@ def dilutions():
def test_short_range_model_ndarray(concentration_model, presences, expirations, dilutions):
concentration_model = concentration_model.build_model(250_000)
model = mc_models.ShortRangeModel(presences, expirations, dilutions)
model = mc_models.ShortRangeModel(activities, presences, expirations, dilutions)
model = model.build_model(250_000)
assert isinstance(model._normed_concentration(concentration_model, 10.75), np.ndarray)
assert isinstance(model.short_range_concentration(concentration_model, 14.75), np.ndarray)
@ -77,7 +77,7 @@ def test_short_range_model(
concentration_model, presences, expirations, dilutions,
):
concentration_model = concentration_model.build_model(250_000)
model = mc_models.ShortRangeModel(presences, expirations, dilutions)
model = mc_models.ShortRangeModel(activities, presences, expirations, dilutions)
model = model.build_model(250_000)
np.testing.assert_almost_equal(
model._normed_concentration(concentration_model, time).mean(), expected_sr_normed_concentration, decimal=0

View file

@ -64,9 +64,10 @@ def baseline_mc_concentration_model() -> cara.monte_carlo.ConcentrationModel:
@pytest.fixture
def baseline_mc_sr_model() -> cara.monte_carlo.ShortRangeModel:
return cara.monte_carlo.ShortRangeModel(
presence=[],
expirations=[],
dilutions=[],
activities=(),
presence=(),
expirations=(),
dilutions=(),
)

View file

@ -43,9 +43,10 @@ TorontoTemperatures = {
@pytest.fixture
def sr_model_mc() -> mc.ShortRangeModel:
return mc.ShortRangeModel(
presence=[],
expirations=[],
dilutions=[],
activities=(),
presence=(),
expirations=(),
dilutions=(),
)
@pytest.fixture