Skip to content

Instantly share code, notes, and snippets.

@masyanru
Last active March 27, 2020 12:36
Show Gist options
  • Save masyanru/195332e0ffe211efdf1db5da25f49f57 to your computer and use it in GitHub Desktop.
Save masyanru/195332e0ffe211efdf1db5da25f49f57 to your computer and use it in GitHub Desktop.
import csv
import json
data = {}
final = []
csvFilePath = 'h2_prod_ok.csv'
jsonFilePath = 'h2_prod_anomalies.json'
fieldnames = ('Series', 'Time', 'Value')
with open(csvFilePath) as csvFile:
csvReader = csv.DictReader(csvFile, fieldnames, delimiter=';')
for row in csvReader:
# leave only every minute
if '00+03:00' in row['Time']:
digit = row['Value'].split('.', 1)[0]
data = {'timestamp': row['Time'], 'value': digit}
# print(row['Value'])
final.append(data)
print(json.dumps(final))
# convert csv into json for anomaly detecttion
# json_data = '{"maxAnomalyRatio": 0.45, "granularity": "minutely", "sensitivity": 90, "series": ' + json.dumps(final) + '}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment