Created
March 15, 2020 03:22
-
-
Save bergel/6ebcde9696ef922f2b519c56a4520bac to your computer and use it in GitHub Desktop.
Comparing the number of infected people of the coronavirus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" | |
This script of the day compare confirmed cases for the Coronavirus (COVID-19). | |
It uses a reliable source of data, which is provided by Johns Hopkins University Center for Systems Science and Engineering (JHU CSSE). | |
Website of the data: https://github.com/CSSEGISandData/COVID-19 | |
Before running the script, you need to have Roassal3 and DataFrame installed. Simply execute: | |
Metacello new | |
baseline: 'Roassal3'; | |
repository: 'github://ObjectProfile/Roassal3'; | |
load. | |
Metacello new | |
baseline: 'DataFrame'; | |
repository: 'github://PolyMathOrg/DataFrame:v2.0/src'; | |
load. | |
" | |
"Indicate here the countries you wish to compare" | |
countries := #('France' 'Spain' 'Italy' 'Germany'). | |
url := 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv'. | |
content := (ZnEasy get: url) contents. | |
dataFrame := DataFrame | |
readFromCsv: content readStream contents | |
withSeparator: $,. | |
"Could be that the last columns is empty" | |
((dataFrame columnAt: dataFrame numberOfColumns) asSet includes: nil) | |
ifTrue: [ nbColumns := dataFrame numberOfColumns - 1 ] | |
ifFalse: [ nbColumns := dataFrame numberOfColumns ]. | |
allDataSum := OrderedCollection new. | |
"TSScale google20" | |
color := TSScale category20. | |
countries do: [ :country | | |
dataSum := OrderedCollection new. | |
subDataFrame := dataFrame select: [ :row | row second = country ]. | |
5 to: nbColumns do: [ :index | | |
dataSum add: (subDataFrame columnAt: index) sum ]. | |
allDataSum add: dataSum. | |
]. | |
columnNames := dataFrame columnNames allButFirst: 4. | |
indexX := (1 to: nbColumns - 4) reversed negated. | |
chart := RSChart new. | |
chart extent: 400 @ 400. | |
chart colors: color. | |
allDataSum do: [ :data | | |
chart addPlot:(RSLinePlot new x: indexX y: data). | |
]. | |
chart xlabel: 'Days ago'. | |
chart ylabel: 'Contaminated'. | |
chart title: 'Coronavirus confirmed cases'. | |
chart addDecoration: (RSHorizontalTick new integer; fontSize: 10). | |
chart addDecoration: (RSVerticalTick new integerWithCommas; fontSize: 10). | |
chart build. | |
b := RSLegend new. | |
b container: chart canvas. | |
countries with: chart plots do: [ :c : p | | |
b text: c withBoxColor: (chart colorFor: p) ]. | |
b leyendDo: [ :l | | |
l | |
withBorder; | |
padding: 10 ]. | |
b layout horizontal gapSize: 30. | |
b build. | |
b canvas @ RSCanvasController. | |
^ b canvas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment