def test_generate_forecast_figure_components(ac_power_forecast_metadata,
                                             forecast_values):
    # not great, just testing that script and div are returned
    out = timeseries.generate_forecast_figure(ac_power_forecast_metadata,
                                              forecast_values,
                                              return_components=True)
    assert '<script' in out[0]
    assert '<div' in out[1]
예제 #2
0
def timeseries_adapter(type_, metadata, json_value_response):
    metadata = deepcopy(metadata)
    # ignores any modeling parameters as they aren't need for this
    site = datamodel.Site.from_dict(metadata['site'], raise_on_extra=False)
    metadata['site'] = site
    if type_ == 'forecast':
        obj = datamodel.Forecast.from_dict(metadata)
        data = io_utils.json_payload_to_forecast_series(json_value_response)
        return timeseries.generate_forecast_figure(obj,
                                                   data,
                                                   return_components=True)
    else:
        obj = datamodel.Observation.from_dict(metadata)
        data = io_utils.json_payload_to_observation_df(json_value_response)
        return timeseries.generate_observation_figure(obj,
                                                      data,
                                                      return_components=True)
예제 #3
0
def timeseries_adapter(type_, metadata, json_value_response):
    metadata = deepcopy(metadata)
    # ignores any modeling parameters as they aren't need for this
    if 'site' in metadata:
        site = datamodel.Site.from_dict(metadata['site'], raise_on_extra=False)
        metadata['site'] = site
    elif 'aggregate' in metadata:
        # Patch aggregates so data model doesn't throw an error. We don't
        # need to load all of the observations when plotting forecasts.
        metadata['aggregate']['observations'] = []
    if type_ == 'forecast':
        obj = datamodel.Forecast.from_dict(metadata)
        data = io_utils.json_payload_to_forecast_series(json_value_response)
        return timeseries.generate_forecast_figure(obj,
                                                   data,
                                                   return_components=True,
                                                   limit=None)
    elif type_ == 'observation':
        obj = datamodel.Observation.from_dict(metadata)
        data = io_utils.json_payload_to_observation_df(json_value_response)
        return timeseries.generate_observation_figure(obj,
                                                      data,
                                                      return_components=True,
                                                      limit=None)
    elif type_ == 'probabilistic_forecast':
        cvs = []
        for constant_value in metadata['constant_values']:
            cv_dict = metadata.copy()
            cv_dict.update(constant_value)
            cvs.append(
                datamodel.ProbabilisticForecastConstantValue.from_dict(
                    cv_dict))
        metadata['constant_values'] = cvs
        obj = datamodel.ProbabilisticForecast.from_dict(metadata,
                                                        raise_on_extra=False)
        return timeseries.generate_probabilistic_forecast_figure(
            obj, json_value_response)
    else:
        # remove observations, we aren't using them for plotting aggregates
        metadata['observations'] = []
        obj = datamodel.Aggregate.from_dict(metadata, raise_on_extra=False)
        data = io_utils.json_payload_to_observation_df(json_value_response)
        return timeseries.generate_observation_figure(obj,
                                                      data,
                                                      return_components=True,
                                                      limit=None)
def test_generate_forecast_figure_empty(ac_power_forecast_metadata, rc):
    assert timeseries.generate_forecast_figure(ac_power_forecast_metadata,
                                               pd.Series(dtype=float),
                                               return_components=rc) is None
def test_generate_forecast_figure(ac_power_forecast_metadata, forecast_values):
    # not great, just testing that script and div are returned
    out = timeseries.generate_forecast_figure(ac_power_forecast_metadata,
                                              forecast_values)
    assert isinstance(out, bokeh.models.Column)