Skip to content

Commit

Permalink
block[weather]: nws convert wind speed from km/s to m/s
Browse files Browse the repository at this point in the history
  • Loading branch information
bim9262 committed Jul 11, 2024
1 parent 07bf5bc commit 6dcc632
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/blocks/weather/nws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ impl ApiForecast {
.to_string()
}

fn wind_speed(&self) -> f64 {
if self.wind_speed.unit_code.ends_with("km_h-1") {
// m/s
self.wind_speed.value / 3.6
} else {
// mph
self.wind_speed.value
}
}

fn wind_kmh(&self) -> f64 {
if self.wind_speed.unit_code.ends_with("km_h-1") {
self.wind_speed.value
Expand All @@ -177,6 +187,7 @@ impl ApiForecast {
(self.temperature.value - 32.0) * 5.0 / 9.0
};
let humidity = self.relative_humidity.value;
// wind_speed in m/s
let wind_speed = self.wind_kmh() / 3.6;
let apparent = australian_apparent_temp(temp, humidity, wind_speed);
if self.temperature.unit_code.ends_with("degC") {
Expand All @@ -196,7 +207,7 @@ impl ApiForecast {
temp: self.temperature.value,
apparent: self.apparent_temp(),
humidity: self.relative_humidity.value,
wind: self.wind_speed.value,
wind: self.wind_speed(),
wind_kmh: self.wind_kmh(),
wind_direction: self.wind_direction(),
}
Expand All @@ -207,7 +218,7 @@ impl ApiForecast {
temp: self.temperature.value,
apparent: self.apparent_temp(),
humidity: self.relative_humidity.value,
wind: self.wind_speed.value,
wind: self.wind_speed(),
wind_kmh: self.wind_kmh(),
wind_direction: self.wind_direction(),
}
Expand Down

0 comments on commit 6dcc632

Please sign in to comment.