diff options
Diffstat (limited to 'src/net/cbaines/suma/DataManager.java')
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 08425a7..8b04928 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -75,6 +75,56 @@ public class DataManager { private static Dao<Bus, Integer> busDao; private static Dao<BusStop, String> busStopDao; + static void createDatabase(final Context context) throws SQLException, IOException { + Log.i(TAG, "Begining loading databases"); + + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + + Dao<Building, String> buildingDao; + + buildingDao = helper.getBuildingDao(); + + long buildingCount = buildingDao.countOf(); + Log.i(TAG, "Building count " + buildingCount); + if (buildingCount < 260) { + + loadBuildings(context); + Log.i(TAG, "Loaded building database"); + + } + + Dao<BusStop, String> busStopDao = helper.getBusStopDao(); + Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao(); + Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao(); + + long busStopCount = busStopDao.countOf(); + long busRouteCount = busRouteDao.countOf(); + long routeStopsCount = routeStopsDao.countOf(); + + Log.i(TAG, "BusStop count " + busStopCount); + Log.i(TAG, "BusRoute count " + busRouteCount); + Log.i(TAG, "RouteStops count " + routeStopsCount); + if (busStopCount < 217 || busRouteCount < 5 || routeStopsCount < 327) { + + loadBusData(context, true); + Log.i(TAG, "Loaded bus stop database"); + + } + + Dao<Site, String> siteDao = helper.getSiteDao(); + + long siteCount = siteDao.countOf(); + Log.i(TAG, "Sites count " + siteCount); + if (siteCount < 21) { + + loadSiteData(context); + + } + + Log.i(TAG, "Finished loading databases"); + + } + public static void loadBuildings(Context context) throws SQLException, IOException { DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); Dao<Building, String> buildingDao = helper.getBuildingDao(); @@ -407,9 +457,10 @@ public class DataManager { GeoPoint point = null; if (dataBits[2].length() > 1 && dataBits[3].length() > 1) { - point = Util.csLatLongToGeoPoint(dataBits[2], dataBits[3]); + point = Util.csLatLongToGeoPoint(dataBits[3], dataBits[2]); } else { - point = new GeoPoint(0, 0); + Log.e(TAG, "Missing point for site " + dataBits[1]); + throw new RuntimeException(); } Polygon poly = Util.csPolygonToPolygon(strLine.split("\"")[1]); @@ -438,10 +489,10 @@ public class DataManager { Dao<RouteStop, Integer> routeStopsDao = null; if (routeStopsDao == null) routeStopsDao = helper.getRouteStopsDao(); - if (busDao == null) - busDao = helper.getBusDao(); if (busStopDao == null) busStopDao = helper.getBusStopDao(); + if (busDao == null) + busDao = helper.getBusDao(); String time = stopObj.getString("time"); @@ -554,7 +605,8 @@ public class DataManager { List<RouteStop> routeStops = routeStopsDao.query(routeStopsPreparedQuery); if (routeStops.size() > 0) { - // Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + + // Log.i(TAG, "Found " + routeStops.size() + + // " stops matching the destStop " + destStop + " on route " + // route.code); } else { Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); @@ -643,6 +695,7 @@ public class DataManager { if (route != null) { busRoutes.add(route); } else { + Log.e(TAG, "Route not found " + key.substring(key.length() - 3, key.length()) + " " + key); throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " + key); } } @@ -655,12 +708,14 @@ public class DataManager { JSONObject stopObj = stopsArray.getJSONObject(stopNum); if (!keepNonUniLink && !stopObj.getString("name").startsWith("U")) { - // Log.v(TAG, "Skipping non uni-link stop " + stopObj.getString("name")); + // Log.v(TAG, "Skipping non uni-link stop " + + // stopObj.getString("name")); continue; } if (!keepUniLink && stopObj.getString("name").startsWith("U")) { - // Log.v(TAG, "Skipping uni-link stop " + stopObj.getString("name")); + // Log.v(TAG, "Skipping uni-link stop " + + // stopObj.getString("name")); continue; } @@ -751,7 +806,8 @@ public class DataManager { continue; } - // Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + // Log.v(TAG, "Found stop for a unidentified " + + // stop.bus.toString() + " at " + stop.busStop.id + " at " // + stop.arivalTime); timetable.add(stop); |