Add wind chill.

This commit is contained in:
Hyperling 2025-04-25 17:33:11 -07:00
parent 7e53a2b4e2
commit 7ffcfee1d3

View File

@ -2,19 +2,18 @@
import '/var/config.dart';
import 'package:flutter/material.dart';
import 'dart:math';
String formatOpenWeatherData(var data) {
String location = pullOpenWeatherCity(data),
temp = pullOpenWeatherTemp(data),
conditions = pullOpenWeatherConditions(data),
windSpeed = pullOpenWeatherWind(data),
humidity = pullOpenWeatherHumidity(data),
windChill = "",
heatIndex = "",
comfort = "";
humidity = pullOpenWeatherHumidity(data);
// Always ask for Imperial units in API request
final String tempUnits = 'F', windUnits = 'mph', humidityUnits = '%';
String windChill = getWindChill(temp, windSpeed), heatIndex = "";
String comfort = "";
String text =
"$location is $temp$tempUnits and $conditions"
@ -70,3 +69,30 @@ String pullOpenWeatherHumidity(var data) {
}
return humidity;
}
double calcWindChill(double temp, double windSpeed) {
// ## Wind Chill ##
// # Wind speed as noted in: https://answers.yahoo.com/question/index?qid=20091020183148AAHm3kB&guccounter=1
// # More official source: https://www.weather.gov/media/epz/wxcalc/windChill.pdf
double windChill =
35.74 +
(0.6215 * temp) -
(35.75 * pow(windSpeed, 0.16)) +
(0.4275 * temp * pow(windSpeed, 0.16));
if (debug) {
debugPrint("DEBUG: windChill = '$windChill'");
}
return windChill;
}
String getWindChill(String temp, String windSpeed) {
double temperature = double.parse(temp);
double wind = double.parse(windSpeed);
if (temperature < 50 && wind > 5) {
double windChill = calcWindChill((temperature), (wind));
return "My guess is that's a wind chill of $windChill$tempUnits";
}
return "";
}