Compare commits
7 Commits
7ffcfee1d3
...
dev
Author | SHA1 | Date | |
---|---|---|---|
ad4630e495 | |||
2ee8eaecc8 | |||
13c532e87f | |||
70eaa8a4fb | |||
3ae27fdda4 | |||
4132aa0f83 | |||
6e2d293cdc |
3
assets/README.md
Normal file
3
assets/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Assets
|
||||
|
||||
Images and other media for Buddy.
|
4
bin/README.md
Normal file
4
bin/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# bin
|
||||
|
||||
Helper scripts forthose new to Flutter or for myself if I take a break and need
|
||||
reminders. ;D
|
@ -4,18 +4,19 @@ import '/var/config.dart';
|
||||
import '/var/secrets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
//import 'dart:convert';
|
||||
|
||||
// Generic method to hit a GET request and return the response.
|
||||
Future<String> hitAPI(String url) async {
|
||||
if (debug) debugPrint("DEBUG: URL is '$url'.");
|
||||
|
||||
try {
|
||||
http.Response response = await http.get(Uri.parse(url));
|
||||
|
||||
String data = "";
|
||||
if (response.statusCode == 200) {
|
||||
data = response.body;
|
||||
var decodedData = jsonDecode(data);
|
||||
//var decodedData = jsonDecode(data);
|
||||
//data = decodedData.toString();
|
||||
//data = jsonEncode(decodedData);
|
||||
if (debugVerbose) {
|
||||
@ -30,6 +31,9 @@ Future<String> hitAPI(String url) async {
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (e) {
|
||||
return "Sorry! It seems we have an issue: '${e.toString()}'.";
|
||||
}
|
||||
}
|
||||
|
||||
// How to guide: https://openweathermap.org/current#zip
|
||||
|
@ -11,7 +11,10 @@ String formatOpenWeatherData(var data) {
|
||||
windSpeed = pullOpenWeatherWind(data),
|
||||
humidity = pullOpenWeatherHumidity(data);
|
||||
|
||||
String windChill = getWindChill(temp, windSpeed), heatIndex = "";
|
||||
String windChill = getWindChill(temp, windSpeed),
|
||||
heatIndex = getHeatIndex(temp, humidity),
|
||||
windAnnoyance = getWindAnnoyance(temp, windSpeed),
|
||||
feelsLike = getUniversalThermalClimateIndex();
|
||||
|
||||
String comfort = "";
|
||||
|
||||
@ -19,7 +22,10 @@ String formatOpenWeatherData(var data) {
|
||||
"$location is $temp$tempUnits and $conditions"
|
||||
" with a wind speed of $windSpeed$windUnits"
|
||||
" and humidity of $humidity$humidityUnits."
|
||||
" $windChill$heatIndex"
|
||||
" $windChill"
|
||||
" $heatIndex"
|
||||
" $windAnnoyance"
|
||||
" $feelsLike"
|
||||
" $comfort";
|
||||
|
||||
final String doubleSpace = " ", singleSpace = " ";
|
||||
@ -89,10 +95,83 @@ String getWindChill(String temp, String windSpeed) {
|
||||
double temperature = double.parse(temp);
|
||||
double wind = double.parse(windSpeed);
|
||||
|
||||
if (temperature < 50 && wind > 5) {
|
||||
if ((temperature < 50 && wind > 5) || debug) {
|
||||
double windChill = calcWindChill((temperature), (wind));
|
||||
return "My guess is that's a wind chill of $windChill$tempUnits";
|
||||
return "My guess is that's a wind chill of $windChill$tempUnits.";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
double calcHeatIndex(double temp, double humidity) {
|
||||
// ## Heat Index ##
|
||||
// # Official formula: https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
|
||||
double heatIndex =
|
||||
-42.379 +
|
||||
2.04901523 * temp +
|
||||
10.14333127 * humidity -
|
||||
0.22475541 * temp * humidity -
|
||||
0.00683783 * temp * temp -
|
||||
0.05481717 * humidity * humidity +
|
||||
0.00122874 * temp * temp * humidity +
|
||||
0.00085282 * temp * humidity * humidity -
|
||||
0.00000199 * temp * temp * humidity * humidity;
|
||||
|
||||
if (humidity < 13 && temp >= 80 && temp <= 112) {
|
||||
heatIndex -= ((13 - humidity) / 4) * sqrt((17 - (temp - 95.0).abs()) / 17);
|
||||
}
|
||||
|
||||
if (humidity > 85 && temp >= 80 && temp <= 87) {
|
||||
heatIndex += ((humidity - 85) / 10) * ((87 - temp) / 5);
|
||||
}
|
||||
|
||||
if (heatIndex < 80) {
|
||||
heatIndex =
|
||||
0.5 * (temp + 61.0 + ((temp - 68.0) * 1.2) + (humidity * 0.094));
|
||||
heatIndex = (heatIndex + temp) / 2;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: heatIndex = '$heatIndex'");
|
||||
}
|
||||
return heatIndex;
|
||||
}
|
||||
|
||||
String getHeatIndex(String temp, String humidity) {
|
||||
double temperature = double.parse(temp);
|
||||
double humid = double.parse(humidity);
|
||||
|
||||
if (temperature > 80 || debug) {
|
||||
double heatIndex = calcHeatIndex((temperature), (humid));
|
||||
return "My guess is that's a heat index of $heatIndex$tempUnits.";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
double calcWindAnnoyance(double temp, double windSpeed) {
|
||||
double windAnnoyance = (temp / (windSpeed * (windSpeed * 0.05)));
|
||||
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: windAnnoyance = '$windAnnoyance'");
|
||||
}
|
||||
return windAnnoyance;
|
||||
}
|
||||
|
||||
String getWindAnnoyance(String temp, String windSpeed) {
|
||||
double temperature = double.parse(temp);
|
||||
double wind = double.parse(windSpeed);
|
||||
|
||||
double windAnnoyance = calcWindAnnoyance(temperature, wind);
|
||||
|
||||
if (windAnnoyance < 3) {
|
||||
return "Wind may be a bit much for the temperature.";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
double calcUniversalThermalClimateIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String getUniversalThermalClimateIndex() {
|
||||
return "";
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Local
|
||||
import 'dart:convert';
|
||||
|
||||
import '/var/secrets.dart';
|
||||
//import '/var/secrets.dart';
|
||||
import '/var/config.dart';
|
||||
import 'helpers/http.dart';
|
||||
import 'helpers/json.dart';
|
||||
@ -23,6 +23,12 @@ class MainApp extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MainAppState extends State<MainApp> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
String _zipcode = "";
|
||||
String _city = "";
|
||||
String _country = "";
|
||||
String _latlong = "";
|
||||
|
||||
String weather = loadText;
|
||||
bool keepLoading = false;
|
||||
DateTime lastLoadTime = DateTime.now().subtract(
|
||||
@ -42,6 +48,80 @@ class _MainAppState extends State<MainApp> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget form = Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 20,
|
||||
width: 100,
|
||||
child: TextFormField(
|
||||
initialValue: _zipcode,
|
||||
validator: (value) {
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_zipcode = value!;
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
width: 100,
|
||||
child: TextFormField(
|
||||
initialValue: _city,
|
||||
validator: (value) {
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_city = value!;
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
width: 100,
|
||||
child: TextFormField(
|
||||
initialValue: _country,
|
||||
validator: (value) {
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_country = value!;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
width: 300,
|
||||
child: TextFormField(
|
||||
initialValue: _latlong,
|
||||
validator: (value) {
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_latlong = value!;
|
||||
},
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
}
|
||||
},
|
||||
child: Text("Save"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget weatherLayout = Column(
|
||||
children: [Text(weather), CircularProgressIndicator()],
|
||||
);
|
||||
@ -71,7 +151,13 @@ class _MainAppState extends State<MainApp> {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: Column(children: [Text('Weather Today!'), weatherLayout]),
|
||||
child: Column(
|
||||
children: [
|
||||
Text('Weather Today!'),
|
||||
form,
|
||||
Expanded(child: weatherLayout),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -97,6 +183,10 @@ class _MainAppState extends State<MainApp> {
|
||||
weather = "Please enter a location.";
|
||||
}
|
||||
|
||||
if (weather.toString().contains("Sorry!")) {
|
||||
return weather;
|
||||
}
|
||||
|
||||
if (weather != loadText) {
|
||||
if (debug) {
|
||||
debugPrint("DEBUG: Formatting text.");
|
||||
|
3
notes/README.md
Normal file
3
notes/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Notes
|
||||
|
||||
Any calculations, tests, or general ideas for functionality within Buddy. :)
|
BIN
notes/WindyTempComfortCalculations.ods
Normal file
BIN
notes/WindyTempComfortCalculations.ods
Normal file
Binary file not shown.
Reference in New Issue
Block a user