From 890daa97025f55e0ac01be9f92c2021d8bd9c16a Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 16 Jul 2024 23:51:28 +0200 Subject: [PATCH] use pandas csv reader and use subplots --- logdata_visualization/analyze.py | 83 +++++++++++++++----------------- logdata_visualization/logfix.py | 4 +- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/logdata_visualization/analyze.py b/logdata_visualization/analyze.py index 0f7474b..04b3ac6 100644 --- a/logdata_visualization/analyze.py +++ b/logdata_visualization/analyze.py @@ -1,52 +1,47 @@ import matplotlib.pyplot as plt -import csv +#import csv +import pandas as pd -x=[] -speed_FrontL=[] -speed_FrontR=[] -speed_RearL=[] -speed_RearR=[] - -fp = open('LOG00203c_replacedFrontLeftWheel.TXT') - -rdr = csv.DictReader(filter(lambda row: row[0]!='#', fp)) -for row in rdr: - #print(row) - x.append(float(row['cmd_FrontL'])) - - speed_FrontL.append(float(row['speed_FrontL'])) - speed_FrontR.append(float(row['speed_FrontR'])) - speed_RearL.append(float(row['speed_RearL'])) - speed_RearR.append(float(row['speed_RearR'])) -fp.close() +import numpy as np -#plt.plot(x,y, label='Loaded from file!') -scattersize=5 +import argparse + +parser = argparse.ArgumentParser(description='Analyzes fixed csv logs from bobbycar') +parser.add_argument('-i', '--input', type=argparse.FileType('r'), required=True, help="input csv log file") +args = parser.parse_args() + +df = pd.read_csv(args.input.name) + +x = df['timestamp'] +x = [i-x[0] for i in x] #offset time by starttime + + +scattersize=1 scatteralpha=0.1 -plt.scatter(x,speed_FrontL, s=scattersize, alpha=scatteralpha, label="speed_FrontL") -plt.scatter(x,speed_FrontR, s=scattersize, alpha=scatteralpha, label="speed_FrontR") -plt.scatter(x,speed_RearL, s=scattersize, alpha=scatteralpha, label="speed_RearL") -plt.scatter(x,speed_RearR, s=scattersize, alpha=scatteralpha, label="speed_RearR") -plt.xlabel('cmd') -plt.ylabel('speed') -plt.title('Interesting Graph\nCheck it out') -plt.legend() + + +fig, ax1 = plt.subplots() + +ax2 = ax1.twinx() + + +#plt.scatter(x,df['rpm_FrontL'], s=scattersize, alpha=scatteralpha, label="rpm_FrontL") +ax1.plot(x,np.array(df['vbat_Front']), c='b', alpha=0.5, label="vbat_Front") +ax1.plot(x,np.array(df['vbat_Rear']), c='r', alpha=0.5, label="vbat_Rear") +ax2.plot(x,np.array(df['cmd_FrontL']), c='r', alpha=0.5, label="cmd_FrontL") +#plt.plot(x,np.array(df['currentConsumed']), c='g', alpha=0.5, label="currentConsumed") + +#plt.scatter(x,df['rpm_FrontR'], s=scattersize, alpha=scatteralpha, label="rpm_FrontR") + +ax1.set_xlabel('timestamp') +#plt.ylabel('data') +ax1.set_ylabel('first axis') +ax2.set_ylabel('second axis') +#plt.title('') +ax1.legend(loc='upper left') +ax2.legend(loc='upper right') plt.show() -''' -with open(,'r') as csvfile: - plots = csv.reader(filter(lambda row: row[0]!='#', csvfile), delimiter=',') - for row in plots: - x.append(float(row[0])) - y.append(float(row[1])) - -plt.plot(x,y, label='Loaded from file!') -plt.xlabel('x') -plt.ylabel('y') -plt.title('Interesting Graph\nCheck it out') -plt.legend() -plt.show() -''' - +exit() diff --git a/logdata_visualization/logfix.py b/logdata_visualization/logfix.py index fc019f7..fd7fec1 100644 --- a/logdata_visualization/logfix.py +++ b/logdata_visualization/logfix.py @@ -107,8 +107,6 @@ if (args.consecutive): - print("") - print(inputFilenames) else: @@ -150,7 +148,7 @@ for inputFilename in inputFilenames: linesStarttime+=_linesStarttime - print("Line in file="+str(len(inputlines))) + print("Lines in file="+str(len(inputlines))) assert len(lines)==len(linesStarttime), "Length of lines and linesStarttime does not match"