Skip to content

Instantly share code, notes, and snippets.

@fokklz
Created January 31, 2023 13:31
Show Gist options
  • Save fokklz/461d26b217a29e87cab0eb0f614aa641 to your computer and use it in GitHub Desktop.
Save fokklz/461d26b217a29e87cab0eb0f614aa641 to your computer and use it in GitHub Desktop.
int hpa_to_scale(float hpa_value) {
// Define the range of HPA values that will correspond to the 1-10 scale
float min_hpa = 950.0;
float max_hpa = 1030.0;
// Normalize the HPA value to fall within the defined range
float normalized_hpa = fmax(fmin(hpa_value, max_hpa), min_hpa);
// Scale the normalized HPA value to the 1-10 range
int scale_value = round((normalized_hpa - min_hpa) * 10.0 / (max_hpa - min_hpa) + 1.0);
return scale_value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment