Skip to content

Instantly share code, notes, and snippets.

@nishitpatel01
Last active September 20, 2022 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishitpatel01/38203da1a5478673163622a4e6e0acbe to your computer and use it in GitHub Desktop.
Save nishitpatel01/38203da1a5478673163622a4e6e0acbe to your computer and use it in GitHub Desktop.
Query TSI dataset for anomaly or forecasting
#create json payload for API query
request_body = {
"detectionTime": "2021-06-27T15:00:00Z",
"slicingParams": {
"dimensionNames": ["measure"]
},
"timeseriesParams": {
"forecastHistory": "259200s",
"granularity": "1800s",
"metric": "temp",
},
"forecastParams": {
"noiseThreshold": 50.0,
"seasonalityHint": "DAILY"
},
"returnTimeseries": "true"
}
dataset = "sensor-data"
# get forecast
query_ds_endpt = f'https://timeseriesinsights.googleapis.com/v1/projects/{PROJECT_ID}/datasets/{dataset}:query'
res = query_ts(method="POST", endpoint=query_ds_endpt, data=request_body, auth_token=token_array[0])
res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment