GithubHelp home page GithubHelp logo

sean-b765 / covid-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 219 KB

Find current or historical COVID-19 data. Uses JHU and OWID GitHub repositories as source.

TypeScript 99.87% Procfile 0.13%

covid-api's Introduction

COVID-19 API

NOTE Demo no longer working because heroku free tiers discontinued

Uses latest data from John Hopkins University. Historical data is pulled from the OWID repository, which collates all the previous dates into one CSV file. Current data is pulled from JHU's repository.

A worker thread is used to perform daily updates. Due to the free heroku plan idling when no activity is detected, these updates occur when the service is started. Your response may contain outdated data while the worker thread updates the database.

List all Locations

Some listings (e.g. Bermuda) are provinces belonging to a larger territory. Current data does not list Bermuda, as it is a province of the United Kingdom

https://covid-history.herokuapp.com/locations

Historical data

Use (almost) all options from /locations route, or continents, or World e.g.

https://covid-history.herokuapp.com/history/World

https://covid-history.herokuapp.com/history/North%20America

https://covid-history.herokuapp.com/history/India

type response = [
	{
		location: string
		data: [
			{
				date: string
				new_cases: string
				new_deaths: string
				total_cases: string
				total_deaths: string
				weekly_cases: string
				weekly_deaths: string
				biweekly_cases: string
				biweekly_deaths: string
			}
		]
	}
]

Current data

Will return a total for the country, as well as all provinces (if data exists) e.g.

https://covid-history.herokuapp.com/current/Australia

https://covid-history.herokuapp.com/current/United%20Kingdom

type response = [
	{
		location: string
		provinces: [
			{
				county: string
				zip: string
				state: string
				lat: string
				lng: string
				cumulative: string
				deaths: string
				recovered: string
			}
		]
		lat: string
		lng: string
		cumulative: string
		deaths: string
		recovered: string
	}
]

covid-api's People

Contributors

sean-b765 avatar

Watchers

 avatar

covid-api's Issues

Requests take too long when performing DB update

One way to fix this would be to use worker threads for DB update. This will allow requests to be fulfilled while the newest data is fetched. The request will not contain up-to-date data, though this is better then having an unresponsive service.

Performing DB update still makes requests take too long

After heroku has started from being idle, it will perform a DB update if it has been +12 hours since the last update. Heroku service=471ms shows that the request is being handled quickly, but the response must be taking long because MongoDB is being updated with so much data.

Large memory usage when handling historical data

Historical COVID data are very large. When performing DB append functions, such as appendHistorical(), the memory usage spikes to 1GB. Look for optimizations in append functions. Initial fetch functions don't need to be optimized.

US provinces are too many

Currently the JHU data contains about 3,300 provinces in the United States. These should be reduced down into the 52 states to reduce loading times

Bug: TypeError: Cannot read property 'provinces' of null

const appendCurrentDocs = (records) => __awaiter(void 0, void 0, void 0, function* () {
    const { dictionary } = parseCurrentRecords(records);
    // Simply loop through and set properties.
    //  use Promise.all to wait for all operations to complete
    yield Promise.all(Object.values(dictionary).map((value) => __awaiter(void 0, void 0, void 0, function* () {
        const current = yield Current_1.default.findOne({ location: value.location });
// LINE 365 below
        if (current.provinces.length !== 0) {
            current.cumulative = `${value.provinces
                .map((item) => Number(item.cumulative))
                .reduce((prev, next) => prev + next)}`;
            current.deaths = `${value.provinces
                .map((item) => Number(item.deaths))
                .reduce((prev, next) => prev + next)}`;
            current.recovered = `${value.provinces
                .map((item) => Number(item.recovered))
                .reduce((prev, next) => prev + next)}`;
        }
        else {
            current.cumulative = value.cumulative;
            current.deaths = value.deaths;
            current.recovered = value.recovered;
        }
        current.provinces = value.provinces;
        yield current.save();
    })));

Add try catch!

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.