mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 05:44:23 +00:00
optimized code in fit.py
This commit is contained in:
@@ -1,15 +1,23 @@
|
|||||||
import csv
|
import csv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
n = int(input("Aktuelle Sondennummer: "))
|
go = 0
|
||||||
|
|
||||||
|
n = int(input("Aktuelle Sondennummer: "))
|
||||||
|
try:
|
||||||
imp = open("Sonden2021.csv", "r")
|
imp = open("Sonden2021.csv", "r")
|
||||||
|
go = 1
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Failed to open file (non-existent or corrupted")
|
||||||
|
go = 0
|
||||||
|
if go == 1:
|
||||||
reader = csv.reader(imp, delimiter=',')
|
reader = csv.reader(imp, delimiter=',')
|
||||||
rohdaten = list(reader)
|
rohdaten = list(reader)
|
||||||
rohdaten.sort(key=lambda imp: float(imp[2]))
|
rohdaten.sort(key=lambda imp: float(imp[2]))
|
||||||
lenght = len(rohdaten)
|
lenght = len(rohdaten)
|
||||||
x = []
|
x = []
|
||||||
y = []
|
y = []
|
||||||
|
|
||||||
for i in range(lenght):
|
for i in range(lenght):
|
||||||
extract = rohdaten.pop(0)
|
extract = rohdaten.pop(0)
|
||||||
sondennummer = int(extract.pop(0))
|
sondennummer = int(extract.pop(0))
|
||||||
@@ -22,7 +30,8 @@ for i in range(lenght):
|
|||||||
fit = np.polyfit(x, y, 2)
|
fit = np.polyfit(x, y, 2)
|
||||||
print(fit)
|
print(fit)
|
||||||
|
|
||||||
formula = "F(U) = %sU^2+%sU+%s"%(str(round(float(fit[0]),4)),str(round(float(fit[1]),4)),str(round(float(fit[2]),4)))
|
formula = "F(U) = %sU^2+%sU+%s"%(str(), str(round(float(fit[1]), 4)), str(round(float(fit[2]), 4)))
|
||||||
|
formula = f"F(U) = {round(float(fit[0]), 4)}U^2+{round(float(fit[1]), 4)}U+{round(float(fit[2]), 4)}"
|
||||||
|
|
||||||
fit_fn = np.poly1d(fit)
|
fit_fn = np.poly1d(fit)
|
||||||
|
|
||||||
@@ -40,7 +49,7 @@ plt.annotate(formula, xy=(0.85,60))
|
|||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
saveit = input("Sollen der Graph gespeichert werden? (y/n) ").lower()
|
saveit = input("Soll der Graph gespeichert werden? (y/n) ").lower()
|
||||||
if saveit == "y":
|
if saveit == "y":
|
||||||
plt.savefig("Sonde"+str(n)+".png")
|
plt.savefig("Sonde"+str(n)+".png")
|
||||||
plt.savefig("Sonde"+str(n)+".pdf", format="pdf")
|
plt.savefig("Sonde"+str(n)+".pdf", format="pdf")
|
||||||
|
|||||||
Reference in New Issue
Block a user