aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-03-14 18:46:46 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-03-14 18:46:46 +0000
commit87fab59964901d5ddbae6e72cbb8064c5a301297 (patch)
tree195489d4a86c2f8917ef47e40250947ed9de5f66
parent4d8977583a8b90d464dd4298b14d0bd6778618f5 (diff)
downloadsouthamptonuniversitymap-87fab59964901d5ddbae6e72cbb8064c5a301297.tar
southamptonuniversitymap-87fab59964901d5ddbae6e72cbb8064c5a301297.tar.gz
Begin fixing ambeguity caused by a bus appearing with the same ID e.g. 2003 and different names U2C and U2B at the same bus stop.
-rw-r--r--src/net/cbaines/suma/BusActivity.java59
-rw-r--r--src/net/cbaines/suma/DataManager.java131
2 files changed, 134 insertions, 56 deletions
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index 04fe6cf..8d7dcbe 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -113,7 +113,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
timetableView = (ListView) findViewById(R.id.busActivityTimes);
if (bus.id != null) {
- // Log.i(TAG, "Bus id is not null (" + bus.id + ") setting busIDTextView");
+ // Log.i(TAG, "Bus id is not null (" + bus.id +
+ // ") setting busIDTextView");
busIDTextView.setText(bus.id + " " + bus.getName());
} else {
Log.w(TAG, "Bus id is null?");
@@ -122,9 +123,10 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
}
if (bus.destinationString != null) {
- // Log.i(TAG, "Bus destination string is " + bus.destinationString);
- busDestTextView
- .setText(getResources().getString(R.string.bus_activity_destination_label) + bus.destinationString);
+ // Log.i(TAG, "Bus destination string is " +
+ // bus.destinationString);
+ busDestTextView.setText(getResources().getString(R.string.bus_activity_destination_label)
+ + bus.destinationString);
busDestTextView.setVisibility(View.VISIBLE);
} else {
// Log.i(TAG, "Bus destination string is null");
@@ -132,20 +134,20 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
busDestTextView.setVisibility(View.VISIBLE);
}
- busStops = bus.route.getRouteSection(instance, bus.direction);
+ busStops = bus.route.getRouteBusStops(this);
// Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
if (bus.destination != null) {
Log.i(TAG, "Bus destination is " + bus.destination);
- int index = busStops.indexOf(bus.destination);
- if (index != -1) {
- Log.v(TAG, "Found destination stop in busStops");
- for (int i = index + 1; i < busStops.size(); i++) {
- Log.v(TAG, "Removing " + busStops.get(i));
- busStops.remove(i);
- }
- }
+ // int index = busStops.indexOf(bus.destination);
+ // if (index != -1) {
+ // Log.v(TAG, "Found destination stop in busStops");
+ // for (int i = index + 1; i < busStops.size(); i++) {
+ // Log.v(TAG, "Removing " + busStops.get(i));
+ // busStops.remove(i);
+ // }
+ // }
} else {
Log.i(TAG, "Bus destination is null");
}
@@ -154,14 +156,17 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
public void run() {
Log.v(TAG, "Refreshing data " + (System.currentTimeMillis() - timeOfLastRefresh));
timeOfLastRefresh = System.currentTimeMillis();
- for (int num = timetableView.getFirstVisiblePosition(); num <= timetableView.getLastVisiblePosition(); num++) {
+ for (int num = timetableView.getFirstVisiblePosition(); num <= timetableView
+ .getLastVisiblePosition(); num++) {
final Stop stop = timetable.get(num);
if (System.currentTimeMillis() - stop.timeOfFetch.getTime() > 20000) {
GetTimetableStopTask task = tasks.get(busStops.get(num));
if (task != null) { // If there is a taks
- if (task.getStatus() == AsyncTask.Status.FINISHED) { // If its finished
+ if (task.getStatus() == AsyncTask.Status.FINISHED) { // If
+ // its
+ // finished
task = null; // Delete it
}
}
@@ -171,9 +176,10 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
// Remove the old time from the timetable
synchronized (timetable) {
- timetable.set(num,
- new StopLoading(bus, busStops.get(num), null, new Date(
- System.currentTimeMillis() - 21000), false));
+ timetable.set(
+ num,
+ new StopLoading(bus, busStops.get(num), null, new Date(System
+ .currentTimeMillis() - 21000), false));
displayTimetable(timetable);
}
@@ -217,9 +223,10 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
Log.i(TAG, "No Previous timetable");
timetable = new Timetable();
for (int i = 0; i < busStops.size(); i++) {
- // Add a loading stop, with a fetch time such that it will be fetched
- timetable
- .add(new StopLoading(bus, busStops.get(i), null, new Date(System.currentTimeMillis() - 21000), false));
+ // Add a loading stop, with a fetch time such that it will
+ // be fetched
+ timetable.add(new StopLoading(bus, busStops.get(i), null, new Date(
+ System.currentTimeMillis() - 21000), false));
}
// Log.v(TAG, "Finished adding placeholder stops");
} else {
@@ -272,8 +279,9 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
// Remove the old time from the timetable
synchronized (timetable) {
- timetable.set(num, new StopLoading(bus, busStops.get(num), null, new Date(
- System.currentTimeMillis() - 21000), false));
+ timetable.set(num,
+ new StopLoading(bus, busStops.get(num), null, new Date(
+ System.currentTimeMillis() - 21000), false));
displayTimetable(timetable);
}
@@ -312,7 +320,7 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
try {
// Log.i(TAG, "Fetching stop for busStop " + position);
- stop = DataManager.getStop(instance, bus, busStop);
+ stop = DataManager.getStop(instance, bus, position);
if (stop == null) {
stop = new Stop(bus, busStop, null, new Date(System.currentTimeMillis()), false);
}
@@ -324,7 +332,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
// errorMessage = "ClientProtocolException!?!";
e.printStackTrace();
} catch (IOException e) {
- // errorMessage = "Error fetching bus times from server, are you connected to the internet?";
+ // errorMessage =
+ // "Error fetching bus times from server, are you connected to the internet?";
e.printStackTrace();
} catch (JSONException e) {
// errorMessage = "Error parsing bus times";
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index 8b04928..bdfedb5 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -187,9 +187,13 @@ public class DataManager {
/*
* 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() + " " + 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()); }
*/
// Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name
@@ -213,9 +217,13 @@ public class DataManager {
/*
* 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() + " " + 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()); }
*/
// Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name
@@ -234,13 +242,17 @@ public class DataManager {
}
/*
- * for (Iterator<String> iter = buildingPoints.keySet().iterator(); iter.hasNext();) { String key = iter.next();
+ * for (Iterator<String> iter = buildingPoints.keySet().iterator();
+ * iter.hasNext();) { String key = iter.next();
*
- * Building bdg = new Building(key, buildingPoints.get(key), false); Polygon poly = buildingPolys.get(key);
+ * 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); }
*/
@@ -277,18 +289,18 @@ public class DataManager {
// 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;
+ double lat = Double.valueOf(quBitsLat[0])
+ + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) / 60d;
// 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;
+ double lng = Double.valueOf(quBitsLng[0])
+ + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) / 60d;
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));
}
@@ -409,26 +421,36 @@ public class DataManager {
}
/*
- * for (Iterator<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { BusStop stop =
- * busStopIter.next(); // Log.i(TAG, "Looking at stop " + stop.id);
+ * for (Iterator<BusStop> busStopIter = busStopDao.iterator();
+ * busStopIter.hasNext();) { BusStop stop = busStopIter.next(); //
+ * Log.i(TAG, "Looking at stop " + stop.id);
*
*
- * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ * 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();
- * routeStopsQueryBuilder.setCountOf(true); routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop);
+ * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder =
+ * routeStopsDao.queryBuilder();
+ * routeStopsQueryBuilder.setCountOf(true);
+ * routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME,
+ * stop);
*
- * PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops =
- * routeStopsDao.query(routeStopsPreparedQuery); // long num = routeStopsDao.query(routeStopsPreparedQuery).size(); //
- * Log.i(TAG, "Number is " + num);
+ * PreparedQuery<RouteStops> routeStopsPreparedQuery =
+ * routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops =
+ * routeStopsDao.query(routeStopsPreparedQuery); // long num =
+ * routeStopsDao.query(routeStopsPreparedQuery).size(); // Log.i(TAG,
+ * "Number is " + num);
*
- * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if (routeStop.busRoute.uniLink) { stop.uniLink = true;
- * } } busStopDao.update(stop); }
+ * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if
+ * (routeStop.busRoute.uniLink) { stop.uniLink = true; } }
+ * busStopDao.update(stop); }
*/
Log.i(TAG, "Finished loading bus data");
@@ -609,7 +631,8 @@ public class DataManager {
// " 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);
+ Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route "
+ + route.code);
}
}
@@ -696,7 +719,8 @@ public class DataManager {
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);
+ throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " "
+ + key);
}
}
@@ -866,6 +890,51 @@ public class DataManager {
return stop;
}
+ public static Stop getStop(Context context, Bus bus, int busStopRouteIndex) throws SQLException, ClientProtocolException,
+ IOException, JSONException {
+
+ if (helper == null)
+ helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+ if (busRouteDao == null)
+ busRouteDao = helper.getBusRouteDao();
+ if (busStopDao == null)
+ busStopDao = helper.getBusStopDao();
+
+ String file = getFileFromServer(busStopUrl + busStop.id + ".json");
+
+ JSONObject data = new JSONObject(file);
+ JSONArray stopsArray = data.getJSONArray("stops");
+
+ HashSet<BusRoute> busRoutes = new HashSet<BusRoute>();
+ busRouteDao.refresh(bus.route);
+ busRoutes.add(bus.route);
+
+ int age = Integer.parseInt(data.getString("age"));
+
+ Stop stop = null;
+
+ // Log.v(TAG, "Number of entries " + data.length());
+
+ // Log.v(TAG, "Stops: " + data.getJSONArray("stops"));
+
+ for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
+ JSONObject stopObj = stopsArray.getJSONObject(stopNum);
+
+ // Log.v(TAG, "stopObj: " + stopObj);
+ if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(bus.id)) {
+
+ stop = getStop(context, stopObj, busRoutes, busStop, age);
+ break;
+
+ // Log.v(TAG, "Found stop for a unidentified " +
+ // stop.bus.toString() + " at " + stop.busStop.id + " at "
+ // + stop.arivalTime);
+ }
+ }
+
+ return stop;
+ }
+
static PathOverlay getRoutePath(InputStream routeResource, int colour, ResourceProxy resProxy) {
PathOverlay data = null;