refactoring

This commit is contained in:
frankknoll
2022-03-15 09:27:49 +01:00
parent dd4d521918
commit 8757f15c0d
2 changed files with 26 additions and 8 deletions

View File

@@ -36,14 +36,11 @@
kreisText: selectedOption.text,
kreisValue: selectedOption.value
});
// FK-TODO: extract method
fetch(`data/intensivstationen/intensivstationen-${selectedOption.value}.json`)
.then(response => response.json())
.then(json => {
for (const dataElement of json.data) {
dataElement.free_beds_divided_by_all_beds_in_percent = dataElement.betten_frei / (dataElement.betten_frei + dataElement.betten_belegt) * 100;
}
freeBedsChartView.displayChart({ data: json.data, title: selectedOption.text });
displayFreeBedsChart(
{
freeBedsChartView: freeBedsChartView,
kreisText: selectedOption.text,
kreisValue: selectedOption.value
});
}
</script>

View File

@@ -9,3 +9,24 @@ function displayIntensiveCareCapacitiesChart(
intensiveCareCapacitiesChartView.displayChart({ data: json.data, title: kreisText });
});
}
function displayFreeBedsChart({ freeBedsChartView, kreisText, kreisValue }) {
fetch(`data/intensivstationen/intensivstationen-${kreisValue}.json`)
.then(response => response.json())
.then(json =>
freeBedsChartView.displayChart(
{
data: get_free_beds_divided_by_all_beds_in_percent(json.data),
title: kreisText
}));
}
function get_free_beds_divided_by_all_beds_in_percent(data) {
return data.map(({ date, betten_frei, betten_belegt }) =>
(
{
"date": date,
"free_beds_divided_by_all_beds_in_percent": betten_frei / (betten_frei + betten_belegt) * 100
}
));
}