Options
All
  • Public
  • Public/Protected
  • All
Menu

Class COVID19API

A class that provides a simple API for interacting with the JHU CSSE COVID-19 time series data.

Hierarchy

  • COVID19API

Index

Constructors

constructor

Properties

Private _firstDate

_firstDate: Date | undefined

Private _lastDate

_lastDate: Date | undefined

Private _locations

_locations: string[] | undefined

Private _sourceLastUpdatedAt

_sourceLastUpdatedAt: Date | undefined

Private Readonly dataGetter

dataGetter: DataGetter

Private Readonly dataStore

dataStore: DataStore

Private Readonly dataValidityInMS

dataValidityInMS: number

Private isInitialized

isInitialized: boolean = false

Private Readonly lazyLoadUSData

lazyLoadUSData: boolean

Private Readonly onLoadingStatusChange

onLoadingStatusChange: ((isLoading: boolean, loadingMessage?: undefined | string) => void) | undefined

Accessors

firstDate

  • get firstDate(): Date

lastDate

  • get lastDate(): Date

locations

  • get locations(): string[]

sourceLastUpdatedAt

  • get sourceLastUpdatedAt(): Date | undefined
  • Returns the date and time the source of the data was last updated at.

    If the data getter is not able to get the date that the source was last updated on, it might return undefined.

    throws

    COVID19APINotInitializedError Thrown when the API instance is not initialized by calling the init method first.

    Returns Date | undefined

Methods

Private addCalculatedValues

  • The internal location data only includes confirmed cases, deaths and recoveries data. This method adds extra calculated values to the data, such as new confirmed cases and case fatality rate.

    Parameters

    Returns LocationData

getDataByLocation

  • getDataByLocation(location: string): Promise<LocationData>
  • Returns the location data for the given location name.

    If the API is initialized to lazy load the US data, calling this also automatically loads the US data if the given location name is of a US county or state.

    throws

    COVID19APINotInitializedError Thrown when the API instance is not initialized by calling the init method first.

    throws

    DataStoreInvalidLocationError Thrown when the given location cannot be found in the store.

    throws

    DataGetterError Thrown when there is an error getting the data.

    Parameters

    • location: string

      The full name of the location, e.g. "US (Autauga, Alabama)".

    Returns Promise<LocationData>

getDataByLocationAndDate

  • getDataByLocationAndDate(location: string, date: Date): Promise<ValuesOnDate | undefined>
  • Returns the location data for the given location name and date.

    If the API is initialized to lazy load the US data, calling this also automatically loads the US data if the given location name is of a US county or state.

    throws

    COVID19APINotInitializedError Thrown when the API instance is not initialized by calling the init method first.

    throws

    DataStoreInvalidLocationError Thrown when the given location cannot be found in the store.

    throws

    DataGetterError Thrown when there is an error getting the data.

    Parameters

    • location: string

      The full name of the location, e.g. "US (Autauga, Alabama)".

    • date: Date

    Returns Promise<ValuesOnDate | undefined>

    A Promise that will resolve to a ValuesOnDate object, of undefined if there is no data available for the given date.

getDataByLocations

  • getDataByLocations(locations: string[]): Promise<LocationData[]>
  • Returns the location data for the given location names.

    If the API is initialized to lazy load the US data, calling this also automatically loads the US data if one of the given location names is of a US county or state.

    throws

    COVID19APINotInitializedError Thrown when the API instance is not initialized by calling the init method first.

    throws

    DataStoreInvalidLocationError Thrown when the given location cannot be found in the store.

    throws

    DataGetterError Thrown when there is an error getting the data.

    Parameters

    • locations: string[]

      An array containing the full names of the locations, e.g. ["US (Autauga, Alabama)", "Turkey"].

    Returns Promise<LocationData[]>

Private getParsedGlobalConfirmedData

  • getParsedGlobalConfirmedData(): Promise<ParsedCSV>

Private getParsedGlobalDeathsData

  • getParsedGlobalDeathsData(): Promise<ParsedCSV>

Private getParsedGlobalRecoveredData

  • getParsedGlobalRecoveredData(): Promise<ParsedCSV>

Private getParsedUSConfirmedData

  • getParsedUSConfirmedData(): Promise<ParsedCSV>

Private getParsedUSDeathsData

  • getParsedUSDeathsData(): Promise<ParsedCSV>

Private hasFreshDataInStore

  • hasFreshDataInStore(): Promise<boolean>
  • Checks if the data store already has data AND it is not stale, i.e. hasn't expired based on the dataValidityInMS option.

    Returns Promise<boolean>

Private hasUSDataInStore

  • hasUSDataInStore(): Promise<boolean>
  • Returns true if the data store already has US county-level data.

    Returns Promise<boolean>

init

  • init(): Promise<void>

Private loadDataIfStoreHasNoFreshData

  • loadDataIfStoreHasNoFreshData(forceLoadUSData?: boolean): Promise<void>
  • Loads data if the store does not have data or the data in the store is expired.

    throws

    DataGetterError Thrown when there is an error getting the data.

    Parameters

    • Default value forceLoadUSData: boolean = false

      When true, loads the US county-level data even when lazyLoadUSData option is also set to true.

    Returns Promise<void>

Private loadGlobalData

  • loadGlobalData(): Promise<void>
  • Loads the data global confirmed cases, deaths and recoveries data from the data store.

    throws

    DataGetterError Thrown when there is an error getting the data.

    Returns Promise<void>

Private loadUSStateAndCountyData

  • loadUSStateAndCountyData(): Promise<void>
  • Loads the US state and county data for confirmed cases and deaths from the data store.

    throws

    DataGetterError Thrown when there is an error getting the data.

    Returns Promise<void>

Private setFirstAndLastDates

  • setFirstAndLastDates(): Promise<void>
  • Internally sets the first and the last date that the data store has data for.

    Returns Promise<void>

Private setLocations

  • setLocations(): Promise<void>
  • Internally sets the list of locations that are available in the data store, as well as the US state and county location names even if they are not yet loaded, so that they can still be requested even when they are lazy loaded.

    Returns Promise<void>

Private setSourceLastUpdatedAt

  • setSourceLastUpdatedAt(): Promise<void>
  • Internally sets the date that the source of the data was last updated.

    When using GitHubGetter, this is the last commit date of the source CSV files.

    Returns Promise<void>

Static Private getParsedData

  • getParsedData(csvPromise: Promise<string>): Promise<ParsedCSV>
  • Returns a parsed version of the given string containing comma separated values.

    Parameters

    • csvPromise: Promise<string>

    Returns Promise<ParsedCSV>

Generated using TypeDoc