Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new key for TripDataHistoryCache based on route, direction and start time. #255

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,24 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.lang3.time.DateUtils;

import org.transitclock.applications.Core;
import org.transitclock.config.BooleanConfigValue;
import org.transitclock.config.IntegerConfigValue;
import org.transitclock.core.dataCache.PredictionComparator;
import org.transitclock.core.dataCache.PredictionDataCache;
import org.transitclock.core.dataCache.StopArrivalDepartureCacheFactory;
import org.transitclock.core.dataCache.StopArrivalDepartureCacheKey;
import org.transitclock.core.dataCache.TripDataHistoryCacheFactory;
import org.transitclock.core.dataCache.TripDataHistoryCacheInterface;
import org.transitclock.core.dataCache.TripKey;
import org.transitclock.core.dataCache.ehcache.StopArrivalDepartureCache;
import org.transitclock.core.dataCache.ehcache.scheduled.TripDataHistoryCache;
import org.transitclock.core.predictiongenerator.datafilter.DwellTimeDataFilter;
import org.transitclock.core.predictiongenerator.datafilter.DwellTimeFilterFactory;
import org.transitclock.core.dataCache.keys.StopArrivalDepartureCacheKey;
import org.transitclock.core.dataCache.keys.byroute.TripKey;
import org.transitclock.core.predictiongenerator.datafilter.TravelTimeDataFilter;
import org.transitclock.core.predictiongenerator.datafilter.TravelTimeFilterFactory;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.db.structs.AvlReport;
import org.transitclock.db.structs.Block;
import org.transitclock.db.structs.PredictionEvent;
import org.transitclock.db.structs.Trip;
import org.transitclock.gtfs.DbConfig;
import org.transitclock.ipc.data.IpcArrivalDeparture;
import org.transitclock.ipc.data.IpcPrediction;
import org.transitclock.ipc.data.IpcPredictionsForRouteStopDest;
import org.transitclock.utils.Time;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -262,7 +250,7 @@ Integer numAfter(List<String> stops, String stop1, String stop2) {
}


