1 package IrrigationController;
3 // Standard Java Packages
4 import java.text.SimpleDateFormat;
5 import java.text.ParseException;
8 /** Class DayWeather to represent the parsed weather data as a compact object.
10 * @author Ali Younis <ayounis @ uci.edu>
14 public class DayWeather {
16 // enumeration representing the weather conditions
17 public enum WeatherConditions {
18 THUNDERSTORM_WITH_LIGHT_RAIN,
19 THUNDERSTORM_WITH_RAIN,
20 THUNDERSTORM_WITH_HEAVY_RAIN,
25 THUNDERSTORM_WITH_LIGHT_DRIZZLE,
26 THUNDERSTORM_WITH_DRIZZLE,
27 THUNDERSTORM_WITH_HEAVY_DRIZZLE,
28 LIGHT_INTENSITY_DRIZZLE,
30 HEAVY_INTENSITY_DRIZZLE,
31 LIGHT_INTENSITY_DRIZZLE_RAIN,
33 HEAVY_INTENSITY_DRIZZLE_RAIN,
34 SHOWER_RAIN_AND_DRIZZLE,
35 HEAVY_SHOWER_RAIN_AND_DRIZZLE,
43 LIGHT_INTENSITY_SHOWER_RAIN,
45 HEAVY_INTENSITY_SHOWER_RAIN,
93 /*******************************************************************************************************************************************
97 *******************************************************************************************************************************************/
98 private Date date = null;
99 private WeatherConditions weatherCondition = WeatherConditions.UNKNOWN;
102 private String windDirection = "";
103 private int windDirectionDegrees = 0; // In degrees
104 private float windSpeed = 0; // In Miles per hour
106 // Temperature Information
107 private float dayTemperature = 0; // In degrees F
108 private float eveningTemperature = 0; // In degrees F
109 private float morningTemperature = 0; // In degrees F
110 private float nightTemperature = 0; // In degrees F
111 private float maxTemperature = 0; // In degrees F
112 private float minTemperature = 0; // In degrees F
115 private float pressure = 0; // In hPa
116 private float humidity = 0; // In percent
117 private float cloudPercentage = 0; // In percent
122 * @param _date [String], String representing the date information for this days weather.
123 * @param _weatherCondition [String], String representing the weather condition code information for this days weather.
124 * @param _windDirection [String], String representing the wind direction in text format information for this days weather.
125 * @param _windDirectionDegrees [String], String representing the wind direction in degrees information for this days weather.
126 * @param _windSpeed [String], String representing the wind speed information for this days weather.
127 * @param _dayTemperature [String], String representing the day temperature information for this days weather.
128 * @param _eveningTemperature [String], String representing the evening temperature information for this days weather.
129 * @param _morningTemperature [String], String representing the morning temperature information for this days weather.
130 * @param _nighttemperature [String], String representing the night temperature information for this days weather.
131 * @param _maxTemperature [String], String representing the max temperature information for this days weather.
132 * @param _minTemperature [String], String representing the min temperature information for this days weather.
133 * @param _pressure [String], String representing the pressure information for this days weather.
134 * @param _humidity [String], String representing the humidity percentage information for this days weather.
135 * @param _cloudPercentage [String], String representing the cloud coverage percentage information for this days weather.
138 public DayWeather(String _date,
139 String _weatherCondition,
140 String _windDirection,
141 String _windDirectionDegrees,
143 String _dayTemperature,
144 String _eveningTemperature,
145 String _morningTemperature,
146 String _nighttemperature,
147 String _maxTemperature,
148 String _minTemperature,
151 String _cloudPercentage) {
153 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
155 date = formatter.parse(_date);
156 } catch (ParseException e) {
160 weatherCondition = getWeatherConditionForCode(Integer.parseInt(_weatherCondition));
163 windDirection = _windDirection;
164 windDirectionDegrees = Integer.parseInt(_windDirectionDegrees);
165 windSpeed = Float.parseFloat(_windSpeed);
167 // Temperature Information
168 dayTemperature = Float.parseFloat(_dayTemperature);
169 eveningTemperature = Float.parseFloat(_eveningTemperature);
170 morningTemperature = Float.parseFloat(_morningTemperature);
171 nightTemperature = Float.parseFloat(_nighttemperature);
172 maxTemperature = Float.parseFloat(_maxTemperature);
173 minTemperature = Float.parseFloat(_minTemperature);
176 pressure = Float.parseFloat(_pressure);
177 humidity = Float.parseFloat(_humidity);
178 cloudPercentage = Float.parseFloat(_cloudPercentage);
182 /** Method to get the date for this weather object.
184 * @return [Date] Date and time for this weather object.
186 public Date getDate() {
191 /** Method to get the wind direction text (N,NE,S,EXT).
193 * @return [String] Wind direction in compass text.
195 public String getWindDirection() {
196 return windDirection;
200 /** Method to get the wind direction in degrees.
202 * @return [int] Wind direction in degrees.
204 public int getWindDirectionDegrees() {
205 return windDirectionDegrees;
209 /** Method to get the wind speed in miles per hour.
211 * @return [float] Wind speed in miles per hour.
213 public float getWindSpeed() {
218 /** Method to get the temperature during the day.
220 * @return [float] Temperature in degrees F.
222 public float getDayTemperature() {
223 return dayTemperature;
226 /** Method to get the temperature during the evening.
228 * @return [float] Temperature in degrees F.
230 public float getEveningTemperature() {
231 return eveningTemperature;
235 /** Method to get the temperature during the morning.
237 * @return [float] Temperature in degrees F.
239 public float getMorningTemperature() {
240 return morningTemperature;
244 /** Method to get the temperature during the night.
246 * @return [float] Temperature in degrees F.
248 public float getNighttemperature() {
249 return nightTemperature;
253 /** Method to get the max temperature.
255 * @return [float] Temperature in degrees F.
257 public float getMaxTemperature() {
258 return maxTemperature;
262 /** Method to get the min temperature.
264 * @return [float] Temperature in degrees F.
266 public float getMinTemperature() {
267 return minTemperature;
271 /** Method to get the pressure.
273 * @return [float] Pressure in hPa.
275 public float getPressure() {
280 /** Method to get the humidity.
282 * @return [float] Humidity percentage.
284 public float getHumidity() {
289 /** Method to get the cloud coverage percentage.
291 * @return [float] Cloud coverage percentage.
293 public float getCloudPercentage() {
294 return cloudPercentage;
298 /** Method to check if this day is a wet day such as rain or something
300 * @return [float] Cloud coverage percentage.
302 public boolean getIsWetDay() {
303 if ((weatherCondition == WeatherConditions.THUNDERSTORM_WITH_LIGHT_RAIN) ||
304 (weatherCondition == WeatherConditions.THUNDERSTORM_WITH_RAIN) ||
305 (weatherCondition == WeatherConditions.THUNDERSTORM_WITH_HEAVY_RAIN) ||
306 (weatherCondition == WeatherConditions.LIGHT_THUNDERSTORM) ||
307 (weatherCondition == WeatherConditions.THUNDERSTORM) ||
308 (weatherCondition == WeatherConditions.HEAVY_THUNDERSTORM) ||
309 (weatherCondition == WeatherConditions.RAGGED_THUNDERSTORM) ||
310 (weatherCondition == WeatherConditions.THUNDERSTORM_WITH_LIGHT_DRIZZLE) ||
311 (weatherCondition == WeatherConditions.THUNDERSTORM_WITH_DRIZZLE) ||
312 (weatherCondition == WeatherConditions.THUNDERSTORM_WITH_HEAVY_DRIZZLE) ||
313 (weatherCondition == WeatherConditions.LIGHT_INTENSITY_DRIZZLE) ||
314 (weatherCondition == WeatherConditions.DRIZZLE) ||
315 (weatherCondition == WeatherConditions.HEAVY_INTENSITY_DRIZZLE) ||
316 (weatherCondition == WeatherConditions.LIGHT_INTENSITY_DRIZZLE_RAIN) ||
317 (weatherCondition == WeatherConditions.DRIZZLE_RAIN) ||
318 (weatherCondition == WeatherConditions.HEAVY_INTENSITY_DRIZZLE_RAIN) ||
319 (weatherCondition == WeatherConditions.SHOWER_RAIN_AND_DRIZZLE) ||
320 (weatherCondition == WeatherConditions.HEAVY_SHOWER_RAIN_AND_DRIZZLE) ||
321 (weatherCondition == WeatherConditions.SHOWER_DRIZZLE) ||
322 (weatherCondition == WeatherConditions.LIGHT_RAIN) ||
323 (weatherCondition == WeatherConditions.MODERATE_RAIN) ||
324 (weatherCondition == WeatherConditions.HEAVY_INTENSITY_RAIN) ||
325 (weatherCondition == WeatherConditions.VERY_HEAVY_RAIN) ||
326 (weatherCondition == WeatherConditions.EXTREME_RAIN) ||
327 (weatherCondition == WeatherConditions.FREEZING_RAIN) ||
328 (weatherCondition == WeatherConditions.LIGHT_INTENSITY_SHOWER_RAIN) ||
329 (weatherCondition == WeatherConditions.SHOWER_RAIN) ||
330 (weatherCondition == WeatherConditions.HEAVY_INTENSITY_SHOWER_RAIN) ||
331 (weatherCondition == WeatherConditions.RAGGED_SHOWER_RAIN) ||
332 (weatherCondition == WeatherConditions.SHOWER_SLEET) ||
333 (weatherCondition == WeatherConditions.LIGHT_RAIN_AND_SNOW) ||
334 (weatherCondition == WeatherConditions.RAIN_AND_SNOW) ||
335 (weatherCondition == WeatherConditions.LIGHT_SHOWER_SNOW) ||
336 (weatherCondition == WeatherConditions.SHOWER_SNOW) ||
337 (weatherCondition == WeatherConditions.HEAVY_SHOWER_SNOW) ||
338 (weatherCondition == WeatherConditions.TORNADO) ||
339 (weatherCondition == WeatherConditions.TROPICAL_STORM) ||
340 (weatherCondition == WeatherConditions.WINDY) ||
341 (weatherCondition == WeatherConditions.HAIL) ||
342 (weatherCondition == WeatherConditions.STORM) ||
343 (weatherCondition == WeatherConditions.VIOLENT_STORM) ||
344 (weatherCondition == WeatherConditions.HURRICANE)) {
351 /** Method to get the string representation of this object.
353 * @return [String] String representation of this object.
355 public String toString() {
356 String retString = "";
357 SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
358 retString += "Forcast for day: " + df.format(date) + "\n";
359 retString += "\t" + "Weather Condition:" + "\n";
360 retString += "\t\t" + "Weather Condition: " + getStringforWeatherCondition(weatherCondition) + "\n";
362 // Wind information to string
363 retString += "\t" + "Wind Information:" + "\n";
364 retString += "\t\t" + "Wind Direction (Text) : " + windDirection + "\n";
365 retString += "\t\t" + "Wind Direction (Degrees): " + Integer.toString(windDirectionDegrees) + "\n";
366 retString += "\t\t" + "Wind Speed (mph) : " + Float.toString(windSpeed) + "\n";
368 // Temperature information to string
369 retString += "\t" + "Temperature Information:" + "\n";
370 retString += "\t\t" + "Day Temperature (Degrees F) : " + Float.toString(dayTemperature) + "\n";
371 retString += "\t\t" + "Evening Temperature (Degrees F) : " + Float.toString(eveningTemperature) + "\n";
372 retString += "\t\t" + "Morning Temperature (Degrees F) : " + Float.toString(morningTemperature) + "\n";
373 retString += "\t\t" + "Night Temperature (Degrees F) : " + Float.toString(nightTemperature) + "\n";
374 retString += "\t\t" + "Max Temperature (Degrees F) : " + Float.toString(maxTemperature) + "\n";
375 retString += "\t\t" + "Min Temperature (Degrees F) : " + Float.toString(minTemperature) + "\n";
377 // Other information to string
378 retString += "\t" + "Other Information:" + "\n";
379 retString += "\t\t" + "Pressure (hPa) : " + Float.toString(pressure) + "\n";
380 retString += "\t\t" + "Humidity (Percentage) : " + Float.toString(humidity) + "\n";
381 retString += "\t\t" + "Cloud Coverage (Percentage) : " + Float.toString(cloudPercentage) + "\n";
388 /*******************************************************************************************************************************************
392 *******************************************************************************************************************************************/
394 /** Method get the string representation of the weather condition for display.
396 * @param cond [WeatherConditions], weather condition code.
398 * @return [String] String representation of the weather condition.
400 private String getStringforWeatherCondition(WeatherConditions cond) {
402 case THUNDERSTORM_WITH_LIGHT_RAIN:
403 return "THUNDERSTORM_WITH_LIGHT_RAIN";
405 case THUNDERSTORM_WITH_RAIN:
406 return "THUNDERSTORM_WITH_RAIN";
408 case THUNDERSTORM_WITH_HEAVY_RAIN:
409 return "THUNDERSTORM_WITH_HEAVY_RAIN";
411 case LIGHT_THUNDERSTORM:
412 return "LIGHT_THUNDERSTORM";
415 return "THUNDERSTORM";
417 case HEAVY_THUNDERSTORM:
418 return "HEAVY_THUNDERSTORM";
420 case RAGGED_THUNDERSTORM:
421 return "RAGGED_THUNDERSTORM";
423 case THUNDERSTORM_WITH_LIGHT_DRIZZLE:
424 return "THUNDERSTORM_WITH_LIGHT_DRIZZLE";
426 case THUNDERSTORM_WITH_DRIZZLE:
427 return "THUNDERSTORM_WITH_DRIZZLE";
429 case THUNDERSTORM_WITH_HEAVY_DRIZZLE:
430 return "THUNDERSTORM_WITH_HEAVY_DRIZZLE";
432 case LIGHT_INTENSITY_DRIZZLE:
433 return "LIGHT_INTENSITY_DRIZZLE";
438 case HEAVY_INTENSITY_DRIZZLE:
439 return "HEAVY_INTENSITY_DRIZZLE";
441 case LIGHT_INTENSITY_DRIZZLE_RAIN:
442 return "LIGHT_INTENSITY_DRIZZLE_RAIN";
445 return "DRIZZLE_RAIN";
447 case HEAVY_INTENSITY_DRIZZLE_RAIN:
448 return "HEAVY_INTENSITY_DRIZZLE_RAIN";
450 case SHOWER_RAIN_AND_DRIZZLE:
451 return "SHOWER_RAIN_AND_DRIZZLE";
453 case HEAVY_SHOWER_RAIN_AND_DRIZZLE:
454 return "HEAVY_SHOWER_RAIN_AND_DRIZZLE";
457 return "SHOWER_DRIZZLE";
463 return "MODERATE_RAIN";
465 case HEAVY_INTENSITY_RAIN:
466 return "HEAVY_INTENSITY_RAIN";
468 case VERY_HEAVY_RAIN:
469 return "VERY_HEAVY_RAIN";
472 return "EXTREME_RAIN";
475 return "FREEZING_RAIN";
477 case LIGHT_INTENSITY_SHOWER_RAIN:
478 return "LIGHT_INTENSITY_SHOWER_RAIN";
481 return "SHOWER_RAIN";
483 case HEAVY_INTENSITY_SHOWER_RAIN:
484 return "HEAVY_INTENSITY_SHOWER_RAIN";
486 case RAGGED_SHOWER_RAIN:
487 return "RAGGED_SHOWER_RAIN";
502 return "SHOWER_SLEET";
504 case LIGHT_RAIN_AND_SNOW:
505 return "LIGHT_RAIN_AND_SNOW";
508 return "RAIN_AND_SNOW";
510 case LIGHT_SHOWER_SNOW:
511 return "LIGHT_SHOWER_SNOW";
514 return "SHOWER_SNOW";
516 case HEAVY_SHOWER_SNOW:
517 return "HEAVY_SHOWER_SNOW";
528 case SAND_DUST_WHIRLS:
529 return "SAND_DUST_WHIRLS";
541 return "VOLCANIC_ASH";
555 case SCATTERED_CLOUDS:
556 return "SCATTERED_CLOUDS";
559 return "BROKEN_CLOUDS";
561 case OVERCAST_CLOUDS:
562 return "OVERCAST_CLOUDS";
565 return "TROPICAL_STORM";
586 return "LIGHT_BREEZE";
589 return "GENTLE_BREEZE";
591 case MODERATE_BREEZE:
592 return "MODERATE_BREEZE";
595 return "FRESH_BREEZE";
598 return "STRONG_BREEZE";
600 case HIGH_WIND_NEAR_GALE:
601 return "HIGH_WIND_NEAR_GALE";
607 return "SEVERE_GALE";
613 return "VIOLENT_STORM";
621 /** Method to change the weather condition code into a WeatherConditions enum type
623 * @param cond [int], weather condition code.
625 * @return [WeatherConditions] weather conditions enum type.
627 private WeatherConditions getWeatherConditionForCode(int code) {
630 return WeatherConditions.THUNDERSTORM_WITH_LIGHT_RAIN;
633 return WeatherConditions.THUNDERSTORM_WITH_RAIN;
636 return WeatherConditions.THUNDERSTORM_WITH_HEAVY_RAIN;
639 return WeatherConditions.LIGHT_THUNDERSTORM;
642 return WeatherConditions.THUNDERSTORM;
645 return WeatherConditions.HEAVY_THUNDERSTORM;
648 return WeatherConditions.RAGGED_THUNDERSTORM;
651 return WeatherConditions.THUNDERSTORM_WITH_LIGHT_DRIZZLE;
654 return WeatherConditions.THUNDERSTORM_WITH_DRIZZLE;
657 return WeatherConditions.THUNDERSTORM_WITH_HEAVY_DRIZZLE;
660 return WeatherConditions.LIGHT_INTENSITY_DRIZZLE;
663 return WeatherConditions.DRIZZLE;
666 return WeatherConditions.HEAVY_INTENSITY_DRIZZLE;
669 return WeatherConditions.LIGHT_INTENSITY_DRIZZLE_RAIN;
672 return WeatherConditions.DRIZZLE_RAIN;
675 return WeatherConditions.HEAVY_INTENSITY_DRIZZLE_RAIN;
678 return WeatherConditions.SHOWER_RAIN_AND_DRIZZLE;
681 return WeatherConditions.HEAVY_SHOWER_RAIN_AND_DRIZZLE;
684 return WeatherConditions.SHOWER_DRIZZLE;
687 return WeatherConditions.LIGHT_RAIN;
690 return WeatherConditions.MODERATE_RAIN;
693 return WeatherConditions.HEAVY_INTENSITY_RAIN;
696 return WeatherConditions.VERY_HEAVY_RAIN;
699 return WeatherConditions.EXTREME_RAIN;
702 return WeatherConditions.FREEZING_RAIN;
705 return WeatherConditions.LIGHT_INTENSITY_SHOWER_RAIN;
708 return WeatherConditions.SHOWER_RAIN;
711 return WeatherConditions.HEAVY_INTENSITY_SHOWER_RAIN;
714 return WeatherConditions.RAGGED_SHOWER_RAIN;
717 return WeatherConditions.LIGHT_SNOW;
720 return WeatherConditions.SNOW;
723 return WeatherConditions.HEAVY_SNOW;
726 return WeatherConditions.SLEET;
729 return WeatherConditions.SHOWER_SLEET;
732 return WeatherConditions.LIGHT_RAIN_AND_SNOW;
735 return WeatherConditions.RAIN_AND_SNOW;
738 return WeatherConditions.LIGHT_SHOWER_SNOW;
741 return WeatherConditions.SHOWER_SNOW;
744 return WeatherConditions.HEAVY_SHOWER_SNOW;
747 return WeatherConditions.MIST;
750 return WeatherConditions.SMOKE;
753 return WeatherConditions.HAZE;
756 return WeatherConditions.SAND_DUST_WHIRLS;
759 return WeatherConditions.FOG;
762 return WeatherConditions.SAND;
765 return WeatherConditions.DUST;
768 return WeatherConditions.VOLCANIC_ASH;
771 return WeatherConditions.SQUALLS;
774 return WeatherConditions.TORNADO;
777 return WeatherConditions.CLEAR_SKY;
780 return WeatherConditions.FEW_CLOUDS;
783 return WeatherConditions.SCATTERED_CLOUDS;
786 return WeatherConditions.BROKEN_CLOUDS;
789 return WeatherConditions.OVERCAST_CLOUDS;
792 return WeatherConditions.TORNADO;
795 return WeatherConditions.TROPICAL_STORM;
798 return WeatherConditions.HURRICANE;
801 return WeatherConditions.COLD;
804 return WeatherConditions.HOT;
807 return WeatherConditions.WINDY;
810 return WeatherConditions.HAIL;
813 return WeatherConditions.CALM;
816 return WeatherConditions.LIGHT_BREEZE;
819 return WeatherConditions.GENTLE_BREEZE;
822 return WeatherConditions.MODERATE_BREEZE;
825 return WeatherConditions.FRESH_BREEZE;
828 return WeatherConditions.STRONG_BREEZE;
831 return WeatherConditions.HIGH_WIND_NEAR_GALE;
834 return WeatherConditions.GALE;
837 return WeatherConditions.SEVERE_GALE;
840 return WeatherConditions.STORM;
843 return WeatherConditions.VIOLENT_STORM;
846 return WeatherConditions.HURRICANE;
849 return WeatherConditions.UNKNOWN;