Commit e411be91 authored by Michał Woźniak's avatar Michał Woźniak
Browse files

rounding to hundredths when calculating averages or normalizing to population (fixes #5)

parent 5c0b5cc4
Pipeline #294 passed with stage
in 5 seconds
......@@ -1418,7 +1418,7 @@ let updateChartData = (siteSelect) => {
// are we in for per-million values?
if (population_ratio) {
// we've set population ratio before already
to_chart.data = to_chart.data.map(row => Math.round(row / population_ratio))
to_chart.data = to_chart.data.map(row => Math.round((row * 100) / population_ratio) / 100)
}
// are we doing the incidence / rolling average thing?
......@@ -1431,7 +1431,7 @@ let updateChartData = (siteSelect) => {
to_chart.data = to_chart.data.reduce((acc, cur, idx, arr) => {
var mean = 0;
var sum = 0;
var avg_start = idx - avg_over + 1
var avg_end = idx
......@@ -1441,17 +1441,13 @@ let updateChartData = (siteSelect) => {
avg_start = 0
}
// calculate the mean
// calculate the sum
for (var j=avg_start; j<=avg_end; j++) {
mean += arr[j];
}
// if we're talking case fatality rate, we should not round
if (dataset === 'cfr') {
acc.push(mean / (avg_end - avg_start + 1))
// everything else nicely rounded
} else {
acc.push(Math.round(mean / (avg_end - avg_start + 1)))
sum += arr[j];
}
acc.push(
Math.round( (sum * 100) / (avg_end - avg_start + 1)) / 100
)
return acc
}, [])
......@@ -1575,7 +1571,7 @@ let updateChartSettings = () => {
}
// set the max value
theChart.options.scales.yAxes[0].ticks.max = Math.round((max_cases * chart_type_factor) * 1000) / 1000
theChart.options.scales.yAxes[0].ticks.max = Math.ceil((max_cases * chart_type_factor) * 1000) / 1000
var chart_start_setting = document.querySelector('input[type=radio][name=chart-start]:checked').value
if (chart_start_setting === "date") {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment