Weather-Simulator is a Java tool to predict weather for a location.
The tool predicts the weather data like Temperature, Cloud Cover, Dew Point, Humidity, Pressure, Wind Speed, Summary for a given location.
High level flow:-
-
Get the location details from User.
-
Based on location, get the Lat/Long coordinates using the configuration file LatLongCity.list.json.
-
Get the elevation of a location using Elevation API (https://elevation-api.io/)
-
Get the current weather data using Dark Sky API (https://darksky.net/dev) for that location.
-
Get the weather data for last N days for that location using Dark Sky API.
-
Get the last year weather data (Historical data) for that location using Dark Sky API. This includes ( LAST_YEAR_N_PREVIOUS_DAYS + LAST_YEAR_CURRENT_DATE + LAST_YEAR_N_SUBSEQUENT_DAYS ) weather data.
-
Last N days weather data is used to predict the features - Temperature, Cloud Cover, Dew Point, Humidity, Pressure, Wind Speed.
Predicted value of a feature = Mean of a feature for last N days + Random number within ( 0 to Standard Deviation of that feature)
-
Last year weather data is used to predict the Summary Feature. Values of Summary Feature can be Sunny, Snow, Rain, Cloudy, Partly Cloudy, Clear etc.
Prediction of Summary Feature = Euclidean distance between predicted Weather data and last year weather data and get the summary that have minimum distance
Sample Output
```
Location Position Local Time Conditions Temperature Cloud Cover Dew Point Humidity Pressure Wind Speed
---------------------------------------------------------------------------------------------------------------------------------------------------
westmead -33.803829,150.987686,34 2019-04-22 11:49:01 Partly Cloudy 68.68 0.50 64.18 0.91 1025.70 6.01
rooty hill -33.76667,150.833328,50 2019-04-22 11:49:06 Mostly Cloudy 64.99 0.55 61.25 0.91 1026.07 4.33
sydney -33.867851,151.207321,8 2019-04-22 11:49:10 Partly Cloudy 69.65 0.46 65.58 0.92 1025.73 8.31
seven hills 30.654079,-88.303062,50 2019-04-22 11:49:14 Clear 61.96 0.46 62.62 0.90 1016.13 6.84
```
- Java 8
- Maven
- JUnit
- RPM
Click here to download the RPM
-
Update the Weather API Key
The tool uses the Dark Sky API to get the recent weather and historical weather details.
Register the user in https://darksky.net/dev/register Login to Dark Sky API - https://darksky.net/dev/account to get the secret key.
Open the WeatherSimulator.properties and update the property weatherAPI.connector.key
-
Build using maven
Update the Weather API Key (property weatherAPI.connector.key) in src/test/resources/WeatherSimulator.properties
mvn clean compile package -DWeatherSimulator.properties=src/test/resources/WeatherSimulator.properties
Build will compile, test and generate the RPM and final RPM is copied to RPM Directory
-
Install RPM
Click here to download the RPM
[root@hdp3test3 ~]# rpm -ivh WeatherSimulator-1.0-1.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:WeatherSimulator-1.0-1 ################################# [100%] [root@hdp3test3 ~]#
-
Running the script
After installing RPM, Application will be available under /opt/WeatherSimulator
- The scripts will be available under /opt/WeatherSimulator/bin/
- Configuration files & log4j.properties are under /opt/WeatherSimulator/conf/
- The application logs will be in /opt/WeatherSimulator/log/
- The forecast output will be written to files under /opt/WeatherSimulator/output/
[root@hdp3test3 ~]# cd /opt/WeatherSimulator/ [root@hdp3test3 WeatherSimulator]# ls bin conf lib log output Readme.txt [root@hdp3test3 WeatherSimulator]#
Update the Weather API Key (property weatherAPI.connector.key) in /opt/WeatherSimulator/conf/WeatherSimulator.properties
[root@hdp3test3 opt]# cd /opt/WeatherSimulator/bin/ [root@hdp3test3 bin]# ./WeatherSimulator Enter the City/Suburb: Westmead Would you like to add more location (y/n): y Enter the City/Suburb: Rooty hill Would you like to add more location (y/n): y Enter the City/Suburb: Sydney Multiple Suburbs exist in same name. Id Suburb Country ====================================================================== 1 sydney CA 2 sydney AU Select the suburb you would like to get the weather details: 2 Would you like to add more location (y/n): y Enter the City/Suburb: Seven Hills Would you like to add more location (y/n): n Processing the Weather simulation Location Position Local Time Conditions Temperature Cloud Cover Dew Point Humidity Pressure Wind Speed --------------------------------------------------------------------------------------------------------------------------------------------------- westmead -33.803829,150.987686,34 2019-04-22 11:49:01 Partly Cloudy 68.68 0.50 64.18 0.91 1025.70 6.01 rooty hill -33.76667,150.833328,50 2019-04-22 11:49:06 Mostly Cloudy 64.99 0.55 61.25 0.91 1026.07 4.33 sydney -33.867851,151.207321,8 2019-04-22 11:49:10 Partly Cloudy 69.65 0.46 65.58 0.92 1025.73 8.31 seven hills 30.654079,-88.303062,50 2019-04-22 11:49:14 Clear 61.96 0.46 62.62 0.90 1016.13 6.84 Weather output written to /opt/WeatherSimulator/output/weatherResults2019_04_22_23_49_14.txt Weather Prediction completed. [root@hdp3test3 bin]# [root@hdp3test3 bin]# cat /opt/WeatherSimulator/output/weatherResults2019_04_22_23_49_14.txt Location|Position|Local Time|Conditions|Temperature|Cloud Cover|Dew Point|Humidity|Pressure|Wind Speed rooty|hill|-33.76667,150.833328,50|2019-04-22|11:49:06|Mostly|Cloudy|64.99|0.55|61.25|0.91|1026.07|4.33| sydney|-33.867851,151.207321,8|2019-04-22|11:49:10|Partly|Cloudy|69.65|0.46|65.58|0.92|1025.73|8.31| seven|hills|30.654079,-88.303062,50|2019-04-22|11:49:14|Clear|61.96|0.46|62.62|0.90|1016.13|6.84| [root@hdp3test3 bin]#
-
Uninstalling RPM
[root@hdp3test3 bin]# rpm -e WeatherSimulator-1.0-1.noarch Uninstalling the Weather Simulator Setup completed [root@hdp3test3 bin]#
-
How do I debug the issues?
Enable the DEBUG in /opt/WeatherSimulator/conf/log4j.properties. The logs will be in /opt/WeatherSimulator/log
-
How do I add new locations to the tool?
Add the new location to /opt/WeatherSimulator/conf/LatLongCity.list.json.
The sample format
{ "id": 123678, "name": "Trichur", "country": "IN", "coord": { "lon": 134.283333, "lat": 24.549999 } }
-
How do I improve the accuracy of the prediction.
Increase the value of property weatherAPI.lastNDaysWeather in WeatherSimulator.properties. By default, tool takes the last 5 days and last year 10 days to predict the features. Increasing the value will help in providing more accurate predictions.
This application uses API's provided by below third parties.
- Dark Sky API (https://darksky.net/dev) to get the recent weather and historical weather details.
- Elevation API (https://elevation-api.io/) to get the elevation for a latitude/longitude coordinates.
- OpenWeatherMap (https://openweathermap.org/api) to get the latitiude/longitude for a location.
Nisanth Simon - NisanthSimon@LinkedIn