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
pub struct HeatWave { pub maxtemperaturec: f64, pub durationdays: u32, pub relativehumiditypercent: f64, } impl HeatWave { pub fn heatindexc(&self) -> f64 { let t = self.maxtemperaturec; let rh = self.relativehumiditypercent; let tf = t * 9.0 / 5.0 + 32.0; let hif = -42.379 + 2.04901523 * tf + 10.14333127 * rh - 0.22475541 * tf * rh - 6.83783e-3 * tf * tf - 5.481717e-2 * rh * rh + 1.22874e-3 * tf * tf * rh + 8.5282e-4 * tf * rh * rh - 1.99e-6 * tf * tf * rh * rh; (hif - 32.0) * 5.0 / 9.0 } pub fn wetbulbtemperaturec(&self) -> f64 { let t = self.maxtemperaturec; let rh = self.relativehumiditypercent; t * (0.151977 * (rh + 8.313659f64).sqrt()).atan() + (t + rh).atan() - (rh - 1.676331).atan() + 0.00391838 * rh.powf(1.5) * (0.023101 * rh).atan() - 4.686035 } pub fn dangerlevel(&self) -> &'static str { let hi = self.heatindexc(); if hi >= 54.0 { "Extreme danger" } else if hi >= 41.0 { "Danger" } else if hi >= 32.0 { "Extreme caution" } else if hi >= 27.0 { "Caution" } else { "Normal" } } pub fn excessmortalityfactor(&self) -> f64 { let threshold = 30.0; if self.maxtemperaturec <= threshold { 1.0 } else { 1.0 + 0.03 * (self.maxtemperaturec - threshold) * self.durationdays as f64 } } } pub fn saturationvaporpressurepa(tempc: f64) -> f64 { 610.78 * (17.27 * tempc / (tempc + 237.3)).exp() } pub fn dewpointc(tempc: f64, relativehumidity: f64) -> f64 { let a = 17.27; let b = 237.3; let alpha = a * tempc / (b + tempc) + (relativehumidity / 100.0).ln(); b * alpha / (a - alpha) }