Ejemplo n.º 1
0
 def _has_recent_data(self, series: pd.Series) -> bool:
     """Returns True iff series has recent data relative to today().
     TODO(tom): Replace with something that uses most_recent_date instead of a global clock.
     """
     return series_utils.has_recent_data(series,
                                         days_back=self.recent_days,
                                         required_non_null_datapoints=1)
    def actual_current_icu_total(self) -> Optional[pd.Series]:
        actuals = self._data[CommonFields.CURRENT_ICU_TOTAL]
        if not actuals.any():
            return None

        if self._require_recent_data and not series_utils.has_recent_data(actuals):
            return None

        return actuals
Ejemplo n.º 3
0
    def _latest_icu_beds(self):
        timeseries = self._data[CommonFields.ICU_BEDS]
        has_recent_data = series_utils.has_recent_data(
            timeseries, days_back=7, required_non_null_datapoints=1)
        has_any_data = timeseries.any()

        if has_recent_data:
            return timeseries.loc[timeseries.last_valid_index()]

        if has_any_data and not self._require_recent_data:
            return timeseries.loc[timeseries.last_valid_index()]

        return self._latest_values.get(CommonFields.ICU_BEDS)
Ejemplo n.º 4
0
def test_has_recent_data():
    start_date = datetime.datetime.today().date() - timedelta(days=15)
    series = _series_with_date_index([0] * 15, date=start_date)
    assert not series_utils.has_recent_data(series)

    series = _series_with_date_index([1] * 15, date=start_date)
    assert series_utils.has_recent_data(series)

    series = _series_with_date_index([1] * 7, date=start_date)
    assert not series_utils.has_recent_data(series)

    series = _series_with_date_index([1] * 8, date=start_date)
    assert series_utils.has_recent_data(series)

    series = _series_with_date_index([np.nan] * 8, date=start_date)
    assert not series_utils.has_recent_data(series)

    series = _series_with_date_index([1] * 8, date=start_date)
    assert not series_utils.has_recent_data(series, days_back=5)
Ejemplo n.º 5
0
def has_data_in_past_10_days(series: pd.Series) -> bool:
    return series_utils.has_recent_data(series,
                                        days_back=10,
                                        required_non_null_datapoints=1)