Skip to content

Commit

Permalink
Replaced anonymous series record type with SeriesInfo (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
breki committed Dec 22, 2020
1 parent e830cf6 commit 4e03f20
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# TODO

- https://github.com/sledilnik/website/issues/770
- find out where the data is
- add pages buttons
- we cannot have single Series for different types of metrics

- new OWID export
- return back the official URL, once it has been pushed to production
Expand Down
28 changes: 5 additions & 23 deletions src/visualizations/DeceasedViz/Rendering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ type Msg =
| ChangeMetrics of DisplayMetrics
| RangeSelectionChanged of int

type Series =
| DeceasedInIcu
| DeceasedAcute
| DeceasedCare
| DeceasedOther

module Series =
let all =
[ DeceasedOther; DeceasedCare; DeceasedAcute; DeceasedInIcu ]

let getSeriesInfo = function
| DeceasedInIcu -> true, "#6d5b80", "deceased-icu"
| DeceasedAcute -> true, "#8c71a8", "deceased-acute"
| DeceasedCare -> true, "#a483c7", "deceased-care"
| DeceasedOther -> true, "#c59eef", "deceased-rest"

let init(statsData : StatsData) : DeceasedVizState * Cmd<Msg> =
let state = {
StatsData = statsData
Expand Down Expand Up @@ -97,20 +81,18 @@ let renderChartOptions (state : DeceasedVizState) dispatch =
let scaleType = ScaleType.Linear

let renderSeries series =

let visible, color, seriesId = Series.getSeriesInfo series
{|
``type`` = "column"
visible = visible
color = color
name = I18N.tt "charts.deceased" seriesId
visible = true
color = series.Color
name = I18N.tt "charts.deceased" series.SeriesId
data =
state.PatientsData
|> Seq.map (fun dataPoint ->
{|
x = dataPoint.Date |> jsTime12h
y = getPoint state series dataPoint
seriesId = seriesId
seriesId = series.SeriesId
fmtDate = I18N.tOptions "days.longerDate"
{| date = dataPoint.Date |}
fmtTotal =
Expand All @@ -122,7 +104,7 @@ let renderChartOptions (state : DeceasedVizState) dispatch =
|> pojo

let allSeries = [|
for series in Series.all do
for series in hospitalSeries() do
yield renderSeries series
|]

Expand Down
30 changes: 25 additions & 5 deletions src/visualizations/DeceasedViz/Synthesis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ type DeceasedVizState = {
Error : string option
}

type Series =
| DeceasedInIcu
| DeceasedAcute
| DeceasedCare
| DeceasedOther

type SeriesInfo = {
SeriesType: Series
SeriesId: string
Color: string
}

let subtract (a : int option) (b : int option) =
match a, b with
| Some aa, Some bb -> Some (bb - aa)
| Some aa, None -> -aa |> Some
| None, Some _ -> b
| _ -> None

let getPoint state series dataPoint : int option =
let getPoint state (series: SeriesInfo) dataPoint : int option =
match state.Metrics.MetricsType with
| HospitalsToday ->
match series with
match series.SeriesType with
| DeceasedInIcu -> dataPoint.total.deceased.hospital.icu.today
| DeceasedAcute ->
dataPoint.total.deceased.hospital.today
Expand All @@ -33,7 +45,7 @@ let getPoint state series dataPoint : int option =
|> subtract dataPoint.total.deceased.hospital.today
|> subtract dataPoint.total.deceasedCare.today
| HospitalsToDate ->
match series with
match series.SeriesType with
| DeceasedInIcu -> dataPoint.total.deceased.hospital.icu.toDate
| DeceasedAcute ->
dataPoint.total.deceased.hospital.toDate
Expand All @@ -47,14 +59,22 @@ let getPoint state series dataPoint : int option =
let getPointTotal state series dataPoint : int option =
match state.Metrics.MetricsType with
| HospitalsToday ->
match series with
match series.SeriesType with
| DeceasedInIcu -> dataPoint.total.deceased.hospital.icu.today
| DeceasedAcute -> dataPoint.total.deceased.hospital.today
| DeceasedCare -> dataPoint.total.deceasedCare.today
| DeceasedOther -> dataPoint.total.deceased.today
| HospitalsToDate ->
match series with
match series.SeriesType with
| DeceasedInIcu -> dataPoint.total.deceased.hospital.icu.toDate
| DeceasedAcute -> dataPoint.total.deceased.hospital.toDate
| DeceasedCare -> dataPoint.total.deceasedCare.toDate
| DeceasedOther -> dataPoint.total.deceased.toDate

let hospitalSeries() =
[
{ SeriesType = DeceasedInIcu; SeriesId = "deceased-icu"; Color = "#6d5b80" }
{ SeriesType = DeceasedAcute; SeriesId = "deceased-acute"; Color = "#8c71a8" }
{ SeriesType = DeceasedCare; SeriesId = "deceased-care"; Color = "#a483c7" }
{ SeriesType = DeceasedOther; SeriesId = "deceased-rest"; Color = "#c59eef" }
]

0 comments on commit 4e03f20

Please sign in to comment.