brightwind-dev/brightwind

[load.BrightHub.get_data()] update url to pull from assembled file

stephenholleran opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
The bw.BrightHub.get_data() underlying URL is changing.

image

It is changing to: "/measurement-locations/{}/timeseries-data".
At the moment there are no query parameters but there will be in the future for select a date range.
At the moment the whole timeseries data is returned. This removes the need to chunk the data as is the case at the moment. The speed to return will be greatly increased as the data will already be assembled. Previously, the timeseries data is assembled on the fly from the raw logger files.

Describe the solution you'd like
Suggested code:

import requests
import pandas as pd
from io import StringIO
import numpy as np

def get_timeseries_data(measurement_station_uuid):
    """
    Get the timeseries data from BrightHub for a particular measurement station.

    :param measurement_station_uuid: A specific measurement station's uuid.
    :type measurement_station_uuid:  str
    :return:                         The timeseries data.
    :rtype:                          pd.DataFrame
    """
    response = bw.LoadBrightHub._brighthub_request(url_end="/measurement-locations/{}/timeseries-data"
                                                   .format(measurement_station_uuid))
    response_json = response.json()
    if 'Error' in response_json:  # catch if error comes back e.g. measurement_location_uuid isn't found
        raise ValueError(response_json['Error'])
    
    pre_signed_url = response_json["url"]
    timeseries_response = requests.get(pre_signed_url)
    return pd.read_csv(StringIO(timeseries_response.text,))

The timestamp column should be made the index before returning.

Merged.