git_baw/tachymeter.py

65 lines
1.7 KiB
Python

import csv, sys
from lib2to3.pgen2.pgen import DFAState
import plotly.express as px
import plotly.io as pio
import plotly.graph_objects as go
filename = 'example_data/TachymeterTable_103.csv'
# einfaches Beispiel: CSV direkt ausgeben:
#with open(filename, newline='') as f:
# reader = csv.reader(f)
# try:
# for row in reader:
# print(row)
# except csv.Error as e:
# sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
# Time,x,y,z,d,deltaT,SOG,RelTime,Beschleunigung,BeschleunigungDeltaTFix,ABSBeschleunigung
class Tachymeter(object):
def __init__(self, i, x, y, z, d, deltaT, SOG, RelTime, Beschleunigung, BeschleunigungDeltaTFix, ABSBeschleunigung):
self.index = i
self.x = x
self.y = y
self.z = z
self.d = d
self.deltaT = deltaT
self.SOG = SOG
self.RelTime = RelTime
self.Beschleunigung = Beschleunigung
self.BeschleunigungDeltaTFix = BeschleunigungDeltaTFix
self.ABSBeschleunigung = ABSBeschleunigung
def __init__(self, row, header):
self.__dict__ = dict(zip(header, row))
self.index = row
data = list(csv.reader(open(filename, newline='')))
tachies = [Tachymeter(i, data[0]) for i in data[1:]]
# for tachy in tachies:
# print(tachy.x)
fig = dict({
"data": [{"type": "bar",
"x": [1, 2, 3],
"y": [1, 3, 2]}],
"layout": {"title": {"text": "A Figure Specified By Python Dictionary"}}
})
# pio.show(fig)
# fig = px.line(tachies, x="x", y="x", title="Tachymeter Daten x, y")
# fig.show()
df = dict( {
"x" : [ 1, 2, 3, 4, 5],
"y" : [0.4, 2.3, 2.4, 2.7, 1.3]
})
fig = go.Figure(go.Line(x = df['x'], y = df['y'],
name='Position (x/y)'))
fig.show()