Created
June 16, 2020 17:24
-
-
Save umangshrestha/682bdf691c1bd8ed48ad71c3a96dfd82 to your computer and use it in GitHub Desktop.
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 json | |
import csv | |
file_name = "timestamp.csv" | |
prev_spo2 = 0 | |
prev_ecg = 0 | |
csvFile = open(file_name, 'w+') | |
writer = csv.writer(csvFile) | |
row = ["seq", "TsEcg", "TsSpo2", "delta_TsEcg", "delta_TsSpo2"] | |
writer.writerow(row) | |
lines = open('/home/hmicro/Downloads/RecData_1.json', 'r') # edit file name here | |
for line in lines: | |
receiver_data = json.loads(line) | |
sensor_data = receiver_data.values()[0]["SensorData"] | |
if "TsSpO2" in sensor_data.keys(): | |
tsSpo2 = sensor_data["TsSpO2"] | |
else: | |
tsSpo2 = "-" | |
seq = sensor_data["Seq"] | |
tsEcg = sensor_data["TsECG"] | |
try: | |
del_spo2 = tsSpo2 - prev_spo2 | |
except: | |
del_spo2 = "-" | |
row = [seq, tsEcg, tsSpo2, tsEcg - prev_ecg, del_spo2] | |
prev_spo2 = tsSpo2 | |
prev_ecg = tsEcg | |
print row | |
writer.writerow(row) | |
lines.close() | |
csvFile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment