From 574ea86a77bf4911ae6956c9127ea3bf862352a3 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 8 Feb 2012 18:11:17 +0000 Subject: Begun the process of adding more of the bus data. --- src/net/cbaines/suma/BusRoute.java | 9 ++-- src/net/cbaines/suma/DataManager.java | 54 ++++++---------------- .../suma/SouthamptonUniversityMapActivity.java | 7 ++- 3 files changed, 24 insertions(+), 46 deletions(-) diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index b25b5d0..2dacfd2 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -63,10 +63,13 @@ public class BusRoute { @DatabaseField(canBeNull = true) String reverseDirection; + @DatabaseField(canBeNull = false) + boolean uniLink; + BusRoute() { } - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection) { + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) { this.id = id.intValue(); this.code = code; this.label = label; @@ -74,8 +77,8 @@ public class BusRoute { this.reverseDirection = reverseDirection; } - public BusRoute(Integer id, String code, String label) { - this(id, code, label, null, null); + public BusRoute(Integer id, String code, String label, boolean uniLink) { + this(id, code, label, null, null, uniLink); } public String toString() { diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 536cc64..770e649 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -62,9 +62,9 @@ import com.j256.ormlite.table.TableUtils; public class DataManager { - final static String TAG = "DataManager"; + private final static String TAG = "DataManager"; - final static String busStopUrl = "http://data.southampton.ac.uk/bus-stop/"; + private final static String busStopUrl = "http://data.southampton.ac.uk/bus-stop/"; private static DatabaseHelper helper; private static Dao busRoutes; @@ -256,10 +256,17 @@ public class DataManager { String[] dataBits = strLine.split(","); BusRoute route; + + boolean uniLink = false; + int id = Integer.parseInt(dataBits[0]); + if (id == 326 || id == 468 || id == 327 || id == 329 || id == 354) { + uniLink = true; + } + if (dataBits.length > 3) { - route = new BusRoute(Integer.parseInt(dataBits[0]), dataBits[1], dataBits[2].replace("\"", ""), dataBits[3], dataBits[4]); + route = new BusRoute(id, dataBits[1], dataBits[2].replace("\"", ""), dataBits[3], dataBits[4], uniLink); } else { - route = new BusRoute(Integer.parseInt(dataBits[0]), dataBits[1], dataBits[2].replace("\"", "")); + route = new BusRoute(id, dataBits[1], dataBits[2].replace("\"", ""), uniLink); } // Log.i(TAG, "Loaded route " + route.id + " " + route.code + " " + route.label); busRouteDao.create(route); @@ -317,6 +324,8 @@ public class DataManager { stop.routes = (byte) (stop.routes | (1 << 3)); } else if (route.id == 354) { // U9 stop.routes = (byte) (stop.routes | (1 << 4)); + } else { + stop.routes = 0; } Log.v(TAG, "Stop routes " + stop.routes); @@ -331,43 +340,6 @@ public class DataManager { e.printStackTrace(); } - long sizeBeforeRemoval = busStopDao.countOf(); - - // Removing busstops not used by unilink busses - for (Iterator busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { - BusStop stop = busStopIter.next(); - // Log.i(TAG, "Looking at stop " + stop.id); - - /* - * QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); routeStopsQueryBuilder.where().eq(columnName, value) - * - * DeleteBuilder deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is null - * deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare()); - */ - - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.setCountOf(true); - routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop); - - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - long num = routeStopsDao.countOf(routeStopsPreparedQuery); - // long num = routeStopsDao.query(routeStopsPreparedQuery).size(); - // Log.i(TAG, "Number is " + num); - if (num == 0) { - // Log.i(TAG, "Removing " + stop.id); - stop.uniLink = false; - if (onlyUniLink) { - busStopIter.remove(); - } - } else { - stop.uniLink = true; - } - } - - long sizeAfterRemoval = busStopDao.countOf(); - - Log.i(TAG, "Removed " + (sizeBeforeRemoval - sizeAfterRemoval) + " stops (from " + sizeBeforeRemoval + ") now have " + sizeAfterRemoval); - Log.i(TAG, "Finished loading bus data"); } diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java index c67ceea..f624a43 100644 --- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java +++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java @@ -76,7 +76,7 @@ import com.j256.ormlite.dao.Dao; public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity implements MapViewConstants, Runnable, RouteColorConstants, OnChildClickListener, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences { - private boolean useBundledDatabase = true; + private boolean useBundledDatabase = false; private MapView mapView; private MapController mapController; @@ -384,6 +384,9 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity