Add wind chill.
This commit is contained in:
parent
7e53a2b4e2
commit
7ffcfee1d3
@ -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 "";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user