diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-18 20:38:19 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-18 20:38:19 +0000 |
commit | b374a50fb6f3bd0866bc1f75f7592abb0a6b8cc1 (patch) | |
tree | b4a95dd2bf151891f9a6129594e531bee3a74d37 /src/net/cbaines/suma/DataManager.java | |
parent | 6a1277d9a0d69dc34b1c0c1cfb6c502346035434 (diff) | |
download | southamptonuniversitymap-b374a50fb6f3bd0866bc1f75f7592abb0a6b8cc1.tar southamptonuniversitymap-b374a50fb6f3bd0866bc1f75f7592abb0a6b8cc1.tar.gz |
Fixed a bug in the constructor of BusRoute, and rebuild the database acordingly. Also made improvements to the preferences system.
Diffstat (limited to 'src/net/cbaines/suma/DataManager.java')
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 100 |
1 files changed, 64 insertions, 36 deletions
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 9ccc8f0..196a7e2 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -96,7 +96,8 @@ public class DataManager { // Log.i(TAG, "Data: " + strLine); String[] dataBits = strLine.split(","); GeoPoint point = Util.csLatLongToGeoPoint(dataBits[2], dataBits[1]); - // Log.i(TAG, "Creating building with id " + dataBits[0] + " and " + point.getLatitudeE6() + " " + point.getLongitudeE6()); + // Log.i(TAG, "Creating building with id " + dataBits[0] + " and " + point.getLatitudeE6() + " " + + // point.getLongitudeE6()); buildingPoints.put(dataBits[0], point); } @@ -109,14 +110,14 @@ public class DataManager { Log.i(TAG, "Number of building points " + buildingPoints.size()); /* - * inputStream = context.getResources().openRawResource(R.raw.buildings_shapes); bufferedReader = new BufferedReader(new - * InputStreamReader(inputStream)); + * inputStream = context.getResources().openRawResource(R.raw.buildings_shapes); bufferedReader = new + * BufferedReader(new InputStreamReader(inputStream)); * * try { String def = bufferedReader.readLine(); // Log.i(TAG, "Reading the definition " + def); * - * while ((strLine = bufferedReader.readLine()) != null) { // Log.i(TAG, "Data: " + strLine); String[] dataBits = strLine.split(","); Polygon poly = - * Util.csPolygonToPolygon(strLine.split("\"")[1]); // Log.i(TAG, "Creating building with id " + dataBits[0] + " and " + poly); - * buildingPolys.put(dataBits[0], poly); } + * while ((strLine = bufferedReader.readLine()) != null) { // Log.i(TAG, "Data: " + strLine); String[] dataBits + * = strLine.split(","); Polygon poly = Util.csPolygonToPolygon(strLine.split("\"")[1]); // Log.i(TAG, + * "Creating building with id " + dataBits[0] + " and " + poly); buildingPolys.put(dataBits[0], poly); } * * bufferedReader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } * @@ -143,16 +144,19 @@ public class DataManager { continue; } - Building bdg = new Building(dataBits[1], buildingPoints.get(dataBits[1]), dataBits[3].equals("R"), quoteBits[0]); + Building bdg = new Building(dataBits[1], buildingPoints.get(dataBits[1]), dataBits[3].equals("R"), + quoteBits[0]); /* * Polygon poly = buildingPolys.get(dataBits[1]); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // + * Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + * bdg.point.getLongitudeE6()); } */ - // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name + " " + bdg.point + " " + bdg.residential + " " + bdg.outline); + // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name + " " + bdg.point + " " + + // bdg.residential + " " + bdg.outline); buildingDao.create(bdg); @@ -165,16 +169,19 @@ public class DataManager { continue; } - Building bdg = new Building(dataBits[1], buildingPoints.get(dataBits[1]), dataBits[3].equals("R"), dataBits[0]); + Building bdg = new Building(dataBits[1], buildingPoints.get(dataBits[1]), dataBits[3].equals("R"), + dataBits[0]); /* * Polygon poly = buildingPolys.get(dataBits[1]); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // + * Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + * bdg.point.getLongitudeE6()); } */ - // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name + " " + bdg.point + " " + bdg.residential + " " + bdg.outline); + // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name + " " + bdg.point + " " + + // bdg.residential + " " + bdg.outline); buildingDao.create(bdg); @@ -192,8 +199,9 @@ public class DataManager { * * Building bdg = new Building(key, buildingPoints.get(key), false); Polygon poly = buildingPolys.get(key); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + - * " " + poly); } else { // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, + * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } * * buildingDao.create(bdg); } */ @@ -229,13 +237,18 @@ public class DataManager { String[] quBitsLng = dataBits[4].substring(1, dataBits[4].length() - 1).split(" "); // Log.i(TAG, "Whole " + dataBits[3] + " First bit " + quBitsLat[0] + " last bit " + quBitsLat[1]); - double lat = Double.valueOf(quBitsLat[0]) + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) / 60d; // TODO Much hackage + double lat = Double.valueOf(quBitsLat[0]) + + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) / 60d; // TODO Much + // hackage // Log.i(TAG, "Whole " + dataBits[4] + " First bit " + quBitsLng[0] + " last bit " + quBitsLng[1]); - double lng = Double.valueOf(quBitsLng[0]) + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) / 60d; // TODO Much hackage + double lng = Double.valueOf(quBitsLng[0]) + + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) / 60d; // TODO Much + // hackage GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * -1e6)); // Log.i(TAG, "Lat " + point.getLatitudeE6() + " lng " + point.getLongitudeE6()); - busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2].replace("\"", ""), point)); + busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2] + .replace("\"", ""), point)); } @@ -261,10 +274,14 @@ public class DataManager { BusRoute route; - boolean uniLink = false; + boolean uniLink; int id = Integer.parseInt(dataBits[0]); if (id == 326 || id == 468 || id == 327 || id == 329 || id == 354) { + Log.e(TAG, "Route " + id + " " + dataBits[1] + " is uni link"); uniLink = true; + } else { + Log.e(TAG, "Route " + id + " " + dataBits[1] + " is not uni link"); + uniLink = false; } route = new BusRoute(id, dataBits[1], dataBits[2].replace("\"", ""), uniLink); @@ -357,10 +374,12 @@ public class DataManager { // Log.i(TAG, "Looking at stop " + stop.id); /* - * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); routeStopsQueryBuilder.where().eq(columnName, value) + * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + * routeStopsQueryBuilder.where().eq(columnName, value) * - * DeleteBuilder<BusStop, String> deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is null - * deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare()); + * DeleteBuilder<BusStop, String> 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<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); @@ -427,7 +446,8 @@ public class DataManager { Log.i(TAG, "Loaded sites from csv"); } - private static Stop getStop(Context context, JSONObject stopObj, Set<BusRoute> routes, BusStop busStop) throws SQLException, JSONException { + private static Stop getStop(Context context, JSONObject stopObj, Set<BusRoute> routes, BusStop busStop) + throws SQLException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -542,14 +562,17 @@ public class DataManager { } QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, route.id).and().eq(RouteStops.STOP_ID_FIELD_NAME, destStop.id); + routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, route.id).and() + .eq(RouteStops.STOP_ID_FIELD_NAME, destStop.id); PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops = routeStopsDao.query(routeStopsPreparedQuery); if (routeStops.size() > 0) { - Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); + Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + + route.code); } else { - Log.e(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); + Log.e(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + + route.code); return null; } @@ -588,8 +611,8 @@ public class DataManager { return stop; } - public static Timetable getTimetable(Context context, String busStop, boolean keepUniLink, boolean keepNonUniLink) throws SQLException, - ClientProtocolException, IOException, JSONException { + public static Timetable getTimetable(Context context, String busStop, boolean keepUniLink, boolean keepNonUniLink) + throws SQLException, ClientProtocolException, IOException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -617,7 +640,8 @@ public class DataManager { if (route != null) { busRoutes.add(route); } else { - throw new RuntimeException("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); } } @@ -648,7 +672,8 @@ public class DataManager { continue; } - Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + stop.arivalTime); + Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + + stop.arivalTime); timetable.add(stop); } @@ -657,8 +682,8 @@ public class DataManager { return timetable; } - public static Timetable getTimetable(Context context, Bus bus, BusStop startStop, int num) throws SQLException, ClientProtocolException, IOException, - JSONException { + public static Timetable getTimetable(Context context, Bus bus, BusStop startStop, int num) throws SQLException, + ClientProtocolException, IOException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -710,7 +735,8 @@ public class DataManager { continue; } - Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + stop.arivalTime); + Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + + " at " + stop.arivalTime); timetable.add(stop); @@ -723,7 +749,8 @@ public class DataManager { return timetable; } - public static Stop getStop(Context context, Bus bus, BusStop busStop) throws SQLException, ClientProtocolException, IOException, JSONException { + public static Stop getStop(Context context, Bus bus, BusStop busStop) throws SQLException, ClientProtocolException, + IOException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -756,7 +783,8 @@ public class DataManager { stop = getStop(context, stopObj, busRoutes, busStop); break; - // Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + stop.arivalTime); + // Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " + // + stop.arivalTime); } } |