Skip to content

Commit

Permalink
Introduced the new page in Deceased chart - daily deceased by age gro…
Browse files Browse the repository at this point in the history
…ups (not yet finished) (#770)
  • Loading branch information
breki committed Dec 24, 2020
1 parent 01c8a80 commit 6fb832d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TODO

- https://github.com/sledilnik/website/issues/770
- try to reuse code from AgeGroupsTimeline
- remove age groups that don't have any deceased

- new OWID export
- return back the official URL, once it has been pushed to production
Expand Down
3 changes: 2 additions & 1 deletion src/visualizations/AgeGroupsTimelineViz/Rendering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ let update (msg: Msg) (state: State) : State * Cmd<Msg> =
let renderChartOptions state dispatch =
let allSeries =
getAgeGroupTimelineAllSeriesData
state.Data state.Metrics.CasesMetricsType
state.Data state.Metrics.ValueCalculation
(fun dataPoint -> dataPoint.StatePerAgeToDate)

let onRangeSelectorButtonClick(buttonIndex: int) =
let res (_ : Event) =
Expand Down
10 changes: 5 additions & 5 deletions src/visualizations/AgeGroupsTimelineViz/Synthesis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ open JsInterop

type DisplayMetrics = {
Id: string
CasesMetricsType: CasesMetricsType
ValueCalculation: ValueCalculationFormula
ChartType: ChartType
}

let availableDisplayMetrics = [|
{ Id = "newCases"; CasesMetricsType = NewCases
{ Id = "newCases"; ValueCalculation = Daily
ChartType = StackedBarNormal }
{ Id = "newCasesRelative"; CasesMetricsType = NewCases
{ Id = "newCasesRelative"; ValueCalculation = Daily
ChartType = StackedBarPercent }
{ Id = "activeCases"; CasesMetricsType = ActiveCases
{ Id = "activeCases"; ValueCalculation = Active
ChartType = StackedBarNormal }
{ Id = "activeCasesRelative"; CasesMetricsType = ActiveCases
{ Id = "activeCasesRelative"; ValueCalculation = Active
ChartType = StackedBarPercent }
|]

Expand Down
20 changes: 12 additions & 8 deletions src/visualizations/DataAnalysis/AgeGroupsTimeline.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ type CasesInAgeGroupSeries = {
Timeline: CasesInAgeGroupTimeline
}

type CasesMetricsType = NewCases | ActiveCases
type ValueCalculationFormula = Daily | Active | Total

let extractTimelineForAgeGroup
ageGroupKey
(casesMetricsType: CasesMetricsType)
(calculationFormula: ValueCalculationFormula)
(casesTimeline: CasesByAgeGroupsTimeline)
: CasesInAgeGroupTimeline =

Expand All @@ -118,18 +118,21 @@ let extractTimelineForAgeGroup
dataForGroup.All
|> Utils.optionToInt
)
match casesMetricsType with
| NewCases -> newCasesTimeline
| ActiveCases ->
match calculationFormula with
| Daily -> newCasesTimeline
| Active ->
newCasesTimeline
|> mapDatedArray (Statistics.calculateWindowedSumInt 14)
| Total -> invalidOp "todo"

let getAgeGroupTimelineAllSeriesData
(statsData: StatsData)
(casesMetricsType: CasesMetricsType) =
(valueCalculationFormula: ValueCalculationFormula)
(pointAgeGroupListSelector: StatsDataPoint -> AgeGroupsList) =
let totalCasesByAgeGroupsList =
statsData
|> List.map (fun point -> (point.Date, point.StatePerAgeToDate))
|> List.map (fun point -> (point.Date,
point |> pointAgeGroupListSelector))

let totalCasesByAgeGroups =
mapDateTuplesListToArray totalCasesByAgeGroupsList
Expand Down Expand Up @@ -163,10 +166,11 @@ let getAgeGroupTimelineAllSeriesData
|> List.mapi (fun index ageGroupKey ->
let points =
timeline
|> extractTimelineForAgeGroup ageGroupKey casesMetricsType
|> extractTimelineForAgeGroup ageGroupKey valueCalculationFormula
|> mapAllPoints

pojo {|
``type`` = "column"
visible = true
name = ageGroupKey.Label
color = AgeGroup.ColorOfAgeGroup index
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/DeceasedViz/Rendering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let availablePages = [|
{ Id = "deceasedTodayRelative"
MetricsType = HospitalsToday; ChartType = StackedBarPercent }
{ Id = "deceasedToDateByAge"
MetricsType = ByAgeToDate; ChartType = StackedBarPercent }
MetricsType = ByAgeToDate; ChartType = StackedBarNormal }
|]

type Msg =
Expand Down
5 changes: 4 additions & 1 deletion src/visualizations/DeceasedViz/Synthesis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open Data.Patients
open DeceasedViz.Analysis
open DataAnalysis.AgeGroupsTimeline
open Types
open Highcharts

Expand Down Expand Up @@ -131,7 +132,9 @@ let renderAllHospitalSeriesData state =
hospitalSeries |> Array.map renderSeriesData

let renderAllAgeGroupsSeriesData state =
invalidOp "todo"
getAgeGroupTimelineAllSeriesData
state.StatsData Daily
(fun dataPoint -> dataPoint.DeceasedPerAgeToDate)

let renderAllSeriesData state =
match state.Page.MetricsType with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let ``Can extract data for individual age group``() =

let timeline =
sourceData
|> extractTimelineForAgeGroup (groupKey 1) NewCases
|> extractTimelineForAgeGroup (groupKey 1) Daily

test <@ timeline.StartDate = baseDate @>
test <@ timeline.Data = [| 15; 25 |] @>

0 comments on commit 6fb832d

Please sign in to comment.