def get_inline_variables(signals: [api.Signal], include_wt: bool) -> {}: variables = {} for signal in signals: if (signal.value_type == 'Numeric'): variable = api.NumericVariable( kind="numeric", # https://docs.microsoft.com/en-us/rest/api/time-series-insights/reference-time-series-expression-syntax#other-functions value=api.Tsx( tsx= f'coalesce($event.{signal._property}.Double, toDouble($event.{signal._property}.Long))' ), aggregation=api.Tsx(tsx="it doesn't matter")) variables[signal._property] = variable else: logger.info( f'Not adding signal {signal._property} with value type {signal.value_type}' ) if include_wt: variables["wt"] = variable = api.NumericVariable( kind="numeric", value=api.Tsx(tsx='$event.wt'), aggregation=api.Tsx(tsx="avg($value)")) return variables
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' ) # access the data in time_series_data.properties print("-----------") # get average of tomorrow's rainfall probablility, filtered by description = Possible shower or Mostly cloudy
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 }) agg_data = ts_api.time_series_query_time_series( a10a.QueryRequest(aggregate_series=get_aggregate)) maxWt = max(agg_data.properties[0].values) # max value from max list
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", value=a10a.Tsx(tsx="$event.deaths"), aggregation=a10a.Tsx(tsx="it doesn't matter")) }
labels=labels) amphora_id = amphora.amphora_id amphora_api = a10a.AmphoraeApi(client.apiClient) T = 25 for i in range(len(country_stor)): sep = "" # Pull beta signal ## Get the data ts_api = a10a.TimeSeriesApi(client.apiClient) time_range = a10a.DateTimeRange(_from=datetime.utcnow() + timedelta(days=-T), to=datetime.utcnow() + timedelta(days=-5)) variables = { "beta": a10a.NumericVariable(kind="numeric", value=a10a.Tsx(tsx="$event.beta"), aggregation=a10a.Tsx(tsx="it doesn't matter")) } get_series_query = a10a.GetSeries( [country_stor[i][0]], search_span=time_range, inline_variables=variables) # the complete query time_series_data = ts_api.time_series_query_time_series( a10a.QueryRequest(get_series=get_series_query)) data_array, unique_dt, data_name = flatten_time_series_data( time_series_data) unique_dt_list = list(unique_dt) beta = data_array[0]