29 lines
1.0 KiB
Python
Executable File
29 lines
1.0 KiB
Python
Executable File
#!./venv/bin/python3
|
|
import pandas as pd
|
|
import json
|
|
import matplotlib.pyplot as plt
|
|
import os
|
|
|
|
DATA_MEAS_DIR = 'data/measurements'
|
|
SPECIFIC_FILE = ''
|
|
MEAS_LOG_FILE = sorted(os.listdir(DATA_MEAS_DIR))[-1] if not SPECIFIC_FILE else SPECIFIC_FILE
|
|
|
|
with open(os.path.join(DATA_MEAS_DIR, MEAS_LOG_FILE)) as f:
|
|
meas_data = [json.loads(line) for line in f]
|
|
data = meas_data
|
|
|
|
df = pd.DataFrame.from_records(data)
|
|
df['time'] = pd.to_datetime(df['time'], unit='s')
|
|
df_pivot = df.pivot_table(values='value', columns='unit', index='time')
|
|
df_resampled = df_pivot.resample('s').mean()
|
|
df_resampled.interpolate(method='linear', inplace=True)
|
|
df_resampled = pd.DataFrame(df_resampled)
|
|
|
|
# Plot the data. Note, that the data will mostly not be plotted with lines.
|
|
plt.ion() # Turn interactive mode on
|
|
plt.figure()
|
|
ax1, ax2 = plt.subplot(211), plt.subplot(212)
|
|
df_resampled[[c for c in df_resampled.columns if '_p' in c]].plot(marker='.', ax=ax1, linewidth=3)
|
|
df_resampled[[c for c in df_resampled.columns if '_q' in c]].plot(marker='.', ax=ax2, linewidth=3)
|
|
plt.show(block=True)
|