pid-balancer/plotter_functions.py

40 lines
1.4 KiB
Python
Raw Normal View History

2024-12-29 14:30:37 +01:00
import pandas as pd
import matplotlib.pyplot as plt
2024-12-18 13:45:00 +01:00
2024-12-29 14:30:37 +01:00
# 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
2024-12-18 13:45:00 +01:00
2024-12-29 14:30:37 +01:00
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()
2024-12-25 16:52:07 +01:00
2024-12-29 14:30:37 +01:00
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')