Skip to content

Instantly share code, notes, and snippets.

@WhoAteDaCake
Created September 25, 2018 17:48
Show Gist options
  • Save WhoAteDaCake/30b474652abf690cf851d2fc5864530b to your computer and use it in GitHub Desktop.
Save WhoAteDaCake/30b474652abf690cf851d2fc5864530b to your computer and use it in GitHub Desktop.
Rain
module Rain = {
/* All measurements are in mm */
module Hourly = {
let light = 2.5;
let moderate = 7.6;
let heavy = 50.0;
let violent = 100.0;
};
module Daily = {
let light = 2.5 *. 24.0;
let moderate = 7.6 *. 24.0;
let heavy = 50.0 *. 24.0;
let violent = 100.0 *. 24.0;
};
let score_to_text = n =>
switch (n) {
| 0 => "Light"
| 1 => "Moderate"
| 2 => "Heavy"
| _ => "Violent"
};
let hourlyIntensity = mm =>
Hourly.(
if (mm < light) {
0;
} else if (mm < moderate) {
1;
} else if (mm < heavy) {
2;
} else {
3;
}
);
let dailyIntensity = mm =>
Daily.(
if (mm < light) {
0;
} else if (mm < moderate) {
1;
} else if (mm < heavy) {
2;
} else {
3;
}
);
let intensity = (daily, hourly) =>
max(dailyIntensity(daily), hourlyIntensity(hourly)) |> score_to_text;
};
@WhoAteDaCake
Copy link
Author

WhoAteDaCake commented Sep 25, 2018

module Rain = {
  /* All measurements are in mm */
  let light = 2.5;
  let moderate = 7.6;
  let heavy = 50.0;
  let violent = 100.0;

  let score_to_text = n =>
    switch (n) {
    | 0 => "Light"
    | 1 => "Moderate"
    | 2 => "Heavy"
    | _ => "Violent"
    };
  let calculate_intensity = (multiplier, mm) =>
    if (mm < light *. multiplier) {
      0;
    } else if (mm < moderate *. multiplier) {
      1;
    } else if (mm < heavy *. multiplier) {
      2;
    } else {
      3;
    };
  let daily_intensity = calculate_intensity(24.0);
  let hourly_intensity = calculate_intensity(1.0);
  let intensity = (daily, hourly) =>
    max(daily_intensity(daily), hourly_intensity(hourly)) |> score_to_text;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment