Weather (WeatherForecastPrediction prediction) { temperature = prediction.getTemperature(); windSpeed = prediction.getWindSpeed(); windDirection = prediction.getWindDirection(); cloudCover = prediction.getCloudCover(); }
WeatherForecastPrediction[] getForecastArray () { WeatherForecast forecast = weatherForecastRepo.currentWeatherForecast(); List<WeatherForecastPrediction> fcsts = forecast.getPredictions(); WeatherForecastPrediction[] result = new WeatherForecastPrediction[fcsts.size()]; fcsts.forEach(fcst -> result[fcst.getForecastTime() - 1] = fcst); return result; }
double[] smoothForecasts (double start, double threshold, double sign, WeatherForecastPrediction[] forecasts) { double[] result = new double[forecasts.length]; double last = start; for (int i = 0; i < forecasts.length; i += 1) { double next = forecasts[i].getTemperature() - threshold; if (Math.signum(next) != Math.signum(sign)) next = 0.0; last = tempAlpha * next + (1.0 - tempAlpha) * last; result[i] = last; } return result; }
@Override public Object unmarshal (HierarchicalStreamReader reader, UnmarshallingContext context) { String id = reader.getAttribute("id"); String temp = reader.getAttribute("temp"); String wind = reader.getAttribute("windspeed"); String dir = reader.getAttribute("winddir"); String cloudCvr = reader.getAttribute("cloudcover"); return new WeatherForecastPrediction(Integer.parseInt(id), Double.parseDouble(temp), Double.parseDouble(wind), Double.parseDouble(dir), Double.parseDouble(cloudCvr)); } }
List<WeatherForecastPrediction> predictions = forecast.getPredictions(); for (WeatherForecastPrediction prediction : predictions) { if (prediction.getForecastTime() == timeToFuture) { weather = new Weather(prediction);
new WeatherForecastPrediction( Integer.parseInt(temp[3]), Double.parseDouble(temp[4]), Double.parseDouble(temp[5]),
private void broadcastWeatherForecasts () { WeatherForecast forecast = null; try { forecast = weatherForecastRepo.currentWeatherForecast(); } catch (PowerTacException e) { log.error("Weather Service reports Weather Forecast Repo emtpy"); } if (forecast == null) { log.error("null weather-forecast for : " + timeslotRepo.currentSerialNumber() +" " + timeslotRepo.currentTimeslot()); // In the event of an error return a default List<WeatherForecastPrediction> currentPredictions = new ArrayList<WeatherForecastPrediction>(); for (int j = 1; j <= getForecastHorizon(); j++) { currentPredictions.add( new WeatherForecastPrediction(j, 0.0, 0.0, 0.0, 0.0)); } brokerProxyService.broadcastMessage(new WeatherForecast( timeslotRepo.currentSerialNumber(), currentPredictions)); } else { brokerProxyService.broadcastMessage(forecast); } }