forked from pomber/covid19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
38,273 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
on: [push] | ||
|
||
jobs: | ||
extract_job: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
path: main | ||
- name: Checkout data repo | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: CSSEGISandData/COVID-19 | ||
path: data | ||
- name: Hello world action step | ||
uses: ./ # Uses an action in the root directory | ||
id: hello | ||
- name: Commit files | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add . | ||
git commit -m "Update json" -a | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const parse = require("csv-parse/lib/sync"); | ||
|
||
const WORKSPACE = process.env.GITHUB_WORKSPACE; | ||
const DATA_REPO = "data"; // from main.yml checkout action path | ||
const MAIN_REPO = "main"; // from main.yml checkout action path | ||
const FILENAME_CONFIRMED = "time_series_19-covid-Confirmed.csv"; | ||
const FILENAME_DEATHS = "time_series_19-covid-Deaths.csv"; | ||
const FILENAME_RECOVERED = "time_series_19-covid-Recovered.csv"; | ||
|
||
const dataPath = path.join( | ||
WORKSPACE, | ||
DATA_REPO, | ||
"csse_covid_19_data", | ||
"csse_covid_19_time_series" | ||
); | ||
const outputPath = path.join(WORKSPACE, MAIN_REPO, "docs", "timeseries.json"); | ||
|
||
function extract(filename) { | ||
const csv = fs.readFileSync(path.resolve(dataPath, filename)); | ||
const [headers, ...rows] = parse(csv); | ||
const [province, country, lat, long, ...dates] = headers; | ||
const countList = {}; | ||
|
||
rows.forEach(([province, country, lat, long, ...counts]) => { | ||
countList[country] = countList[country] || {}; | ||
dates.forEach((date, i) => { | ||
countList[country][date] = countList[country][date] || 0; | ||
countList[country][date] += +counts[i]; | ||
}); | ||
}); | ||
return [countList, dates]; | ||
} | ||
|
||
const [confirmed, dates] = extract(FILENAME_CONFIRMED); | ||
const [deaths] = extract(FILENAME_DEATHS); | ||
const [recovered] = extract(FILENAME_RECOVERED); | ||
const countries = Object.keys(confirmed); | ||
const results = {}; | ||
countries.forEach(country => { | ||
results[country] = dates.map(date => { | ||
const [month, day] = date.split("/"); | ||
return { | ||
date: `2020-${month}-${day}`, | ||
confirmed: confirmed[country][date], | ||
deaths: deaths[country][date], | ||
recovered: recovered[country][date] | ||
}; | ||
}); | ||
}); | ||
|
||
fs.writeFileSync(outputPath, JSON.stringify(results, null, 2)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: "Extract Time Series" | ||
runs: | ||
using: "node12" | ||
main: "action.js" |
Oops, something went wrong.