protected List<TravelTimeDetails> lastDaysTimes(TripDataHistoryCacheInterface cache, String tripId,String direction, int stopPathIndex, Date startDate,
protected List<TravelTimeDetails> lastDaysTimes(TripDataHistoryCacheInterface cache, Indices indicies, String tripId,String direction, int stopPathIndex, Date startDate,

Integer startTime, int num_days_look_back, int num_days) {

Expand All @@ -277,13 +265,16 @@ protected List<TravelTimeDetails> lastDaysTimes(TripDataHistoryCacheInterface ca
for (int i = 0; i < num_days_look_back && num_found < num_days; i++) {

Date nearestDay = DateUtils.truncate(DateUtils.addDays(startDate, (i + 1) * -1), Calendar.DAY_OF_MONTH);

TripKey tripKey = new TripKey(tripId, nearestDay, startTime);


TripKey tripKey = new TripKey(indicies.getRoute().getId(), indicies.getTrip().getDirectionId(), startTime, nearestDay);

logger.debug("Looking for cache entry in TripDataHistoryCache for {}.", tripKey);

results = cache.getTripHistory(tripKey);

if (results != null) {

logger.debug("Have cache entry in TripDataHistoryCache for {}.", tripKey);
IpcArrivalDeparture arrival = getArrival(stopPathIndex, results);

if(arrival!=null)
Expand All @@ -305,7 +296,11 @@ protected List<TravelTimeDetails> lastDaysTimes(TripDataHistoryCacheInterface ca
}
}
}
}else
{
logger.debug("No cache entry in TripDataHistoryCache for {}.", tripKey);
}

}
return times;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.transitclock.core.dataCache;

import org.transitclock.core.dataCache.keys.bytrip.StopPathCacheKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.db.structs.Headway;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.slf4j.Logger;
import org.transitclock.core.Indices;
import org.transitclock.core.dataCache.keys.bytrip.KalmanErrorCacheKey;

public interface ErrorCache {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.transitclock.core.dataCache.keys.StopArrivalDepartureCacheKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.ipc.data.IpcArrivalDeparture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.transitclock.core.Indices;
import org.transitclock.core.dataCache.keys.bytrip.StopPathCacheKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.db.structs.PredictionForStopPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

import org.hibernate.Session;
import org.slf4j.Logger;
import org.transitclock.core.dataCache.keys.byroute.TripKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.ipc.data.IpcArrivalDeparture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.transitclock.core.Indices;
import org.transitclock.core.dataCache.ErrorCache;
import org.transitclock.core.dataCache.KalmanError;
import org.transitclock.core.dataCache.KalmanErrorCacheKey;
import org.transitclock.core.dataCache.keys.bytrip.KalmanErrorCacheKey;
/**
* @author Sean Óg Crudden
*
Expand Down Expand Up @@ -102,7 +102,7 @@ public void putErrorValue(KalmanErrorCacheKey key, Double value) {
error.setError(value);
}


logger.debug("Putting error value {} for key {}.",value, key);
cache.put(key,error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import org.transitclock.core.dataCache.ArrivalDepartureComparator;
import org.transitclock.core.dataCache.DwellTimeModelCacheFactory;
import org.transitclock.core.dataCache.IpcArrivalDepartureComparator;
import org.transitclock.core.dataCache.KalmanErrorCacheKey;
import org.transitclock.core.dataCache.StopArrivalDepartureCacheFactory;
import org.transitclock.core.dataCache.StopArrivalDepartureCacheInterface;
import org.transitclock.core.dataCache.StopArrivalDepartureCacheKey;
import org.transitclock.core.dataCache.StopEvents;
import org.transitclock.core.dataCache.TripEvents;
import org.transitclock.core.dataCache.TripKey;
import org.transitclock.core.dataCache.keys.StopArrivalDepartureCacheKey;
import org.transitclock.core.dataCache.keys.bytrip.KalmanErrorCacheKey;
import org.transitclock.core.dataCache.keys.bytrip.TripKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.ipc.data.IpcArrivalDeparture;
import org.transitclock.utils.Time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import org.transitclock.core.dataCache.TripDataHistoryCacheFactory;
import org.transitclock.core.dataCache.TripDataHistoryCacheInterface;
import org.transitclock.core.dataCache.TripEvents;
import org.transitclock.core.dataCache.TripKey;
import org.transitclock.core.dataCache.ehcache.CacheManagerFactory;
import org.transitclock.core.dataCache.frequency.FrequencyBasedHistoricalAverageCache;
import org.transitclock.core.dataCache.keys.byroute.TripKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.db.structs.Block;
import org.transitclock.db.structs.Trip;
Expand Down Expand Up @@ -164,10 +164,9 @@ synchronized public TripKey putArrivalDeparture(ArrivalDeparture arrivalDepartur
time=FrequencyBasedHistoricalAverageCache.round(time, FrequencyBasedHistoricalAverageCache.getCacheIncrementsForFrequencyService());

if(trip!=null)
{
tripKey = new TripKey(arrivalDeparture.getTripId(),
nearestDay,
time);
{

tripKey=new TripKey(arrivalDeparture.getRouteId(), trip.getDirectionId(), time, nearestDay);

logger.debug("Putting :{} in TripDataHistoryCache cache using key {}.", arrivalDeparture, tripKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.transitclock.config.IntegerConfigValue;
import org.transitclock.config.LongConfigValue;
import org.transitclock.core.dataCache.StopArrivalDepartureCacheFactory;
import org.transitclock.core.dataCache.StopArrivalDepartureCacheKey;
import org.transitclock.core.dataCache.StopPathCacheKey;
import org.transitclock.core.dataCache.ehcache.CacheManagerFactory;
import org.transitclock.core.dataCache.keys.StopArrivalDepartureCacheKey;
import org.transitclock.core.dataCache.keys.bytrip.StopPathCacheKey;
import org.transitclock.core.predictiongenerator.scheduled.dwell.DwellTimeModelFactory;
import org.transitclock.core.predictiongenerator.scheduled.dwell.DwellModel;
import org.transitclock.db.structs.ArrivalDeparture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
import java.util.Collections;
import java.util.Date;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.ehcache.Cache;
import org.ehcache.CacheManager;

import org.ehcache.Status;
import org.ehcache.config.builders.CacheManagerBuilder;

import org.ehcache.xml.XmlConfiguration;
import org.apache.commons.lang3.time.DateUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
Expand All @@ -29,8 +24,8 @@
import org.transitclock.core.dataCache.TripDataHistoryCacheFactory;
import org.transitclock.core.dataCache.TripDataHistoryCacheInterface;
import org.transitclock.core.dataCache.TripEvents;
import org.transitclock.core.dataCache.TripKey;
import org.transitclock.core.dataCache.ehcache.CacheManagerFactory;
import org.transitclock.core.dataCache.keys.byroute.TripKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.db.structs.Trip;
import org.transitclock.gtfs.DbConfig;
Expand All @@ -46,7 +41,7 @@
* filter.
*
*/
public class TripDataHistoryCache implements TripDataHistoryCacheInterface{
public class TripDataHistoryCache implements TripDataHistoryCacheInterface {
private static TripDataHistoryCacheInterface singleton = new TripDataHistoryCache();

private static boolean debug = false;
Expand Down Expand Up @@ -129,10 +124,8 @@ synchronized public TripKey putArrivalDeparture(ArrivalDeparture arrivalDepartur

if(trip!=null)
{

tripKey = new TripKey(arrivalDeparture.getTripId(),
nearestDay,
trip.getStartTime());

tripKey=new TripKey(arrivalDeparture.getRouteId(), trip.getDirectionId(), trip.getStartTime(), nearestDay);

TripEvents result = (TripEvents) cache.get(tripKey);

Expand All @@ -147,7 +140,8 @@ synchronized public TripKey putArrivalDeparture(ArrivalDeparture arrivalDepartur
logger.error("Error adding "+arrivalDeparture.toString()+" event to TripDataHistoryCache.", e);

}

logger.debug("Adding to TripDataHistoryCache {} with key {}.",arrivalDeparture, tripKey);

cache.put(tripKey, result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.transitclock.core.VehicleState;
import org.transitclock.core.dataCache.*;
import org.transitclock.core.dataCache.ehcache.scheduled.TripDataHistoryCache;
import org.transitclock.core.dataCache.keys.bytrip.StopPathCacheKey;
import org.transitclock.core.dataCache.keys.byroute.TripKey;
import org.transitclock.db.structs.ArrivalDeparture;
import org.transitclock.db.structs.Trip;
import org.transitclock.gtfs.DbConfig;
Expand Down Expand Up @@ -248,9 +250,8 @@ public IpcArrivalDeparture findPreviousArrivalEvent(List<IpcArrivalDeparture> ar
private TravelTimeResult getLastPathDuration(IpcArrivalDeparture arrivalDeparture, Trip trip)
{
Date nearestDay = DateUtils.truncate(new Date(arrivalDeparture.getTime().getTime()), Calendar.DAY_OF_MONTH);
TripKey tripKey = new TripKey(arrivalDeparture.getTripId(),
nearestDay,
trip.getStartTime());

TripKey tripKey=new TripKey(arrivalDeparture.getRouteId(), trip.getDirectionId(), trip.getStartTime(), nearestDay);

List<IpcArrivalDeparture> arrivalDepartures=(List<IpcArrivalDeparture>) TripDataHistoryCacheFactory.getInstance().getTripHistory(tripKey);

Expand All @@ -271,9 +272,8 @@ private TravelTimeResult getLastPathDuration(IpcArrivalDeparture arrivalDepartur
private DwellTimeResult getLastStopDuration(IpcArrivalDeparture arrivalDeparture, Trip trip)
{
Date nearestDay = DateUtils.truncate(new Date(arrivalDeparture.getTime().getTime()), Calendar.DAY_OF_MONTH);
TripKey tripKey = new TripKey(arrivalDeparture.getTripId(),
nearestDay,
trip.getStartTime());

TripKey tripKey=new TripKey(arrivalDeparture.getRouteId(), trip.getDirectionId(), trip.getStartTime(), nearestDay);

List<IpcArrivalDeparture> arrivalDepartures=(List<IpcArrivalDeparture>) TripDataHistoryCacheFactory.getInstance().getTripHistory(tripKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Comparator;

import org.transitclock.core.dataCache.StopPathCacheKey;
import org.transitclock.core.dataCache.keys.bytrip.StopPathCacheKey;

public class StopPathCacheKeyStartTimeComparator implements Comparator<StopPathCacheKey>{

Expand Down

This file was deleted.

Loading