Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REGION = "your-cloud-function-region" | |
TOPIC_NAME = "sensor-data-processing" | |
SOURCE_URI = "cloud-function-file-directory" | |
ENTRY_POINT = "detect_anomaly" | |
# create to pub/sub topic | |
gcloud pubsub topics create TOPIC_NAME | |
# Create cloud function | |
gcloud functions deploy sensor-data-processing \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import google.oauth2.id_token | |
import google.auth.transport.requests | |
import json | |
import os | |
import csv | |
import requests | |
import datetime | |
from datetime import date | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google-auth | |
requests==2.24.0 | |
numpy==1.22.3 | |
oauth2client | |
google-cloud-bigquery==3.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
evaluate_slice_payload = { | |
"detectionTime": "2021-08-09T21:31:54+00:00", | |
"pinnedDimensions": [ | |
{ | |
"name": "measure", | |
"stringVal": "LTTH" | |
} | |
], | |
"timeseriesParams": { | |
"forecastHistory": "259200s", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delete_ds_endpt = f'https://timeseriesinsights.googleapis.com/v1/projects/{PROJECT_ID}/datasets/{dataset}' | |
res = query_ts(method="DELETE", endpoint=delete_ds_endpt, data=None, auth_token=token_array[0]) | |
res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new_event_payload = { | |
{ | |
"events": [ | |
{ | |
"groupId":"1324354349507023708", | |
"dimensions":[ | |
{"name":"measure","stringVal":"LTTH"}, | |
{"name":"Humidity","doubleVal":36}, | |
{"name":"Light","doubleVal":99}, | |
{"name":"h2_raw","doubleVal":1041}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create json payload for API query | |
request_body = { | |
"detectionTime": "2021-06-27T15:00:00Z", | |
"slicingParams": { | |
"dimensionNames": ["measure"] | |
}, | |
"timeseriesParams": { | |
"forecastHistory": "259200s", | |
"granularity": "1800s", | |
"metric": "temp", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#list all API datasets | |
res = query_ts(method="GET", endpoint=ts_endpoint, data=None, auth_token=token) | |
res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO - REPLACE WITH SA ACCOUNT KEY | |
KEY_FILE = '/<path-to-your-service-account-file>/file.json' #REPLACE THIS WITH PROJECT SPECIFIC SERVICE ACCOUNT KEY | |
ts_endpoint = f'https://timeseriesinsights.googleapis.com/v1/projects/{PROJECT_ID}/datasets' | |
# Helper function | |
def query_ts(method, endpoint, data, auth_token): | |
data = str(data) | |
headers = {'Content-type': 'application/json', "Authorization": f"Bearer {auth_token}"} | |
if method == "GET": |
NewerOlder