forked from SBorg2014/WLAN-Wetterstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.py
162 lines (144 loc) · 6.42 KB
/
fields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# if [[ ${MESSWERTERAWIN[$i]} == tempinf=* ]] || [[ ${MESSWERTERAWIN[$i]} == indoortempf=* ]]
# then MESSWERTE[0]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_F_to_C 0; fi
# if [[ ${MESSWERTERAWIN[$i]} == tempf=* ]]
# then MESSWERTE[1]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_F_to_C 1; fi
# if [[ ${MESSWERTERAWIN[$i]} == dewptf=* ]]
# then MESSWERTE[2]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_F_to_C 2; fi
# if [[ ${MESSWERTERAWIN[$i]} == windchillf=* ]]
# then MESSWERTE[3]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_F_to_C 3; fi
# if [[ ${MESSWERTERAWIN[$i]} == humidityin=* ]] || [[ ${MESSWERTERAWIN[$i]} == indoorhumidity=* ]]
# then MESSWERTE[4]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); fi
# if [[ ${MESSWERTERAWIN[$i]} == humidity=* ]]
# then MESSWERTE[5]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); fi
# if [[ ${MESSWERTERAWIN[$i]} == windspeedmph=* ]]
# then MESSWERTE[6]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_MPH_to_KMH 6; fi
# if [[ ${MESSWERTERAWIN[$i]} == windgustmph=* ]]
# then MESSWERTE[7]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_MPH_to_KMH 7; fi
# if [[ ${MESSWERTERAWIN[$i]} == winddir=* ]]
# then MESSWERTE[8]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); winddir 8; fi
# if [[ ${MESSWERTERAWIN[$i]} == baromabsin=* ]] || [[ ${MESSWERTERAWIN[$i]} == absbaromin=* ]]
# then MESSWERTE[9]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_luftdruck 9; fi
# if [[ ${MESSWERTERAWIN[$i]} == baromrelin=* ]] || [[ ${MESSWERTERAWIN[$i]} == baromin=* ]]
# then MESSWERTE[10]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_luftdruck 10; fi
# if [[ ${MESSWERTERAWIN[$i]} == rainratein=* ]] || [[ ${MESSWERTERAWIN[$i]} == rainin=* ]]
# then MESSWERTE[11]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 11; fi
# if [[ ${MESSWERTERAWIN[$i]} == dailyrainin=* ]]
# then MESSWERTE[12]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 12; fi
# if [[ ${MESSWERTERAWIN[$i]} == weeklyrainin=* ]]
# then MESSWERTE[13]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 13; fi
# if [[ ${MESSWERTERAWIN[$i]} == monthlyrainin=* ]]
# then MESSWERTE[14]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 14; fi
# if [[ ${MESSWERTERAWIN[$i]} == yearlyrainin=* ]]
# then MESSWERTE[15]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 15; fi
# if [[ ${MESSWERTERAWIN[$i]} == solarradiation=* ]]
# then MESSWERTE[16]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); sonnenpuls 16; fi
# if [[ ${MESSWERTERAWIN[$i]} == uv=* ]] || [[ ${MESSWERTERAWIN[$i]} == UV=* ]]
# then MESSWERTE[17]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); uv_belastung 17; fi
# if [[ ${MESSWERTERAWIN[$i]} == dateutc=* ]]
# then MESSWERTE[18]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_time 18; fi
# if [[ ${MESSWERTERAWIN[$i]} == stationtype=* ]] || [[ ${MESSWERTERAWIN[$i]} == softwaretype=* ]]
# then MESSWERTE[19]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); fi
# if [[ ${MESSWERTERAWIN[$i]} == wh65batt=* ]]
# then MESSWERTE[20]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); fi
# if [[ ${MESSWERTERAWIN[$i]} == maxdailygust=* ]]
# then MESSWERTE[21]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_MPH_to_KMH 21; fi
# if [[ ${MESSWERTERAWIN[$i]} == eventrainin=* ]]
# then MESSWERTE[22]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 22; fi
# if [[ ${MESSWERTERAWIN[$i]} == hourlyrainin=* ]]
# then MESSWERTE[23]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 23; fi
# if [[ ${MESSWERTERAWIN[$i]} == totalrainin=* ]]
# then MESSWERTE[24]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); convert_Inch_to_MM 24; fi
# if [[ ${MESSWERTERAWIN[$i]} == model=* ]]
# then MESSWERTE[25]=$(echo ${MESSWERTERAWIN[$i]}|cut -d"=" -f2); fi'
def convert_F_to_C(x):
return (float(x) - 32.0) * 5.0 / 9.0
def convert_MPH_to_KMH(x):
return float(x) * 16094.0 / 10000.0
_WIND_DIRS = [
"N", "NNO", "NO",
"ONO", "O", "OSO",
"SO", "SSO", "S", "SSW", "SW",
"WSW", "W", "WNW",
"NW", "NNW", "N"
]
def winddir(x):
#WINDRICHTUNG=${WINDDIRS[$(round ${MESSWERTE[$1]}/22.5 0)]}
return float(x)
return _WIND_DIRS[int(float(x) / 22.5)]
def convert_luftdruck(x):
return float(x) * 33864 / 1000.0
def convert_Inch_to_MM(x):
return float(x) * 254 / 10.0
#TODO THIS DOES A LOT MORE IN THE ORIGINAL
def sonnenpuls(x):
return x
def uv_belastung(x):
return x
def convert_time(x):
return x
_fields = [
("tempinf", "indoortempf"), #=* ]] || [[ ${MESSWERTERAWIN[$i]} == indoortempf=*
"tempf",#=*
"dewptf",#=*
"windchillf",#=*
("humidityin", "indoorhumidity"), #=* ]] || [[ ${MESSWERTERAWIN[$i]} == indoorhumidity=*
"humidity",#=*
"windspeedmph",#=*
"windgustmph",#=*
"winddir",#=*
("baromabsin", "absbaromin"), #=* ]] || [[ ${MESSWERTERAWIN[$i]} == absbaromin=*
("baromrelin", "baromin"), #=* ]] || [[ ${MESSWERTERAWIN[$i]} == baromin=*
("rainratein", "rainin"), #=* ]] || [[ ${MESSWERTERAWIN[$i]} == rainin=*
"dailyrainin",#=*
"weeklyrainin",#=*
"monthlyrainin",#=*
"yearlyrainin",#=*
"solarradiation",#=*
("uv", "UV"), #=* ]] || [[ ${MESSWERTERAWIN[$i]} == UV=*
"dateutc",#=*
("stationtype", "softwaretype"), #=* ]] || [[ ${MESSWERTERAWIN[$i]} == softwaretype=*
"wh65batt",#=*
"maxdailygust",#=*
"eventrainin",#=*
"hourlyrainin",#=*
"totalrainin",#=*
"model",#=*
]
_processing = [
convert_F_to_C,
convert_F_to_C,
convert_F_to_C,
convert_F_to_C,
float,
float,
convert_MPH_to_KMH,
convert_MPH_to_KMH,
winddir,
convert_luftdruck,
convert_luftdruck,
convert_Inch_to_MM,
convert_Inch_to_MM,
convert_Inch_to_MM,
convert_Inch_to_MM,
convert_Inch_to_MM,
sonnenpuls,
uv_belastung,
convert_time,
None,
None,
convert_MPH_to_KMH,
convert_Inch_to_MM,
convert_Inch_to_MM,
convert_Inch_to_MM,
None
]
FIELDS = {}
PROCESSING = {}
for v, p in zip(_fields, _processing):
if isinstance(v, tuple):
for u in v:
FIELDS[u] = v[0]
PROCESSING[v[0]] = p
else:
FIELDS[v] = v
PROCESSING[v] = p