diff options
Diffstat (limited to 'src/net/cbaines/suma/DataManager.java')
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 76 |
1 files changed, 69 insertions, 7 deletions
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 2af4b52..f065b07 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -269,13 +269,13 @@ public class DataManager { route = new BusRoute(id, dataBits[1], dataBits[2].replace("\"", ""), uniLink); - if (id == 326) { - route.forwardDirection = "C"; - route.reverseDirection = "A"; - } else if (id == 329) { - route.forwardDirection = "C"; - route.reverseDirection = "B"; - } else if (id == 327) { + if (id == 326) { // U1 + route.forwardDirection = "A"; + route.reverseDirection = "C"; + } else if (id == 329) { // U2 + route.forwardDirection = "B"; + route.reverseDirection = "C"; + } else if (id == 327) { // U6 route.forwardDirection = "H"; route.reverseDirection = "C"; } @@ -801,4 +801,66 @@ public class DataManager { return builder.toString(); } + + public static void routeMovementTest(Context context) throws SQLException { + + Dao<RouteStops, Integer> routeStopsDao = null; + + if (helper == null) + helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + if (routeStopsDao == null) + routeStopsDao = helper.getRouteStopsDao(); + if (busRouteDao == null) + busRouteDao = helper.getBusRouteDao(); + if (busStopDao == null) + busStopDao = helper.getBusStopDao(); + + for (BusRoute busRoute : busRouteDao) { + if (!busRoute.code.startsWith("U") || busRoute.code.equals("U9")) { + continue; + } + List<RouteStops> routeStops = routeStopsDao.queryForEq(RouteStops.ROUTE_ID_FIELD_NAME, busRoute.id); + + ArrayList<String> directions = new ArrayList<String>(); + if (busRoute.forwardDirection != null) { + directions.add(busRoute.forwardDirection); + } + if (busRoute.reverseDirection != null) { + directions.add(busRoute.reverseDirection); + } + if (directions.size() == 0) { + directions.add(null); + } + + BusStop startBusStop = null; + + for (int moveAmount = 1; moveAmount >= -1; moveAmount = moveAmount - 2) { + for (String direction : directions) { + for (int busStop = 0; busStop < routeStops.size() && busStop >= 0; busStop = busStop + moveAmount) { + // if (routeStops.get(busStop).stop.equals(startBusStop)) + // continue; + startBusStop = routeStops.get(busStop).stop; + busStopDao.refresh(startBusStop); + + BusStop predictedNextStop = busRoute.moveInRoute(context, startBusStop, direction, moveAmount); + + BusStop nextStop; + if (busStop == routeStops.size() - 1) { + nextStop = routeStops.get(0).stop; + } else { + nextStop = routeStops.get(busStop + 1).stop; + } + busStopDao.refresh(nextStop); + + if (!nextStop.equals(predictedNextStop) && !startBusStop.equals(nextStop)) { + Log.e(TAG, "predicted: " + predictedNextStop + " next: " + nextStop); + Log.e(TAG, startBusStop.id + " " + nextStop.id); + return; + } + } + } + } + } + + } } |