This repository has been archived on 2022-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
patterns/observer/request/heatindexdisplay.d

40 lines
1.3 KiB
D
Raw Normal View History

2022-11-11 09:54:25 +00:00
module observer.request.heatindexdisplay;
2022-11-11 07:56:59 +00:00
2022-11-11 09:54:25 +00:00
import observer.request.displayelement;
import observer.request.observer;
import observer.request.weatherdata;
2022-11-11 07:22:38 +00:00
import std.stdio : writeln;
class HeatIndexDisplay : Observer, DisplayElement
{
private:
float heatIndex;
WeatherData weatherData;
float computeHeatIndex(float t, float rh)
{
return ((16.923 + (0.185212 * t) + (5.37941 * rh) - (0.100254 * t * rh) + (0.00941695 * (t * t))
+ (0.00728898 * (rh * rh)) + (0.000345372 * (t * t * rh)) - (0.000814971 * (t * rh * rh))
+ (0.0000102102 * (t * t * rh * rh)) - (0.000038646 * (t * t * t)) + (0.0000291583 * (rh * rh * rh))
+ (0.00000142721 * (t * t * t * rh)) + (0.000000197483 * (t * rh * rh * rh))
- (0.0000000218429 * (t * t * t * rh * rh)) + 0.000000000843296 * (t * t * rh * rh * rh))
- (0.0000000000481975 * (t * t * t * rh * rh * rh)));
}
public:
this(WeatherData weatherData)
{
2022-11-11 07:56:59 +00:00
this.weatherData = weatherData;
2022-11-11 07:22:38 +00:00
weatherData.registerObserver(this);
}
2022-11-11 07:56:59 +00:00
override void update()
2022-11-11 07:22:38 +00:00
{
2022-11-11 07:56:59 +00:00
this.heatIndex = computeHeatIndex(weatherData.getTemperature, weatherData.getHumidity);
2022-11-11 07:22:38 +00:00
display();
}
override void display()
{
writeln("Heat index is ", heatIndex);
}
}