The covid19.js library can be used to create web applications based off covid19 data. The original data source is the CSSEGISandData/COVID-19 repository by Johns Hopkins CSSE, and leverages the coviddata/coviddata repository for more reliable data formatting.
DISCLAIMER: This library should only be used for personal projects. If you decide to publish results based on data fetched, or models used, in this library you are accountable for the correctness of any and all results.
<script src="covid19.min.js"></script>
<script src='https://collaboratescience.com/covid19/covid19.min.js'></script>
There is a ~1 second delay before all required files are loaded to run covid19.js. To ensure your application does not call a method that is unavailable you can check the library's ready state like this:
covid.is_ready == true
az.call_once_satisfied({
"condition" : "covid.is_ready",
"function" : function() {
az.load_scripts([scripts/prepare.js", "scripts/responsive.js", "scripts/visuals.js"]) // load your application's scripts here
}
})
covid.countries
country:
key: "united-states"
name: "United States"
dates:
2020-01-22:
new:
cases: 1
deaths: 0
recoveries: 0
cumulative:
cases: 1
deaths: 0
recoveries: 0
covid.regions
region:
key: "hubei-china"
name: "Hubei"
full_name: "Hubei, China"
country:
location_type: "country"
key: "china"
name: "China"
dates:
2020-01-22:
new:
cases: 444
deaths: 17
recoveries: 28
cumulative:
cases: 444
deaths: 17
recoveries: 28
covid.places
place:
key: "new-york-city-new-york-united-states"
name: "New York City"
full_name: "New York City, New York, United States"
country:
location_type: "country"
key: "united-states"
name: "United States"
region:
location_type: "region"
key: "new-york-united-states"
name: "New York"
full_name: "New York, United States"
country:
location_type: "country"
key: "united-states"
name: "United States"
dates:
2020-03-01:
new:
cases: 1
deaths: 0
recoveries: 0
cumulative:
cases: 1
deaths: 0
recoveries: 0
- @returns {object} (summary object with global total cases, deaths, recoveries)
covid.get_global_report()
{cases: 531574, deaths: 24016, recoveries: 123334}
- @param {string} location (choose location)
- @returns {object} (summary object with country total cases, deaths, recoveries)
covid.get_location_report("Wyoming")
{cases: 53, deaths: 0, recoveries: 0}
- @param {string} category (choose between cumulative and new)
- @param {string} type (choose between cases, deaths, and recoveries)
- @param {string} location (choose country, region, or fips)
- @returns {object} (time series object for chosen location)
covid.get_time_series("cumulative", "cases", "California")
[
...
{date: "2020-03-21", value: 1364},
{date: "2020-03-22", value: 1646},
{date: "2020-03-23", value: 2108},
{date: "2020-03-24", value: 2538},
{date: "2020-03-25", value: 2998},
{date: "2020-03-26", value: 3899}
]
- @param {string} category (choose between cumulative and new)
- @param {string} type (choose between cases, deaths, and recoveries)
- @param {string} location_arr (an array of countries, regions, or fips)
- @returns {object} (time series object of all time series for chosen locations)
covid.get_time_series_multiple("cumulative", "cases", ["Germany", "Italy", "France", "United Kingdom"])
{
Germany: (62) [{…}, {…}, {…}, {…}, ...
Italy: (59) [{…}, {…}, {…}, {…}, ...
France: (66) [{…}, {…}, {…}, {…}, ...
United Kingdom: (59) [{…}, {…}, {…}, {…}, ....
}
- @param {string} category (choose between cumulative and new)
- @param {string} type (choose between cases, deaths, and recoveries)
- @param {string} location_arr (an array of countries, regions, or fips)
- @returns {object} (time series object with summed time series for locations chosen)
covid.get_time_series_multiple_sum("cumulative", "cases", ["Germany", "Italy", "France", "United Kingdom"])
{
2020-01-28: 8,
2020-01-29: 9,
2020-01-30: 9,
2020-01-31: 14,
2020-02-01: 18,
...
}
- @param {string} type (sort by cases, deaths, or recoveries)
- @param {string} sort_order (choose between descending (this is default), ascending)
- @returns {array of objects} (array of objects sorted by chosen type and sort order)
covid.sort_reports_by_type("deaths", "descending")
[
{cases: 143626, deaths: 18279, recoveries: 28471, location: "Italy"},
{cases: 461437, deaths: 16478, recoveries: 25581, location: "United States"},
{cases: 153222, deaths: 15447, recoveries: 52165, location: "Spain"},
{cases: 118781, deaths: 12228, recoveries: 23413, location: "France"},
{cases: 65872, deaths: 7993, recoveries: 359, location: "United Kingdom"}
...
]
- @param {string} category (choose between cumulative and new)
- @param {string} type (choose between cases, deaths, and recoveries)
- @returns {object} (object sorted by growth rate by country (assumes exponential growth))
covid.get_all_growth_rates_country("cumulative", "cases")
{
South Sudan: 0.29,
Niger: 0.24,
Guinea: 0.21,
Djibouti: 0.19,
Russia: 0.18,
Belarus: 0.18,
Guinea-Bissau: 0.18
...
}
- @returns {array} (all countries listed in data)
covid.get_all_countries()
[
"Thailand",
"Japan",
"Singapore",
"Nepal",
"Malaysia",
"Canada",
"Australia",
"Cambodia"
...
]
- @returns {array} (all regions listed in data)
covid.get_all_regions()
[
"Washington",
"New York",
"California",
"Massachusetts",
"Diamond Princess",
"Grand Princess",
"Georgia"
...
]
- @returns {array} (all places listed in data)
covid.get_all_places()
[
"New York City",
"Westchester",
"Nassau",
"Suffolk","
...
]
- @returns {array} (all fips listed in data)
covid.get_all_fips()
[
"45001",
"22001",
"51001",
"16001",
"19001",
...
]
- @param {string} place (choose place)
- @returns {array with object} (fips associated with place)
covid.get_fips_from_place("New York City")
[{
FIPS: "36061",
Province_State: "New York"
}]
- @param {string} fips (choose fips)
- @returns {array with object} (place details associated with fips)
covid.get_place_from_fips("48027")
[{
FIPS: "48027",
place: "Bell",
Province_State: "Texas",
Country_Region: "US"
}]
- @param {string} country (choose country)
- @returns {boolean} (true/false whether chosen country has states)
covid.check_if_country_has_region("Italy")
false
- @returns {array} (all available dates in data)
covid.get_available_dates()
[
...
"03-12-2020",
"03-13-2020",
"03-14-2020",
"03-15-2020",
"03-16-2020",
"03-17-2020",
"03-18-2020",
"03-19-2020"
]
- @returns {array} (array of objects with all country and region pairs)
covid.get_countries_and_regions()
[
{country: "China", region: "Hubei"},
{country: "United States", region: "New York"},
{country: "France", region: "France"},
{country: "United States", region: "New Jersey"},
{country: "United Kingdom", region: "United Kingdom"},
{country: "United States", region: "California"}
...
]
- @param {string} region (choose region)
- @returns {string} (name of country associated with region)
covid.get_country_from_region("Faroe Islands")
"Denmark"
- @param {string} country (choose country)
- @returns {array} (all regions associated with country)
covid.get_regions_from_country("Canada")
[
"Alberta",
"British Columbia",
"Diamond Princess",
"Manitoba",
"New Brunswick",
"Newfoundland and Labrador",
"Nova Scotia"
...
]
- @param {string} country (choose country)
- @returns {string} (country code associated with country)
covid.find_code_by_country("Dominican")
"DO"
- @param {string} region (choose region)
- @returns {string} (country code associated with region)
covid.find_code_by_region("Gibraltar")
"GB"
- @param {string} location (choose location)
- @returns {boolean} (true/false depending on whether location is in data)
covid.check_if_location_in_data("Los Angeles")
false
- @param {string} country_or_region (choose country_or_region)
- @returns {boolean} (true/false depending on whether location is a country)
covid.check_if_country("Italy")
true
- @param {string} country_or_region (choose country_or_region)
- @returns {boolean} (true/false depending on whether location is a region)
covid.check_if_region("Canada")
false
- @param {string} location (choose location)
- @returns {string} (image URL of country or region flag)
covid.get_country_flag("Bulgaria")
"https://collaboratescience.com/corona/flags/bg.png"
- @param {float} beta (choose rate of infection)
- @param {float} gamma (choose rate of recovery)
- @returns {array} (plottable x and y values for all 3 compartments (susceptible, infectious and recovered/removed))
covid.run_sir_model(0.1, 0.05)
[
{name: "S", x: Array(2001), y: Array(2001)},
{name: "I", x: Array(2001), y: Array(2001)},
{name: "R", x: Array(2001), y: Array(2001)}
]
- @param {object} time_series (pass time_series calculated using get_time_series method)
- @param {string} type (type of regression between linear, exponential, logarithmic, power, and polynomial)
@returns {object} (regression object containing predicted_results, r_squared, equation and predict function)
- predicted_results: plottable x (index) and y (predicted) values presented in same format as results from get_time_series method)
- r_squared: coefficient of determination (proportion of variance explained by independent variables)
- equation: string representation of equation with solved parameters
- predict function: a function that can be used to predict a new value
var my_series = covid.get_time_series("cumulative", "cases", "Canada")
var reg_results = covid.run_regression_on_time_series(my_series, "exponential")
{
predicted_results : [
...
{index: 61, value: 2879.86},
{index: 62, value: 2949.76},
{index: 63, value: 3019.66},
{index: 64, value: 3089.56},
{index: 65, value: 3159.46},
{index: 66, value: 3229.36}
],
r_squared : 0.87,
equation : "y = 0.05e^(0.19x)",
predict : x => {…}
}
reg_results.predict(70)
[70, 3508.96]
Reach out to Sean McClure if you need assistance or would like to see additional useful functions added to this library.
If you encounter issues with the consistency of results returned by this library please raise an issue on this repo.