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

71 lines
2.2 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-02 14:35:07 +01:00
def offnen(datei):
2014-02-11 18:30:53 +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:30:53 +01:00
summe = 0
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
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-02 14:35:07 +01:00
offnen("vorbereitet.csv")
namen = ["Innentemperatur", "Gerätetemperatur 1", "Außentemperatur", "Gerätetemperatur 2", "Temperatur (Luft)", "Luftfeuchtigkeit", "Luftdruck", "Temperatur (Druck)", "Prozessor"]
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)
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)