From 8757f15c0dbb5c88c65cd165ab9d29360e27079b Mon Sep 17 00:00:00 2001 From: frankknoll Date: Tue, 15 Mar 2022 09:27:49 +0100 Subject: [PATCH] refactoring --- docs/intensivstationen.html | 13 +++++-------- docs/intensivstationen.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/docs/intensivstationen.html b/docs/intensivstationen.html index def195e81df..4a12795eabb 100644 --- a/docs/intensivstationen.html +++ b/docs/intensivstationen.html @@ -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 }); } diff --git a/docs/intensivstationen.js b/docs/intensivstationen.js index 4f50b3cc2d7..1cc0aece53a 100644 --- a/docs/intensivstationen.js +++ b/docs/intensivstationen.js @@ -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 + } + )); +}