From: Ole Artz Date: Mon, 11 Jul 2022 12:37:39 +0000 (+0200) Subject: telnet_data_plot: same design like live_telnet_data_plot X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=a95f30757e75fdbc6d64a6dbdecd96a4a169c88f;p=avr.git telnet_data_plot: same design like live_telnet_data_plot --- diff --git a/esp32/EthernetUART/LANTelnetToI2C_Board/telnet_data_plot.py b/esp32/EthernetUART/LANTelnetToI2C_Board/telnet_data_plot.py index 44fb030..38bd734 100644 --- a/esp32/EthernetUART/LANTelnetToI2C_Board/telnet_data_plot.py +++ b/esp32/EthernetUART/LANTelnetToI2C_Board/telnet_data_plot.py @@ -3,7 +3,10 @@ __email__ = "ole.artz@stud.uni-frankfurt.de" import matplotlib.pyplot as plt import sys +import time +from datetime import datetime +Timestamp_list = list() AIN0_list = list() AIN1_list = list() @@ -19,64 +22,100 @@ ax1 = fig.add_subplot(1,1,1) def split_data(): - with open(filename, "r") as file: - lines = file.readlines() - file.close() - - for line in lines: - if line.startswith('AIN0'): - end_of_val = line.rfind(' ') - new_val = float(line[6:end_of_val]) + if filename == '': + print("Fatal Error! - No filename was given.") + quit() + + try: + with open(filename, "r") as file: + lines = file.readlines() - AIN0_list.append(new_val) + for line in lines: + + if line.startswith('20'): + end_of_val = line.rfind('\n') + format_data = '%Y-%m-%d %H:%M:%S.%f' + new_timestamp = datetime.strptime(str(line[0:end_of_val]), format_data) + + Timestamp_list.append(new_timestamp) + + elif line.startswith('AIN0'): + end_of_val = line.rfind(' ') + new_val = float(line[6:end_of_val]) + + AIN0_list.append(new_val) + + unit = line[end_of_val+1:len(line)-1] + + elif line.startswith('AIN1'): + end_of_val = line.rfind(' ') + new_val = float(line[6:end_of_val]) + + AIN1_list.append(new_val) + + elif line.startswith('AIN2'): + end_of_val = line.rfind(' ') + new_val = float(line[6:end_of_val]) + + AIN2_list.append(new_val) - unit = line[end_of_val+1:len(line)-1] + elif line.startswith('AIN3'): + end_of_val = line.rfind(' ') + new_val = float(line[6:end_of_val]) - if line.startswith('AIN1'): - end_of_val = line.rfind(' ') - new_val = float(line[6:end_of_val]) - - AIN1_list.append(new_val) - - if line.startswith('AIN2'): - end_of_val = line.rfind(' ') - new_val = float(line[6:end_of_val]) - - AIN2_list.append(new_val) + AIN3_list.append(new_val) + + file.close() - if line.startswith('AIN3'): - end_of_val = line.rfind(' ') - new_val = float(line[6:end_of_val]) - - AIN3_list.append(new_val) + except: + print("Fatal Error! - File wasn't found.") + quit() + return unit def plotter(): + starttime = datetime.now() unit = split_data() + split_time_raw = datetime.now() + split_time = (split_time_raw - starttime).total_seconds() + print('Time for splitting data:', split_time,"s.") ax1.clear() - ax1.plot(AIN0_list, 'r', label="AIN0") - ax1.plot(AIN1_list, 'b', label="AIN1") - ax1.plot(AIN2_list, 'g', label="AIN2") - ax1.plot(AIN3_list, 'y', label="AIN3") +# ax1.plot(AIN0_list, 'r', label="AIN0") +# ax1.plot(AIN1_list, 'b', label="AIN1") +# ax1.plot(AIN2_list, 'g', label="AIN2") +# ax1.plot(AIN3_list, 'y', label="AIN3") + + ax1.plot(Timestamp_list, AIN0_list, 'r', label="AIN0") + ax1.plot(Timestamp_list, AIN1_list, 'b', label="AIN1") + ax1.plot(Timestamp_list, AIN2_list, 'g', label="AIN2") + ax1.plot(Timestamp_list, AIN3_list, 'y', label="AIN3") + + plt.xticks(rotation=0) + if unit == 'mV': plot_title = 'Voltage' elif unit == 'mA': plot_title = 'Current' - elif unit == 'mbar': + elif unit == 'mbar' or unit == 'mPa': plot_title = 'Pressure' elif unit == 'degC': plot_title = 'Temperature' plt.title(plot_title) - plt.xlabel('~0.5s') + plt.xlabel('Time') plt.ylabel(unit) plt.legend(loc=2) - + + plot_time_raw = datetime.now() + plot_time = (plot_time_raw - split_time_raw).total_seconds() + print('Time for plot data:', plot_time, 's.') + plt.show() + def main(): plotter()