Пример #1
0
client = AmphoraDataRepositoryClient(credentials)

# https://beta.amphoradata.com/Amphorae/Detail?id=57d6593f-1889-410a-b1fb-631b6f9c9c85
id = "57d6593f-1889-410a-b1fb-631b6f9c9c85"

try:
    amphora_api = a10a.AmphoraeApi(client.apiClient)
    print(f'Getting signals for: {amphora_api.amphorae_read(id).name}')
    signals = amphora_api.amphorae_signals_get_signals(id)
    properties = list((s._property for s in signals))

    ts_api = a10a.TimeSeriesApi(
        client.apiClient)  # the API for interacting with time series
    tomorrow = datetime.now() + timedelta(hours=24)
    # Create a DateTimeRange to describe over what period we want data.
    time_range = a10a.DateTimeRange(_from=datetime.now(), to=tomorrow)
    # Create a variable object for getting temperature data
    temperatureVariable = a10a.NumericVariable(
        kind="numeric",
        value=a10a.Tsx(tsx="$event.temperature"),
        aggregation=a10a.Tsx(tsx="it doesn't matter"))
    get_series = a10a.GetSeries(
        [id],
        search_span=time_range,
        inline_variables={"temperature": temperatureVariable})
    time_series_data = ts_api.time_series_query_time_series(
        a10a.QueryRequest(get_series=get_series))

    print(
        f'Got {len(time_series_data.timestamps)} datapoints and {len(time_series_data.properties)} properties'
    )
Пример #2
0
    return [i for i in a_list if i]


try:

    amphora_api = a10a.AmphoraeApi(client.apiClient)
    print(f'Getting signals for: {amphora_api.amphorae_read(id).name}')
    print("-----------")
    signals = amphora_api.amphorae_signals_get_signals(id)
    properties = list((s._property for s in signals))

    ts_api = a10a.TimeSeriesApi(
        client.apiClient)  # the API for interacting with time series
    one_hour_ago = datetime.utcnow() + timedelta(hours=-1)
    # Create a DateTimeRange to describe over what period we want data.
    time_range = a10a.DateTimeRange(_from=one_hour_ago, to=datetime.utcnow())

    # let's get the maximum write time for the period
    maxWtVar = a10a.AggregateVariable(kind="aggregate",
                                      aggregation=a10a.Tsx("max($event.wt)"))
    minWtVar = a10a.AggregateVariable(kind="aggregate",
                                      aggregation=a10a.Tsx("min($event.wt)"))
    get_aggregate = a10a.AggregateSeries(
        [id],
        search_span=time_range,
        interval="PT4H",
        projected_variables=["maxWt", "minWt"],
        inline_variables={
            "maxWt": maxWtVar,
            "minWt": minWtVar
        })
##############################################################
# parameters and details
credentials = Credentials(username=os.getenv('username'),
                          password=os.getenv('password'))
client = AmphoraDataRepositoryClient(credentials)

Electricity_Amphora_id = '89c2e30d-78c8-46ef-b591-140edd84ddb6'
Weather_Amphora_id = '2866d34f-fe2b-4c07-acdd-28fe2d6d9194'
Forecast_amphora_id = '78831a6b-de49-454e-9e5c-7c757478e783'
name = 'South_Australia_Electricity_Price.json'

#############################################################
# Publish raw data on microprediction
mw = MicroWriter(write_key="bdfd44affd28e6c5b45329d6d4df7729")
time_range = a10a.DateTimeRange(_from=datetime.utcnow() + timedelta(hours=-1),
                                to=datetime.utcnow())
electricity_amphora = client.get_amphora(Electricity_Amphora_id)
electricity_signals = electricity_amphora.get_signals()
df = electricity_signals.pull(date_time_range=time_range).to_pandas()
price = df['price']
mw.set(name=name, value=price[-1])

##########################################################
# Create a prediction and publish on microprediction
# length = mw.num_predictions
# data_time_range = a10a.DateTimeRange(_from = datetime.utcnow() + timedelta(hours=-length/2) , to= datetime.utcnow() )
# pdf = electricity_signals.pull(date_time_range=data_time_range).to_pandas()
# price = pdf['price']
# prices_of_interest = price[-length-1:-1]

# elec_prices_diff = np.zeros(length-1)
            element_of_interest = non_none_indicies[t]
            data_array[i - 1][t] = time_series_data.properties[i].values[
                element_of_interest]

    return data_array, unique_dt, data_name


importCsv("dates_of_interest.csv")

amphora_id = 'fca8998a-2d0e-4afa-a9aa-1467759a8d9a'

T = 60

## Get the data
ts_api = a10a.TimeSeriesApi(client.apiClient)
time_range = a10a.DateTimeRange(_from=datetime.utcnow() + timedelta(days=-T),
                                to=datetime.utcnow())
variables = {
    "confirmedCases":
    a10a.NumericVariable(kind="numeric",
                         value=a10a.Tsx(tsx="$event.confirmedCases"),
                         aggregation=a10a.Tsx(tsx="it doesn't matter")),
    "activeCases":
    a10a.NumericVariable(kind="numeric",
                         value=a10a.Tsx(tsx="$event.activeCases"),
                         aggregation=a10a.Tsx(tsx="it doesn't matter")),
    "recoveredCases":
    a10a.NumericVariable(kind="numeric",
                         value=a10a.Tsx(tsx="$event.recoveredCases"),
                         aggregation=a10a.Tsx(tsx="it doesn't matter")),
    "deaths":
    a10a.NumericVariable(kind="numeric",
Пример #5
0
def default_date_time_range() -> api.DateTimeRange:
    yesterday = datetime.utcnow() + timedelta(hours=-24)
    return api.DateTimeRange(_from=yesterday, to=datetime.utcnow())