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-11 18:11:24 +01:00
|
|
|
|
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:
|
2014-02-11 18:11:24 +01:00
|
|
|
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-02 14:35:07 +01:00
|
|
|
offnen("vorbereitet.csv")
|
2014-02-11 18:11:24 +01:00
|
|
|
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
|
2014-02-11 18:11:24 +01:00
|
|
|
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)]
|
2014-02-11 18:11:24 +01:00
|
|
|
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------")
|
2014-02-11 18:11:24 +01:00
|
|
|
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:
|
2014-02-11 18:11:24 +01:00
|
|
|
print(name + ":\t" + str(minimum) + "\t" + str(maximum))
|
2014-02-11 16:38:01 +01:00
|
|
|
print("------Standardabweichung------")
|
2014-02-11 18:11:24 +01:00
|
|
|
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
|
2014-02-11 18:11:24 +01:00
|
|
|
standardabweichungen.append(abweichung)
|
|
|
|
stabausgabe = zip(namen,standardabweichungen)
|
|
|
|
for name,abweichung in stabausgabe:
|
|
|
|
print(name + ":\t%0.2f" % abweichung)
|