1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
Umweltdatenmessung/Endauswertung/mathe.py

104 lines
3.3 KiB
Python
Raw Normal View History

2014-02-02 14:35:07 +01:00
# -*- coding: utf-8 -*-
import csv
2014-02-10 14:29:03 +01:00
import math
2014-02-13 16:26:11 +01:00
from datetime import datetime # aus dem Modul datetime Datentyp datetime (Datum und Zeit) importieren
bis_roh = "2014/02/01 22:1:00"
namen = ["Innentemperatur", "Gerätetemperatur 1", "Außentemperatur", "Gerätetemperatur 2", "Temperatur (Luft)", "Luftfeuchtigkeit", "Luftdruck", "Temperatur (Druck)", "Prozessor"]
format = "%Y/%m/%d %H:%M:%S"
von_roh = "2014/02/01 18:12:42"
2014-02-02 14:35:07 +01:00
def offnen(datei):
2014-02-11 18:48:10 +01:00
with open(datei) as filein:
2014-02-02 14:35:07 +01:00
reader =csv.reader(filein, quoting=csv.QUOTE_NONNUMERIC)
2014-02-11 18:30:53 +01:00
global liste # Liste außerhalb von Funtion nutzen
liste = list(zip(*reader)) # = [temp1,temp2,temp3,temp4,luft_temp,luft_feucht,druck,temp_druck,rasp]
2014-02-02 14:35:07 +01:00
def mittelwert(spalte):
2014-02-11 18:48:10 +01:00
summe = 0
2014-02-11 18:30:53 +01:00
anzahl = 0 # Anzahl der Messwerte
2014-02-02 14:35:07 +01:00
for wert in spalte:
2014-02-11 18:30:53 +01:00
summe = summe + wert # zur bisherigen Summe addieren
2014-02-11 18:48:10 +01:00
anzahl += 1
2014-02-02 14:35:07 +01:00
mittelwert = summe / anzahl
return mittelwert
def minmax(spalte):
2014-02-11 18:30:53 +01:00
mini = spalte[0] #Minimum auf ersten Wert setzen
2014-02-02 14:35:07 +01:00
maxi = spalte[0]
for wert in spalte:
if wert < mini:
mini = wert
if wert > maxi:
maxi = wert
2014-02-02 14:35:07 +01:00
return (mini,maxi)
2014-02-11 16:38:01 +01:00
def standardabweichung(spalte,mw):
n = 0
summe = 0
for wert in spalte:
term = wert - mw
summe = summe + (term * term)
n += 1
stab = math.sqrt(summe / n)
return stab
2014-02-11 18:48:10 +01:00
2014-02-13 16:26:11 +01:00
def datumsauswahl(von_roh,bis_roh):
von = datetime.strptime(von_roh, format)
bis = datetime.strptime(bis_roh, format)
datei = open("datum.csv", "r")
inhalt = datei.readlines()
datei.close()
start_gefunden = False
stop_gefunden = False
for datum in inhalt:
datum_py = datetime.strptime(datum.rstrip(), format)
if (datum_py > von) and (start_gefunden == False):
start = inhalt.index(datum)
start_gefunden = True
if (start_gefunden == True) and (datum_py > bis) and (stop_gefunden == False):
stop = inhalt.index(datum) - 1
stop_gefunden = True
break
print("Der Messwert geht von Zeile " + str(start) + " bis Zeile " + str(stop) + " und über folgenden Zeitraum: " + str(bis - von))
return start,stop
2014-02-02 14:35:07 +01:00
offnen("vorbereitet.csv")
2014-02-13 16:26:11 +01:00
startstop = datumsauswahl(von_roh,bis_roh)
von = startstop[0]
bis = startstop[1]
liste_auswahl = []
for spalte in liste:
spalte_neu = spalte[von:bis]
liste_auswahl.append(spalte_neu)
liste = liste_auswahl
2014-02-10 14:29:03 +01:00
print("------Mittelwerte------")
2014-02-11 18:30:53 +01:00
mittelwerte = [] # leere Liste erstellen
for spalte in liste:
2014-02-11 18:30:53 +01:00
mw = mittelwert(spalte) #jeden MW ausrechnen ...
mittelwerte.append(mw) # ... und an die Liste anhängen
mittelausgabe = zip(namen,mittelwerte) # in Tupel umwandeln [(Innentemperatur, 25), (Außentemperatur,8)]
for name,mittelwert in mittelausgabe:
2014-02-11 18:30:53 +01:00
print(name + ":\t%0.2f" % mittelwert) # jedes Tupel ausgeben
2014-02-11 16:38:01 +01:00
2014-02-10 14:29:03 +01:00
print("------Minimum-Maximum------")
minima = []
maxima = []
for spalte in liste:
minumax = minmax(spalte)
mini = minumax[0]
maxi = minumax[1]
minima.append(mini)
maxima.append(maxi)
minmaxausgabe = zip(namen,minima,maxima)
2014-02-11 18:48:10 +01:00
for name,minimum,maximum in minmaxausgabe:
print(name + ":\t" + str(minimum) + "\t" + str(maximum))
2014-02-11 16:38:01 +01:00
print("------Standardabweichung------")
standardabweichungen=[]
for spalte in liste:
2014-02-11 18:30:53 +01:00
abweichung = standardabweichung(spalte,mittelwerte[liste.index(spalte)]) #Mittelwert über Stelle in Liste herausfinden
standardabweichungen.append(abweichung)
stabausgabe = zip(namen,standardabweichungen)
for name,abweichung in stabausgabe:
print(name + ":\t%0.2f" % abweichung)