42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import pandas as pd # Data wrangling
|
|
import numpy as np # Number handling
|
|
import matplotlib.pyplot as plt # Plotter handling
|
|
from scipy.integrate import odeint # Integral calculations
|
|
|
|
# Variables to control logging.
|
|
LOG: bool = True # Log data to files
|
|
SCREEN: bool = True # Log data to screen
|
|
DEBUG: bool = False # More data to display
|
|
|
|
def read_data_file(data_file):
|
|
data_frame = pd.read_csv(data_file)
|
|
first_row_time = data_frame['Timestamp'].iloc[1]
|
|
last_row_time = data_frame['Timestamp'].iloc[-1]
|
|
first_row_value = data_frame['Value'].iloc[1]
|
|
last_row_value = data_frame['Value'].iloc[-1]
|
|
mean_value = data_frame['Value'].mean()
|
|
median_value = data_frame['Value'].median()
|
|
sum_value = data_frame['Value'].sum()
|
|
|
|
if SCREEN:
|
|
print('first_row_value ',first_row_value)
|
|
print('last_row_value ',last_row_value)
|
|
print('first_row_time ', first_row_time)
|
|
print('last_row_time ', last_row_time)
|
|
print('elapsed_time ', (last_row_time - first_row_time))
|
|
print('mean_value ', mean_value)
|
|
print('median_value ', median_value)
|
|
print('sum_value ', sum_value)
|
|
|
|
return data_frame
|
|
|
|
def plot_data_frame(data_file):
|
|
|
|
data_frame = read_data_file(data_file)
|
|
plt.plot(data_frame['Timestamp'], data_frame['Value'])
|
|
# plt.savefig(data_file + '.png')
|
|
# img = plt.imread(data_file + '.png')
|
|
# plt.imshow(img)
|
|
plt.show()
|
|
|
|
plot_data_frame(data_file = 'pid-balancer_twin_test_data.csv') |