2020-06-05 21:41:16 +02:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
from msgpack.fallback import unpackb
|
|
|
|
import requests
|
|
|
|
import array
|
2023-07-16 13:20:19 +02:00
|
|
|
import sys
|
2020-06-05 21:41:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def ext_hook(code, data):
|
|
|
|
#if code == -47:
|
2021-05-15 12:19:44 +02:00
|
|
|
print("code", code)
|
2020-06-05 21:41:16 +02:00
|
|
|
if code == -51:
|
2021-05-15 12:19:44 +02:00
|
|
|
print("before")
|
|
|
|
res = np.frombuffer(data, dtype=np.int16)
|
|
|
|
print(res)
|
|
|
|
print("after")
|
|
|
|
return res
|
2020-06-05 21:41:16 +02:00
|
|
|
else:
|
|
|
|
print(code)
|
|
|
|
return 'unknown ext'
|
|
|
|
|
|
|
|
|
|
|
|
def decode(stream):
|
|
|
|
return unpackb(stream, ext_hook=ext_hook, raw=False)
|
|
|
|
|
|
|
|
|
|
|
|
def from_file(file_name):
|
|
|
|
with open(file_name, 'rb') as f:
|
|
|
|
file_contents = f.read()
|
|
|
|
print("File size", len(file_contents))
|
|
|
|
res = decode(file_contents)
|
|
|
|
print(res)
|
|
|
|
plt.plot(res['values'], 'x-')
|
|
|
|
plt.show()
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def from_network(url="http://swimtrainer/api/session", start_index=0):
|
|
|
|
r = requests.get("{}?startIndex={}".format(url, start_index))
|
|
|
|
res = decode(r.content)
|
|
|
|
print(res)
|
|
|
|
plt.plot(res['timestamps'], res['values'], 'x-')
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
def analyze(data, max_size=8*1024):
|
|
|
|
time_stamps = data['timestamps'][:max_size]
|
|
|
|
values = data['values'][:max_size]
|
|
|
|
time_range_seconds = (time_stamps[-1] - time_stamps[0]) / 10
|
|
|
|
dense_time_range_seconds = max_size / 10
|
|
|
|
print("Time range {}, dense {} [minutes]".format(time_range_seconds / 60, dense_time_range_seconds / 60))
|
|
|
|
|
|
|
|
#from_network()
|
2023-07-16 13:20:19 +02:00
|
|
|
res = from_file(sys.argv[1])
|
2020-06-05 21:41:16 +02:00
|
|
|
print(res)
|
|
|
|
#analyze(res)
|