@@ -112,12 +112,39 @@ def display(self):
112
112
print ("Watch out for cooler, rainy weather" )
113
113
114
114
115
+ class HeatIndexDisplay (DisplayElement , Observer ):
116
+ def __init__ (self , weather_data ):
117
+ self .heat_index = 0.
118
+ self ._weather_data = weather_data
119
+ weather_data .register_observer (self )
120
+
121
+ def update (self , temp , humidity , pressure ):
122
+ self .heat_index = self ._compute_heat_index (temp , humidity )
123
+ self .display ()
124
+
125
+ def display (self ):
126
+ print (f"Heat index is { self .heat_index :.5f} " )
127
+
128
+ @classmethod
129
+ def _compute_heat_index (cls , t , rh ):
130
+ index = ((16.923 + (0.185212 * t ) + (5.37941 * rh ) - (0.100254 * t * rh )
131
+ + (0.00941695 * (t * t )) + (0.00728898 * (rh * rh ))
132
+ + (0.000345372 * (t * t * rh )) - (0.000814971 * (t * rh * rh )) +
133
+ (0.0000102102 * (t * t * rh * rh )) - (0.000038646 * (t * t * t )) +
134
+ (0.0000291583 * (rh * rh * rh )) + (0.00000142721 * (t * t * t * rh )) +
135
+ (0.000000197483 * (t * rh * rh * rh )) - (0.0000000218429 * (t * t * t * rh * rh )) +
136
+ 0.000000000843296 * (t * t * rh * rh * rh )) -
137
+ (0.0000000000481975 * (t * t * t * rh * rh * rh )))
138
+ return index
139
+
140
+
115
141
def weather_station ():
116
142
weather_data = WeatherData ()
117
143
118
144
current_display = CurrentConditionsDisplay (weather_data )
119
145
statistics_display = StatisticsDisplay (weather_data )
120
146
forecast_display = ForecastDisplay (weather_data )
147
+ heat_index_display = HeatIndexDisplay (weather_data )
121
148
122
149
weather_data .set_measurements (80 , 65 , 30.4 )
123
150
weather_data .set_measurements (82 , 70 , 29.2 )
0 commit comments