Interface NonEmptyTimeseries<T>

An extension of the Timeseries class that can be used to represent a timeseries that is known to be non-empty, allowing for non-nullable return types for various methods.

Example

Typically you get a NonEmptyTimeseries by using the hasData() type guard, e.g.:

if (ts.hasData()) {
// ts is now a NonEmptyTimeseries so we can e.g. call last() without
// checking for null or undefined.
console.log(ts.last().value);
}

Type Parameters

  • T

Hierarchy

Properties

points: TimeseriesPoint<T>[]

Accessors

  • get firstValue(): T
  • The first value in the timeseries, or undefined if the timeseries is empty.

    You can use hasData to guard against the timeseries being empty and ensure this can't return undefined.

    Returns T

  • get lastValue(): T
  • The last value in the timeseries or undefined if the timeseries is empty.

    You can use hasData to guard against the timeseries being empty and ensure this can't return undefined.

    Returns T

  • get maxDate(): Date
  • The maximum (latest) date in the timeseries.

    You can use hasData to guard against the timeseries being empty and ensure this can't return undefined.

    Returns Date

  • get maxValue(): T
  • The maximum value in the timeseries.

    You can use hasData to guard against the timeseries being empty and ensure this can't return undefined.

    Returns T

  • get minDate(): Date
  • The minimum (earliest) date in the timeseries.

    You can use hasData to guard against the timeseries being empty and ensure this can't return undefined.

    Returns Date

  • get minValue(): T
  • The minimum value in the timeseries.

    You can use hasData to guard against the timeseries being empty and ensure this can't return undefined.

    Returns T

Methods

  • Computes deltas between each point in the timeseries.

    Returns

    A timeseries made up of the deltas between timeseries points.

    Parameters

    • Optional opts: {
          keepInitialValue?: boolean;
          minDeltaToKeep?: number;
      }
      • Optional keepInitialValue?: boolean

        Whether to include the initial value in the series as a delta (with an assumed prior value of 0).

      • Optional minDeltaToKeep?: number

        The minimum delta to keep. By default all deltas are kept, but can be set to 0 to drop negative deltas or 1 to only keep positive deltas.

    Returns Timeseries<number>

  • Filters the timeseries by calling the provided filterFn on each value in the timeseries.

    Returns

    A new timeseries with the filtered points.

    Parameters

    • filterFn: ((val: T) => boolean)

      The function to call on each value in the timeseries. If it returns true, the point will be kept, else discarded.

        • (val: T): boolean
        • Parameters

          • val: T

          Returns boolean

    Returns Timeseries<T>

  • Returns the point with the date closest to the provided date, or undefined if the timeseries is empty.

    You can use hasData to guard against the timeseries being empty and ensure this can't return undefined.

    Returns

    The point with the date closest to the provided date or undefined if the timeseries is empty.

    Parameters

    • date: Date

      The date to find the closest point to.

    Returns TimeseriesPoint<T>

  • Returns a new timeseries with the values in the timeseries mapped to new values using the provided mapFn function.

    Returns

    A new timeseries with the mapped points.

    Type Parameters

    • R = T

    Parameters

    • mapFn: ((val: T) => R)

      The function to call on each value in the timeseries. The return value is used as the point's value in the new timeseries.

        • (val: T): R
        • Parameters

          • val: T

          Returns R

    Returns Timeseries<R>

  • Computes a rolling average of the timeseries where each point represents the average of the prior opts.days days of data points.

    Returns

    A new timeseries containing the rolling average of the original one.

    Parameters

    • opts: {
          days: number;
          treatMissingDatesAsZero?: boolean;
      }
      • days: number

        The number of days to average over.

      • Optional treatMissingDatesAsZero?: boolean

        Whether to treat missing dates as 0. This is typically what you want for "incidence" metrics (like "daily new cases") but not "current" metrics (like "% of beds in use").

    Returns Timeseries<number>

  • Returns a new Timeseries from the slice of data points indicated by the provided start and end indices.

    Example

    ts.slice(2, 4); // Returns a Timeseries with the 3rd and 4th points.
    

    Returns

    A new Timeseries with the sliced data points.

    Parameters

    • start: number

      The first index to be included in the new Timeseries.

    • Optional end: number

      The first index not to be included in the new Timeseries.

    Returns Timeseries<T>

  • Breaks the timeseries into overlapping windows of the specified size and makes a new timeseries from them. Handy for computing aggregations like a rolling average.

    Returns

    A new timeseries that has a point for every point in the original timeseries, but contains a TimeseriesWindow object containing the window of points leading up to that point.

    Parameters

    • opts: {
          days: number;
      }
      • days: number

        The number of days to include in each window. Note that the points at the beginning of the timeseries will have a smaller window due to no prior history.

    Returns Timeseries<TimeseriesWindow<T>>

Generated using TypeDoc