mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 05:44:23 +00:00
added plot generator to project
This commit is contained in:
50
plot_generator/plot_generator.py
Normal file
50
plot_generator/plot_generator.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
"""This Program is CLI only!"""
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
|
||||||
|
path = input("Path to csv-file to be plotted: ")
|
||||||
|
date = input("Date & time at which the measurement was taken (approx.): ")
|
||||||
|
saveit = input("Should the graph be saved? (y/n) ").lower()
|
||||||
|
|
||||||
|
imp = open(path, "r")
|
||||||
|
reader = csv.reader(imp, delimiter=',')
|
||||||
|
rohdaten = list(reader)
|
||||||
|
lenght = len(rohdaten)
|
||||||
|
x = []
|
||||||
|
y = []
|
||||||
|
for i in range(lenght):
|
||||||
|
extract = rohdaten.pop(0)
|
||||||
|
x.append(float(extract.pop(0)))
|
||||||
|
y.append(float(extract.pop(0)))
|
||||||
|
|
||||||
|
plt.plot(x, y, color="MAGENTA")
|
||||||
|
plt.xlabel("Time")
|
||||||
|
plt.ylabel("Voltage")
|
||||||
|
titel = f"GC - Biogasanlage {date}"
|
||||||
|
plt.title(titel)
|
||||||
|
plt.grid(True)
|
||||||
|
if saveit == "y":
|
||||||
|
pos = 0
|
||||||
|
for letter in path[::-1]:
|
||||||
|
if letter == "/":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
pos += 1
|
||||||
|
pos_c = len(path) - pos
|
||||||
|
ppath = path[:pos_c]
|
||||||
|
save_path = f"{ppath}graphs/"
|
||||||
|
try:
|
||||||
|
os.mkdir(save_path)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
plt.savefig(save_path)
|
||||||
|
os.rename(f"{save_path}/.png", f"{save_path}/GC-{date}.png")
|
||||||
|
print(f"saved images to {save_path}")
|
||||||
|
else:
|
||||||
|
print("didn't save images")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user