Created
          June 28, 2011 13:19 
        
      - 
      
- 
        Save coffeeaddict/1051111 to your computer and use it in GitHub Desktop. 
    Calculate the humidex
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env ruby | |
| # estimate the dewpoint temperature | |
| def dew_point(temp, rv) | |
| e = 6.1121 * (10 ** (7.502 * temp / (237.7 + temp))) | |
| p = (rv * e) / 100.0 | |
| dp = (-430.22 + 237.7 * Math.log(p))/(-(Math.log(p)) + 19.08); | |
| end | |
| # estimate the wet bulb temperature | |
| def wet_bulb(temp, rv) | |
| ex = 0.6108*Math.exp((17.27*temp)/(temp+237.3)) | |
| ex_h = ex * rv / 100 | |
| d_p = 237.3*(((Math.log(ex_h/0.6108))/17.27)/(1-((Math.log(ex_h/0.6108))/17.27))); | |
| prem = (4099*ex)/((temp+237.3)**2) | |
| seco = (4099*ex_h )/((d_p+237.3)**2) | |
| third = (prem + seco) / 2; | |
| wb = temp - ( ex - ex_h ) / (third + 0.00066 * 101.325) | |
| wb + 1 | |
| end | |
| temp = ARGV.shift.to_f | |
| rv = ARGV.shift.to_f | |
| puts "Estimates:" | |
| puts "\tDew point : #{dew_point(temp, rv)}" | |
| puts "\tWet bulb : #{wet_bulb(temp, rv)}" | |
| # TODO parse opts for this | |
| motion = 0 # air motion, 0 = none, -0.2 some, -0.4 fair | |
| radiation = 2.1 # heath radiation, 0 = none, 2.1 = some, 4.5 = strong, | |
| # 3.1 = direct sunlight | |
| clothing = 0 # 0 = summer clothing, 3.5 overall, 5 double overall | |
| black_globe = temp + radiation + clothing + motion | |
| wbg_temp = 0.7 * wet_bulb(temp, rv) + 0.3 * black_globe | |
| puts "\tWBGT : #{wbg_temp}" | |
| metabolism = 1 # 0 light work, 1 = moderate work, 2 = heavy work, | |
| # 3 = extra heavy work | |
| acclimated = 0 # 0 = not acclimated, 1 = acclimated | |
| conditions = case acclimated | |
| when 0 | |
| case metabolism | |
| when 0 | |
| { 27.5 => "OK", 29 => "75% work - 25% rest", | |
| 30 => "50% work - 50% rest", 31 => "25% work - 75% rest" } | |
| when 1 | |
| { 25 => "OK", 26.5 => "75% work - 25% rest", | |
| 28 => "50% work - 50% rest", 29 => "25% work - 75% rest" } | |
| when 2 | |
| { 22.5 => "OK", 24.5 => "75% work - 25% rest", | |
| 26.5 => "50% work - 50% rest", 28 => "25% work - 75% rest" } | |
| when 3 | |
| { 25 => "50% work - 50% rest", | |
| 26.5 => "25% work - 75% rest" } | |
| end | |
| when 1 | |
| case metabolism | |
| when 0 | |
| { 29.5 => "OK", 30.5 => "75% work - 25% rest", | |
| 31.5 => "50% work - 50% rest", 32.5 => "25% work - 75% rest" } | |
| when 1 | |
| { 27.5 => "OK", 28.5 => "75% work - 25% rest", | |
| 29.5 => "50% work - 50% rest", 31 => "25% work - 75% rest" } | |
| when 2 | |
| { 26 => "OK", 27.5 => "75% work - 25% rest", | |
| 28.5 => "50% work - 50% rest", 30 => "25% work - 75% rest" } | |
| when 3 | |
| { 27.5 => "50% work - 50% rest", | |
| 29.5 => "25% work - 75% rest" } | |
| end | |
| end | |
| condition = nil | |
| conditions.keys.sort.each do |index| | |
| if wbg_temp <= index | |
| condition = conditions[index] | |
| break | |
| end | |
| end | |
| condition ||= "STOP WORK" | |
| puts "\nConditions:\n\t#{condition}" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment