Skip to content

Commit 495c45a

Browse files
committed
changing version pre MET-213 branch
Inspired by work done here: TheTransitClock#255 (comment) Needs bug fix MET-214
1 parent a5937cd commit 495c45a

File tree

25 files changed

+417
-256
lines changed

25 files changed

+417
-256
lines changed

transitclock/src/main/java/org/transitclock/applications/Core.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,12 @@ static private void populateCaches() throws Exception
480480
if(cacheReloadStartTimeStr.getValue().length()>0&&cacheReloadEndTimeStr.getValue().length()>0)
481481
{
482482
Criteria criteria = session.createCriteria(ArrivalDeparture.class);
483+
logger.info("querying from {} to {}", cacheReloadStartTimeStr, cacheReloadEndTimeStr);
484+
483485
List<ArrivalDeparture> results = StopArrivalDepartureCache.createArrivalDeparturesCriteriaMultiDay(criteria,
484486
new Date(Time.parse(cacheReloadStartTimeStr.getValue()).getTime()),
485487
new Date(Time.parse(cacheReloadEndTimeStr.getValue()).getTime()));
486-
488+
logger.info("query complete from {} to {}", cacheReloadStartTimeStr, cacheReloadEndTimeStr);
487489
if(TripDataHistoryCacheFactory.getInstance()!=null)
488490
{
489491
logger.info("Populating TripDataHistoryCache cache for period {} to {}",cacheReloadStartTimeStr.getValue(),cacheReloadEndTimeStr.getValue());

transitclock/src/main/java/org/transitclock/core/SpatialMatch.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,11 @@ public int getScheduledWaitStopTimeSecs() {
594594
logger.error("no scheduled wait stop time for {} {}", tripIndex, stopPathIndex);
595595
return -1;
596596
}
597+
if (scheduleTime.getDepartureTime() == null) {
598+
// timepoints dont have departure times by convention
599+
// this isn't an error
600+
return -1;
601+
}
597602
return scheduleTime.getDepartureTime();
598603
} catch (Exception e) {
599604
logger.error("Tried to get wait stop time for a stop that didn't "

transitclock/src/main/java/org/transitclock/core/TravelTimes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static int adjustTravelTimeForWaitStop(int timeOfDaySecs,
163163
/**
164164
* Returns the scheduled epoch time vehicle is scheduled leave a wait stop.
165165
* Does not take into account whether vehicle can make it to the wait stop
166-
* in time.
166+
* in time. A wait stop now includes timepoint stops.
167167
*
168168
* @param indices
169169
* Describes which stop
@@ -192,7 +192,9 @@ public static long scheduledDepartureTime(Indices indices,
192192
Integer scheduledDepartureTimeSecs =
193193
scheduleTime.getDepartureTime();
194194
if (scheduledDepartureTimeSecs == null) {
195-
logger.error("Called scheduledDepartureTimePlusWaitTime() for stop "
195+
// timepoints will not have departure time set via convention
196+
// this is not an error
197+
logger.debug("Called scheduledDepartureTimePlusWaitTime() for stop "
196198
+ "that doesn't have a scheduled departure time. {}",
197199
indices);
198200
return -1;

transitclock/src/main/java/org/transitclock/core/dataCache/CacheTask.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,39 @@ public String toString() {
5757

5858
@Override
5959
public void run() throws Exception {
60-
logger.error("in run for task with results=" + futureResults);
60+
logger.info("in run for task with results=" + futureResults);
6161
Session session = null;
6262
List<ArrivalDeparture> results = null;
6363
if (futureResults != null) {
6464
// block here until we have input ready
65-
logger.error("async retrieval of {} to {}", startDate, endDate);
65+
logger.info("async retrieval of {} to {}", startDate, endDate);
6666
try {
6767
results = (List<ArrivalDeparture>) futureResults.get();
6868
} catch (Throwable t) {
6969
// this will catch any hydration issues in the future query
7070
logger.error("futureResult retrieval failed with {}", t, t);
7171
}
7272
if (results == null) {
73-
logger.error("async retrieval of {} to {} failed!", startDate, endDate);
73+
logger.info("async retrieval of {} to {} failed!", startDate, endDate);
7474
} else {
75-
logger.error("async retrieval of {} to {} finished with {} results", startDate, endDate, results.size());
75+
logger.info("async retrieval of {} to {} finished with {} results", startDate, endDate, results.size());
7676
}
7777
}
7878
try {
7979
if (this.futureResults == null) {
8080
session = HibernateUtils.getSession();
8181
Criteria criteria = session.createCriteria(ArrivalDeparture.class);
82-
logger.error("async / future results null, performing manual retrieval now");
82+
logger.info("async / future results null, performing manual retrieval now");
8383
results = criteria.add(Restrictions.between("time", startDate, endDate)).list();
8484
}
8585

8686
logger.info("Populating {} cache for period {} to {}", type, startDate, endDate);
8787
switch (type) {
8888
case TripDataHistoryCacheFactory:
8989
if (results != null) {
90-
logger.error("populating TripDataHistoryCache with " + results.size() + "records");
90+
logger.info("populating TripDataHistoryCache with " + results.size() + "records");
9191
} else {
92-
logger.error("populating TripDataHistoryCache with NuLl records");
92+
logger.info("populating TripDataHistoryCache with NuLl records");
9393
}
9494
TripDataHistoryCacheFactory.getInstance().populateCacheFromDb(results);
9595
break;
@@ -117,7 +117,7 @@ public void run() throws Exception {
117117
} catch (Throwable t) {
118118
logger.error("Error Populating {} cache for period {} to {}, {}", type, startDate, endDate, t, t);
119119
} finally {
120-
logger.error("Finished Populating {} cache for period {} to {}", type, startDate, endDate);
120+
logger.info("Finished Populating {} cache for period {} to {}", type, startDate, endDate);
121121
if (session != null) {
122122
// this session is in a separate thread and needs to be reclaimed
123123
// as it counts against the connection pool

transitclock/src/main/java/org/transitclock/core/dataCache/KalmanErrorCacheKey.java

Lines changed: 86 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,100 @@
11
package org.transitclock.core.dataCache;
22

33
import org.transitclock.core.Indices;
4+
import org.transitclock.db.structs.Trip;
45

56
/**
67
* @author Sean Og Crudden
78
* TODO This is the same as StopPathCacheKey but left seperate in case we might use block_id as well.
89
*/
910
public class KalmanErrorCacheKey implements java.io.Serializable {
1011

12+
13+
private String routeId;
14+
private String directionId;
15+
private Integer startTimeSecondsIntoDay;
16+
private String originStopId;
17+
private String destinationStopId;
1118

12-
public String getTripId() {
13-
return tripId;
19+
// The vehicleId is only used for debug purposed we know in log which vehicle set the error value
20+
private String vehicleId;
21+
22+
public String getRouteId() {
23+
return routeId;
1424
}
1525

16-
public void setTripId(String tripId) {
17-
this.tripId = tripId;
26+
public String getDirectionId() {
27+
return directionId;
1828
}
1929

20-
public void setStopPathIndex(Integer stopPathIndex) {
21-
this.stopPathIndex = stopPathIndex;
30+
public Integer getStartTimeSecondsIntoDay() {
31+
return startTimeSecondsIntoDay;
2232
}
2333

24-
private String tripId;
25-
private Integer stopPathIndex;
26-
27-
// The vehicleId is only used for debug purposed we know in log which vehicle set the error value
28-
private String vehiceId;
29-
30-
31-
public String getVehiceId() {
32-
return vehiceId;
34+
public String getOriginStopId() {
35+
return originStopId;
36+
}
37+
38+
public String getDestinationStopId() {
39+
return destinationStopId;
3340
}
3441

35-
public void setVehiceId(String vehiceId) {
36-
this.vehiceId = vehiceId;
42+
public String getVehicleId() {
43+
return vehicleId;
44+
}
45+
46+
public void setVehicleId(String vehicleId) {
47+
this.vehicleId = vehicleId;
3748
}
3849

3950
/**
4051
* Needs to be serializable to add to cache
4152
*/
42-
private static final long serialVersionUID = 5029823633051153716L;
53+
private static final long serialVersionUID = 5029823633051153717L;
4354

4455

4556
public KalmanErrorCacheKey(Indices indices, String vehicleId) {
4657
super();
47-
48-
this.tripId=indices.getBlock().getTrip(indices.getTripIndex()).getId();
49-
this.stopPathIndex=indices.getStopPathIndex();
50-
this.vehiceId=vehicleId;
58+
59+
Trip trip = indices.getBlock().getTrip(indices.getTripIndex());
60+
this.routeId = trip.getRouteId();
61+
this.directionId = trip.getDirectionId();
62+
this.startTimeSecondsIntoDay = trip.getStartTime();
63+
this.originStopId = trip.getTripPattern().getStopIds().get(0);
64+
this.destinationStopId = trip.getLastStopId();
65+
this.vehicleId =vehicleId;
5166

5267
}
5368
public KalmanErrorCacheKey(Indices indices) {
5469
super();
55-
56-
this.tripId=indices.getBlock().getTrip(indices.getTripIndex()).getId();
57-
this.stopPathIndex=indices.getStopPathIndex();
58-
59-
70+
71+
Trip trip = indices.getBlock().getTrip(indices.getTripIndex());
72+
this.routeId = trip.getRouteId();
73+
this.directionId = trip.getDirectionId();
74+
this.startTimeSecondsIntoDay = trip.getStartTime();
75+
this.originStopId = trip.getTripPattern().getStopIds().get(0);
76+
this.destinationStopId = trip.getLastStopId();
77+
6078
}
6179
@Override
6280
public String toString() {
63-
return "KalmanErrorCacheKey [tripId=" + tripId + ", stopPathIndex=" + stopPathIndex + "]";
81+
return "KalmanErrorCacheKey [routeId=" + routeId
82+
+ ", directionId=" + directionId
83+
+ ", startTime=" + startTimeSecondsIntoDay
84+
+ ", originStopId=" + originStopId
85+
+ ", destinationStopId=" + destinationStopId
86+
+ "]";
6487
}
6588

6689
@Override
6790
public int hashCode() {
6891
final int prime = 31;
6992
int result = 1;
70-
result = prime * result + ((stopPathIndex == null) ? 0 : stopPathIndex.hashCode());
71-
result = prime * result + ((tripId == null) ? 0 : tripId.hashCode());
93+
result = prime * result + ((routeId == null) ? 0 : routeId.hashCode());
94+
result = prime * result + ((directionId == null) ? 0 : directionId.hashCode());
95+
result = prime * result + ((originStopId == null) ? 0 : originStopId.hashCode());
96+
result = prime * result + ((destinationStopId == null) ? 0 : destinationStopId.hashCode());
97+
result = prime * result + ((startTimeSecondsIntoDay == null) ? 0 : startTimeSecondsIntoDay.hashCode());
7298
return result;
7399
}
74100

@@ -81,41 +107,48 @@ public boolean equals(Object obj) {
81107
if (getClass() != obj.getClass())
82108
return false;
83109
KalmanErrorCacheKey other = (KalmanErrorCacheKey) obj;
84-
if (stopPathIndex == null) {
85-
if (other.stopPathIndex != null)
110+
if (routeId == null) {
111+
if (other.routeId != null)
112+
return false;
113+
} else if (!routeId.equals(other.routeId))
114+
return false;
115+
if (directionId == null) {
116+
if (other.directionId != null)
117+
return false;
118+
} else if (!directionId.equals(other.directionId))
119+
return false;
120+
if (startTimeSecondsIntoDay == null) {
121+
if (other.startTimeSecondsIntoDay != null)
122+
return false;
123+
} else if (!startTimeSecondsIntoDay.equals(other.startTimeSecondsIntoDay))
124+
return false;
125+
if (originStopId == null) {
126+
if (other.originStopId != null)
86127
return false;
87-
} else if (!stopPathIndex.equals(other.stopPathIndex))
128+
} else if (!originStopId.equals(other.originStopId))
88129
return false;
89-
if (tripId == null) {
90-
if (other.tripId != null)
130+
if (destinationStopId == null) {
131+
if (other.destinationStopId != null)
91132
return false;
92-
} else if (!tripId.equals(other.tripId))
133+
} else if (!destinationStopId.equals(other.destinationStopId))
93134
return false;
135+
94136
return true;
95137
}
96138

97-
public KalmanErrorCacheKey(String tripId, Integer stopPathIndex) {
139+
public KalmanErrorCacheKey(String routeId, String directionId,
140+
Integer startTimeSecondsIntoDay, String originStopId,
141+
String destinationStopId) {
98142
super();
99143

100-
this.tripId = tripId;
101-
this.stopPathIndex = stopPathIndex;
144+
this.routeId = routeId;
145+
this.directionId = directionId;
146+
this.startTimeSecondsIntoDay = startTimeSecondsIntoDay;
147+
this.originStopId = originStopId;
148+
this.destinationStopId = destinationStopId;
102149
}
103150

104151

105-
/**
106-
* @return the stopPathIndex
107-
*/
108-
public int getStopPathIndex() {
109-
return stopPathIndex;
110-
}
111-
112-
/**
113-
* @param stopPathIndex the stopPathIndex to set
114-
*/
115-
public void setStopPathIndex(int stopPathIndex) {
116-
this.stopPathIndex = stopPathIndex;
117-
}
118-
119152
}
120153

121154

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.transitclock.core.dataCache;
2+
3+
import java.util.Objects;
4+
5+
/**
6+
* StopPatch caching based in TripInstance (Route/Direction/time) instead of tripId.
7+
*/
8+
public class StopPathKey extends TripKey implements java.io.Serializable {
9+
10+
private static long serialVersionUID = 1L;
11+
12+
private String originStopId;
13+
private String destinationStopId;
14+
private boolean travelTime;
15+
16+
public StopPathKey(String routeId,
17+
String directionId,
18+
Integer startTimeSecondsIntoDay,
19+
Long tripStartTime,
20+
String originStopId,
21+
String destinationStopId,
22+
boolean travelTime) {
23+
super(routeId, directionId, tripStartTime, startTimeSecondsIntoDay);
24+
this.originStopId = originStopId;
25+
this.destinationStopId = destinationStopId;
26+
this.travelTime = travelTime;
27+
}
28+
29+
public String getOriginStopId() {
30+
return originStopId;
31+
}
32+
33+
public String getDestinationStopId() {
34+
return destinationStopId;
35+
}
36+
37+
public boolean isTravelTime() {
38+
return travelTime;
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
return Objects.hash(getRouteId(), getDirectionId(), getStartTimeSecondsIntoDay(),
44+
getTripStartTime(), originStopId, destinationStopId, travelTime);
45+
}
46+
47+
@Override
48+
public boolean equals(Object o) {
49+
if (this == o) return true;
50+
if (o == null || getClass() != o.getClass()) return true;
51+
StopPathKey that = (StopPathKey) o;
52+
return Objects.equals(getRouteId(), that.getRouteId())
53+
&& Objects.equals(getDirectionId(), that.getDirectionId())
54+
&& Objects.equals(getStartTimeSecondsIntoDay(), that.getStartTimeSecondsIntoDay())
55+
&& Objects.equals(getTripStartTime(), that.getTripStartTime())
56+
&& Objects.equals(originStopId, that.originStopId)
57+
&& Objects.equals(destinationStopId, that.destinationStopId)
58+
&& Objects.equals(travelTime, that.travelTime);
59+
}
60+
}

transitclock/src/main/java/org/transitclock/core/dataCache/TripDataHistoryCacheInterface.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package org.transitclock.core.dataCache;
22

3-
import java.util.Date;
43
import java.util.List;
54

6-
import org.hibernate.Session;
7-
import org.slf4j.Logger;
85
import org.transitclock.db.structs.ArrivalDeparture;
96
import org.transitclock.ipc.data.IpcArrivalDeparture;
107

0 commit comments

Comments
 (0)