Author SHA1 Message Date
handte 3eced06154 Release 1.0.12.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 00:12:05 +01:00
handte 894b24a4ff Properly handle predictions that are not updated.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-13 23:51:49 +01:00
2 changed files with 64 additions and 49 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ allprojects {
// set version for our project
group = 'com.mowesta'
version = '1.0.12-SNAPSHOT'
version = '1.0.12'
// set versions for our libraries
ext {
@@ -40,32 +40,32 @@ import com.mowesta.service.session.sync.WeatherVideoSyncSessionBean;
/**
* The session bean that handles weather reports.
*
*
* @author Marcus
*/
@Stateless
public class WeatherSessionBean extends AbstractPrincipalSessionBean {
/**
* The maximum age of weather reports included in weather conditions.
*/
private static final long MAX_REPORT_AGE = 60*60*1000;
/**
* The infinispan session bean.
*/
@Inject
private InfinispanSessionBean infinispanSession;
/**
* The session bean to access video metadata.
*/
@Inject
private WeatherVideoSyncSessionBean videoSession;
/**
* Returns the best and longest forecast for a given coordinate.
*
*
* @param location The coordinate.
* @return The best forecast for the coordinate or null, if there is none.
*/
@@ -74,11 +74,22 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
public WeatherForecast getForecast(Coordinate location) {
SearchManager manager = Search.getSearchManager(infinispanSession.getDataCache());
List<WeatherForecastContainer> containers = WeatherForecastContainer.findByLocation(manager, location, 10);
// compute the map of forecasts
// compute the map of forecasts (distance is considered since list is ordered)
Map<WeatherSource, WeatherForecast> forecasts = new HashMap<>();
for (int i = containers.size() - 1; i >= 0; i--) {
forecasts.put(containers.get(i).getSource(), containers.get(i).getForecast());
}
// find the most recent prediction time from all sources
long threshold = 0;
for (WeatherForecast forecast: forecasts.values()) {
if (forecast.getConditions().size() > 0) {
long time = forecast.getConditions().get(0).getTime();
for (int i = 1, s = forecast.getConditions().size(); i < s; i++) {
time = Math.min(forecast.getConditions().get(i).getTime(), time);
}
threshold = Math.max(threshold, time);
}
}
// compute the set of "best" conditions from all sources
Map<Long, WeatherCondition> conditions = new HashMap<>();
WeatherForecast result = null;
@@ -88,7 +99,11 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
if (next != null) {
result = next;
for (WeatherCondition c: next.getConditions()) {
conditions.put(c.getTime(), c);
// only keep data that is fresher than the latest
// prediction, in case some prediction is not updated
if (c.getTime() >= threshold) {
conditions.put(c.getTime(), c);
}
}
}
}
@@ -103,22 +118,22 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
/**
* Returns the forecast with the specified id.
*
*
* @param id The id of the forecast.
* @return The forecast with the id or null, if the id is invalid.
*/
@PermitAll
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public WeatherForecast getForecast(long id){
WeatherForecastContainer container = (WeatherForecastContainer)infinispanSession.getDataCache().get(id);
WeatherForecastContainer container = infinispanSession.getDataCache().get(id);
if (container == null) return null;
else return container.getForecast();
}
/**
* Returns a page of weather stations that match the term. If the
* Returns a page of weather stations that match the term. If the
* term is null or the empty string, all stations will be returned.
*
*
* @param term The search term.
* @param config The page config.
* @param filtered True to filter deleted.
@@ -138,10 +153,10 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
page.setTotal(count);
return page;
}
/**
* Returns the weather station with the specified id.
*
*
* @param id The id of the station.
* @return The weather station.
* @throws EntityNotFoundException
@@ -151,10 +166,10 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
WeatherStationEntity station = getStationEntity(id);
return Convert.with(WeatherStationConverter.class).apply(station, false);
}
/**
* Returns the weather station entity with the specified id.
*
*
* @param id The id to search.
* @return The entity.
* @throws EntityNotFoundException Thrown if not found.
@@ -165,20 +180,20 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
throw new EntityNotFoundException(WeatherStationEntity.class, id);
return station;
}
/**
* Returns the last modification date over all stations.
*
*
* @return The last modification date over all stations.
*/
@PermitAll
public long getLastModifiedStation() {
return AbstractEntity.getLastModified(em, WeatherStationEntity.class);
}
/**
* Returns the last modification time stamp for the station.
*
*
* @param id The station id.
* @return The last modification time stamp.
* @throws EntityNotFoundException Thrown if the entity does not exist.
@@ -188,10 +203,10 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
WeatherStationEntity station = getStationEntity(id);
return WeatherReportEntity.getLastModifiedForStation(em, station);
}
/**
* Returns a report page for a specific station and time range.
*
*
* @param id The station id.
* @param range The time range.
* @param config The page configuration.
@@ -214,10 +229,10 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
}
return page;
}
/**
* Returns the latest report from the station.
*
*
* @param id The id of the station.
* @param filtered True to filter deleted.
* @return The weather report.
@@ -228,10 +243,10 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
WeatherStationEntity station = getStationEntity(id);
return Convert.with(WeatherReportConverter.class).apply(getLatestReportEntity(station, filtered), filtered);
}
/**
* Returns the latest report from the station.
*
*
* @param station The weather station.
* @param filtered True to filter deleted, false otherwise.
* @return The weather report.
@@ -241,12 +256,12 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
if (time == 0) return null;
else return WeatherReportEntity.findByTime(em, station, time);
}
/**
* Returns the nearest weather station for the coordinate or
* null, if there is no nearby station.
*
*
* @param coordinate The coordinate.
* @param filtered True to filter deleted.
* @return The weather station.
@@ -255,10 +270,10 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
public WeatherStation getStation(Coordinate coordinate, boolean filtered) {
return Convert.with(WeatherStationConverter.class).apply(getStationEntity(coordinate, filtered), filtered);
}
/**
* Returns the closest station to the entity.
*
*
* @param coordinate The coordinate.
* @param filtered True to filter deleted.
* @return The station entity.
@@ -270,13 +285,13 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
}
return null;
}
/**
* Returns the weather conditions for the coordinate.
*
*
* @param coordinate The coordinate.
*
*
* @return The weather condition or null.
*/
@PermitAll
@@ -307,32 +322,32 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
}
return result;
}
/**
* Returns the last modification timestamp of the weather video metadata.
*
*
* @return The last modification timestamp.
*/
@PermitAll
public long getLastModifiedVideo() {
return videoSession.getMetadata().getModificationTime();
}
/**
* Returns a page of all videos.
*
*
* @param config The page config.
* @return The video page.
*/
@PermitAll
public WeatherVideoPage getVideos(PageConfig config) {
return getVideoPage(videoSession.getMetadata().getVideos(false), config);
}
/**
* Returns a page of videos that are relevant for the coordinate.
*
*
* @param c The coordinate.
* @param config The page config.
* @return The video page.
@@ -341,10 +356,10 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
public WeatherVideoPage getVideos(Coordinate c, PageConfig config) {
return getVideoPage(videoSession.getMetadata().getVideos(c, false), config);
}
/**
* Creates a page of videos using the list of videos and the page config.
*
*
* @param videos The videos to select from.
* @param config The page configuration.
* @return The video page with contents from the list as defined by the config.
@@ -363,7 +378,7 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
/**
* Returns only the latest videos.
*
*
* @return The latest videos.
*/
@PermitAll
@@ -373,7 +388,7 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
/**
* Returns the latest videos for the coordinate.
*
*
* @param c The coordinate.
* @return The list of latest videos for the coordinate.
*/
@@ -381,6 +396,6 @@ public class WeatherSessionBean extends AbstractPrincipalSessionBean {
public List<WeatherVideo> getLatestVideos(Coordinate c) {
return videoSession.getMetadata().getVideos(c, true);
}
}