Skip to content

Instantly share code, notes, and snippets.

@pkese
Created October 24, 2021 11:05
Show Gist options
  • Save pkese/8172242fd869d09d21742470fb136865 to your computer and use it in GitHub Desktop.
Save pkese/8172242fd869d09d21742470fb136865 to your computer and use it in GitHub Desktop.
Fetch vaccinations vs hospitalizations data from Our World In Data
<html>
<head>
<title>Covid vaccinations vs hospitalizations</title>
<script src="https://code.highcharts.com/highcharts.src.js"></script>
</head>
<body>
<figure class="highcharts-figure">
<div id="container" style="width:100%; height:100%;"></div>
</figure>
<script>
let data_hosps = [
{"name":"Austria","x":72.21,"y":61.22,"date":"2021-10-17"},
{"name":"Belgium","x":73.59,"y":73.15,"date":"2021-10-17"},
{"name":"Bulgaria","x":875.06,"y":20.08,"date":"2021-10-17"},
{"name":"Croatia","x":205.55,"y":40.03,"date":"2021-10-10"},
{"name":"Cyprus","x":66.96,"y":62.97,"date":"2021-10-14"},
{"name":"Czechia","x":47.83,"y":56.22,"date":"2021-10-17"},
{"name":"Denmark","x":20.64,"y":75.64,"date":"2021-10-17"},
{"name":"Estonia","x":312.41,"y":54.91,"date":"2021-10-17"},
{"name":"Finland","x":34.97,"y":67.01,"date":"2021-10-17"},
{"name":"France","x":95.44,"y":67.23,"date":"2021-10-17"},
{"name":"Hungary","x":83.04,"y":59.16,"date":"2021-10-17"},
{"name":"Iceland","x":8.74,"y":80.92,"date":"2021-10-14"},
{"name":"Ireland","x":92.11,"y":74.86,"date":"2021-10-17"},
{"name":"Israel","x":50.97,"y":64.98,"date":"2021-10-22"},
{"name":"Italy","x":45.31,"y":70.03,"date":"2021-10-17"},
{"name":"Latvia","x":481.54,"y":50.31,"date":"2021-10-17"},
{"name":"Lithuania","x":524.93,"y":61.04,"date":"2021-10-14"},
{"name":"Malta","x":23.32,"y":82.60,"date":"2021-10-17"},
{"name":"Netherlands","x":23.93,"y":68.31,"date":"2021-10-17"},
{"name":"Norway","x":17.38,"y":67.85,"date":"2021-10-15"},
{"name":"Poland","x":81.41,"y":52.20,"date":"2021-10-17"},
{"name":"Portugal","x":35.01,"y":86.42,"date":"2021-10-11"},
{"name":"Serbia","x":966.82,"y":42.58,"date":"2021-10-19"},
{"name":"Slovakia","x":163.16,"y":41.80,"date":"2021-10-17"},
{"name":"Slovenia","x":197.72,"y":52.92,"date":"2021-10-17"},
{"name":"Spain","x":39.66,"y":79.21,"date":"2021-10-14"},
{"name":"Sweden","x":21.36,"y":66.84,"date":"2021-10-15"},
{"name":"Switzerland","x":41.99,"y":62.15,"date":"2021-10-21"},
{"name":"United Kingdom","x":120.78,"y":66.69,"date":"2021-10-21"},
{"name":"United States","x":145.55,"y":56.55,"date":"2021-10-22"},
];
let data_deaths = [
{"name":"Albania","x":3.13,"y":29.94,"date":"2021-10-18"},
{"name":"Austria","x":1.22,"y":61.52,"date":"2021-10-21"},
{"name":"Belarus","x":1.69,"y":19.73,"date":"2021-10-17"},
{"name":"Belgium","x":1.63,"y":73.24,"date":"2021-10-21"},
{"name":"Bulgaria","x":19.72,"y":20.74,"date":"2021-10-22"},
{"name":"Croatia","x":4.17,"y":43.31,"date":"2021-10-21"},
{"name":"Cyprus","x":2.23,"y":63.26,"date":"2021-10-20"},
{"name":"Czechia","x":0.56,"y":56.41,"date":"2021-10-22"},
{"name":"Denmark","x":0.34,"y":75.73,"date":"2021-10-21"},
{"name":"Estonia","x":4.53,"y":55.34,"date":"2021-10-21"},
{"name":"Finland","x":0.72,"y":67.98,"date":"2021-10-22"},
{"name":"France","x":0.58,"y":67.50,"date":"2021-10-21"},
{"name":"Germany","x":1.30,"y":65.53,"date":"2021-10-21"},
{"name":"Greece","x":3.47,"y":61.08,"date":"2021-10-22"},
{"name":"Hungary","x":2.08,"y":59.32,"date":"2021-10-21"},
{"name":"Ireland","x":12.64,"y":74.97,"date":"2021-10-20"},
{"name":"Israel","x":0.34,"y":64.98,"date":"2021-10-22"},
{"name":"Italy","x":0.65,"y":70.62,"date":"2021-10-22"},
{"name":"Kosovo","x":0.56,"y":38.05,"date":"2021-10-19"},
{"name":"Latvia","x":13.39,"y":51.78,"date":"2021-10-22"},
{"name":"Liechtenstein","x":52.28,"y":60.32,"date":"2021-10-12"},
{"name":"Lithuania","x":12.27,"y":61.13,"date":"2021-10-21"},
{"name":"Moldova","x":9.44,"y":21.07,"date":"2021-10-22"},
{"name":"Montenegro","x":4.78,"y":37.75,"date":"2021-10-22"},
{"name":"Netherlands","x":0.35,"y":68.31,"date":"2021-10-17"},
{"name":"North Macedonia","x":9.60,"y":36.73,"date":"2021-10-20"},
{"name":"Norway","x":1.65,"y":68.00,"date":"2021-10-20"},
{"name":"Poland","x":1.22,"y":52.37,"date":"2021-10-21"},
{"name":"Portugal","x":0.29,"y":86.82,"date":"2021-10-18"},
{"name":"Romania","x":23.42,"y":30.21,"date":"2021-10-21"},
{"name":"Russia","x":7.11,"y":32.61,"date":"2021-10-22"},
{"name":"Serbia","x":8.25,"y":42.58,"date":"2021-10-19"},
{"name":"Slovakia","x":0.55,"y":41.93,"date":"2021-10-22"},
{"name":"Slovenia","x":3.37,"y":53.37,"date":"2021-10-21"},
{"name":"Spain","x":0.43,"y":79.58,"date":"2021-10-21"},
{"name":"Sweden","x":0.69,"y":67.37,"date":"2021-10-22"},
{"name":"Switzerland","x":0.57,"y":62.15,"date":"2021-10-21"},
{"name":"Ukraine","x":14.72,"y":15.91,"date":"2021-10-22"},
{"name":"United Kingdom","x":1.73,"y":66.69,"date":"2021-10-21"},
{"name":"United States","x":6.49,"y":56.55,"date":"2021-10-22"},
];
//let [data, xaxis_name] = [data_deaths, "Deaths"];
let [data, xaxis_name] = [data_hosps, "Hospitalizations"];
Highcharts.chart('container', {
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: `Vaccination rate vs ${xaxis_name}`
},
subtitle: {
text: 'Source: OurWorldInData'
},
xAxis: {
title: {
enabled: true,
text: `${xaxis_name} per million`
},
type: "logarithmic",
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
title: {
text: '% fully vaccinated'
}
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
//headerFormat: '{series.name}<br>',
pointFormat: `<b>{point.name}</b><br/>{point.y}% vaccinated<br/>{point.x} ${xaxis_name.toLowerCase()} per million<br/>Updated: {point.date}`
}
},
series: {
dataLabels:{
enabled: true,
format: '{point.name}'
}
},
},
series: [{
name: 'Hospitalizations',
//color: 'rgba(223, 83, 83, .5)',
data: data
}]
});
</script>
</body>
</html>
#!/usr/bin/env -S dotnet fsi
#r "nuget: FSharp.Data, 4.2.4"
open System
open FSharp.Data
[<Literal>]
let owidFile = "/home/peter/src/covid/owid-covid-data.csv"
type OwidData = CsvProvider<owidFile, InferRows=0>
//let csvData = OwidData.Load(owidFile)
let csvData = OwidData.Load("https://covid.ourworldindata.org/data/owid-covid-data.csv")
let validCountry (r: OwidData.Row) =
r.Continent = "Europe" || r.Location = "United States" || r.Location = "Israel"
let minDate = DateTime.Today - TimeSpan.FromDays 14.0
csvData.Rows
|> Seq.choose (fun r ->
let x = float r.Hosp_patients_per_million
//let x = float r.New_deaths_smoothed_per_million
//let x = float r.New_deaths_per_million
//let x = float r.Excess_mortality_cumulative_per_million
let y = float r.People_fully_vaccinated_per_hundred
if Double.IsNormal x && Double.IsNormal y && r.Date >= minDate && validCountry r
then Some (r.Location, {| name = r.Location; x=x; y=y; date=r.Date |})
else None
)
|> Map.ofSeq // keep the last item for each country
|> Map.toSeq
|> Seq.sortBy fst
|> Seq.iter (fun (_,d) -> printfn """ {"name":"%s","x":%.2f,"y":%.2f,"date":"%s"},""" d.name d.x d.y (d.date.ToString "yyyy-MM-dd"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment