Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Last active June 20, 2022 05:34
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 sjwaight/709879d562b58c206b938c48b232c5a7 to your computer and use it in GitHub Desktop.
Save sjwaight/709879d562b58c206b938c48b232c5a7 to your computer and use it in GitHub Desktop.
Azure Stream Analytics query used to parse incoming data to make it ready for training Cognitive Services Anomaly Detector
SELECT
DATETIMEFROMPARTS (DATEPART(year,readtime), DATEPART(month,readtime), DATEPART(day,readtime), DATEPART(hour, readtime), DATEPART(minute, readtime), 30, 0) as 'timestamp',
temperature as value
INTO
[temperaturedatacsv]
FROM
[rawiotjsondata]
SELECT
DATETIMEFROMPARTS (DATEPART(year,readtime), DATEPART(month,readtime), DATEPART(day,readtime), DATEPART(hour, readtime), DATEPART(minute, readtime), 30, 0) as 'timestamp',
humidity as value
INTO
[humiditydatacsv]
FROM
[rawiotjsondata]
/* Parse values from both sensors and select the higher one. Does not allow for failure of one sensor, but works for our use case. */
SELECT
DATETIMEFROMPARTS (DATEPART(year,readtime), DATEPART(month,readtime), DATEPART(day,readtime), DATEPART(hour, readtime), DATEPART(minute, readtime), 30, 0) as 'timestamp',
CASE
WHEN pm100atma < pm100atmb THEN pm100atmb
ELSE pm100atma
END as value
INTO
[pm10datacsv]
FROM
[rawiotjsondata]
/* Parse values from both sensors and select the higher one. Does not allow for failure of one sensor, but works for our use case. */
SELECT
DATETIMEFROMPARTS (DATEPART(year,readtime), DATEPART(month,readtime), DATEPART(day,readtime), DATEPART(hour, readtime), DATEPART(minute, readtime), 30, 0) as 'timestamp',
CASE
WHEN pm25atma < pm25atmb THEN pm25atmb
ELSE pm25atma
END as value
INTO
[pm25datacsv]
FROM
[rawiotjsondata]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment