diff options
author | Ruei-sung Lin <rslin@google.com> | 2012-08-28 18:00:48 -0700 |
---|---|---|
committer | Ruei-sung Lin <rslin@google.com> | 2012-08-28 18:00:48 -0700 |
commit | 83954e853dc1e1a28b2c3efbe1585f188266df02 (patch) | |
tree | 243c6985dc69bb68d6c906c5deceddf47c2cfed0 | |
parent | c7c9cf164cc58d03156a53be35e58c3b75871a23 (diff) | |
download | ml-83954e853dc1e1a28b2c3efbe1585f188266df02.tar.gz |
save/load temporal histogram of each semantic cluster
Change-Id: I8b9403c0be2d9900194390d850034441b4f0f666
5 files changed, 73 insertions, 32 deletions
diff --git a/bordeaux/service/src/android/bordeaux/services/AggregatorRecordStorage.java b/bordeaux/service/src/android/bordeaux/services/AggregatorRecordStorage.java index 5c407b75d..4bf677f59 100644 --- a/bordeaux/service/src/android/bordeaux/services/AggregatorRecordStorage.java +++ b/bordeaux/service/src/android/bordeaux/services/AggregatorRecordStorage.java @@ -100,8 +100,11 @@ class AggregatorRecordStorage extends AggregatorStorage { do { HashMap<String, String> oneRow = new HashMap<String, String>(); for (String column : mColumnNames) { - String value = cursor.getString(cursor.getColumnIndex(column)); - oneRow.put(column, value); + int columnIndex = cursor.getColumnIndex(column); + if (!cursor.isNull(columnIndex)) { + String value = cursor.getString(columnIndex); + oneRow.put(column, value); + } } allData.add(oneRow); } while (cursor.moveToNext()); diff --git a/bordeaux/service/src/android/bordeaux/services/BaseCluster.java b/bordeaux/service/src/android/bordeaux/services/BaseCluster.java index 433bb8771..37c2930ff 100644 --- a/bordeaux/service/src/android/bordeaux/services/BaseCluster.java +++ b/bordeaux/service/src/android/bordeaux/services/BaseCluster.java @@ -162,4 +162,21 @@ public class BaseCluster { // TODO: might want to keep semantic cluster return mDuration > durationThreshold; } + + public final HashMap<String, Long> getHistogram() { + return mHistogram; + } + + public void setHistogram(Map<String, Long> histogram) { + mHistogram.clear(); + mHistogram.putAll(histogram); + + mDuration = 0; + if (mHistogram.containsKey(TimeStatsAggregator.WEEKEND)) { + mDuration += mHistogram.get(TimeStatsAggregator.WEEKEND); + } + if (mHistogram.containsKey(TimeStatsAggregator.WEEKDAY)) { + mDuration += mHistogram.get(TimeStatsAggregator.WEEKDAY); + } + } } diff --git a/bordeaux/service/src/android/bordeaux/services/ClusterManager.java b/bordeaux/service/src/android/bordeaux/services/ClusterManager.java index 14721ba55..f6217e328 100644 --- a/bordeaux/service/src/android/bordeaux/services/ClusterManager.java +++ b/bordeaux/service/src/android/bordeaux/services/ClusterManager.java @@ -38,15 +38,19 @@ public class ClusterManager { private static String TAG = "ClusterManager"; - private static float LOCATION_CLUSTER_RADIUS = 25; // meter + private static float LOCATION_CLUSTER_RADIUS = 50; // meter - private static float SEMANTIC_CLUSTER_RADIUS = 50; // meter + private static float SEMANTIC_CLUSTER_RADIUS = 100; // meter - private static long CONSOLIDATE_INTERVAL = 21600000; // + private static long CONSOLIDATE_INTERVAL = 60000; // + // private static long CONSOLIDATE_INTERVAL = 21600000; // - private static long LOCATION_CLUSTER_THRESHOLD = 180000; // in milliseconds - private static long SEMANTIC_CLUSTER_THRESHOLD = 1800000; // in milliseconds + private static long LOCATION_CLUSTER_THRESHOLD = 10000; // in milliseconds + // private static long LOCATION_CLUSTER_THRESHOLD = 180000; // in milliseconds + + private static long SEMANTIC_CLUSTER_THRESHOLD = 30000; // in milliseconds + // private static long SEMANTIC_CLUSTER_THRESHOLD = 1800000; // in milliseconds private static String UNKNOWN_LOCATION = "Unknown Location"; @@ -70,12 +74,25 @@ public class ClusterManager { private static String SEMANTIC_ID = "ID"; - private static String SEMANTIC_LONGITUDE = "Longitude"; + private static final String SEMANTIC_LONGITUDE = "Longitude"; + + private static final String SEMANTIC_LATITUDE = "Latitude"; - private static String SEMANTIC_LATITUDE = "Latitude"; + private static final String[] SEMANTIC_COLUMNS = + new String[]{ SEMANTIC_ID, + SEMANTIC_LONGITUDE, + SEMANTIC_LATITUDE, + TimeStatsAggregator.WEEKEND, + TimeStatsAggregator.WEEKDAY, + TimeStatsAggregator.MORNING, + TimeStatsAggregator.NOON, + TimeStatsAggregator.AFTERNOON, + TimeStatsAggregator.EVENING, + TimeStatsAggregator.NIGHT, + TimeStatsAggregator.LATENIGHT }; - private static String[] SEMANTIC_COLUMNS = - new String[]{ SEMANTIC_ID, SEMANTIC_LONGITUDE, SEMANTIC_LATITUDE}; + private static final int mFeatureValueStart = 3; + private static final int mFeatureValueEnd = 10; public ClusterManager(Context context) { mStorage = new AggregatorRecordStorage(context, SEMANTIC_TABLE, SEMANTIC_COLUMNS); @@ -87,7 +104,7 @@ public class ClusterManager { float bestClusterDistance = Float.MAX_VALUE; int bestClusterIndex = -1; long lastDuration; - long currentTime = location.getTime(); + long currentTime = location.getTime() / 1000; // measure time in seconds if (mLastLocation != null) { // get the duration spent in the last location @@ -135,16 +152,6 @@ public class ClusterManager { consolidateClusters(collectDuration); mTimeRef = currentTime; } - - /* - // TODO: this could be removed - Log.i(TAG, "location : " + location.getLongitude() + ", " + location.getLatitude()); - if (mLastLocation != null) { - Log.i(TAG, "mLastLocation: " + mLastLocation.getLongitude() + ", " + - mLastLocation.getLatitude()); - } // end of deletion - */ - mLastLocation = location; } @@ -182,15 +189,25 @@ public class ClusterManager { private void loadSemanticClusters() { List<Map<String, String> > allData = mStorage.getAllData(); + HashMap<String, Long> histogram = new HashMap<String, Long>(); mSemanticClusters.clear(); for (Map<String, String> map : allData) { String semanticId = map.get(SEMANTIC_ID); double longitude = Double.valueOf(map.get(SEMANTIC_LONGITUDE)); double latitude = Double.valueOf(map.get(SEMANTIC_LATITUDE)); - SemanticCluster cluster = new SemanticCluster( semanticId, longitude, latitude, CONSOLIDATE_INTERVAL); + + histogram.clear(); + for (int i = mFeatureValueStart; i <= mFeatureValueEnd; i++) { + String featureValue = SEMANTIC_COLUMNS[i]; + if (map.containsKey(featureValue)) { + histogram.put(featureValue, Long.valueOf(map.get(featureValue))); + } + } + cluster.setHistogram(histogram); + mSemanticClusters.add(cluster); } @@ -211,12 +228,16 @@ public class ClusterManager { String.valueOf(cluster.getCenterLongitude())); rowFeatures.put(SEMANTIC_LATITUDE, String.valueOf(cluster.getCenterLatitude())); + + HashMap<String, Long> histogram = cluster.getHistogram(); + for (Map.Entry<String, Long> entry : histogram.entrySet()) { + rowFeatures.put(entry.getKey(), String.valueOf(entry.getValue())); + } mStorage.addData(rowFeatures); } } private void updateSemanticClusters() { - HashMap<String, ArrayList<BaseCluster> > semanticMap = new HashMap<String, ArrayList<BaseCluster> >(); for (SemanticCluster cluster : mSemanticClusters) { diff --git a/bordeaux/service/src/android/bordeaux/services/LocationCluster.java b/bordeaux/service/src/android/bordeaux/services/LocationCluster.java index 2797e18b1..2d25cf1fe 100644 --- a/bordeaux/service/src/android/bordeaux/services/LocationCluster.java +++ b/bordeaux/service/src/android/bordeaux/services/LocationCluster.java @@ -58,7 +58,7 @@ public class LocationCluster extends BaseCluster { // update cluster center for (Location location : mLocations) { double[] vector = getLocationVector(location); - long duration = location.getTime(); + long duration = location.getTime(); // in seconds newDuration += duration; for (int i = 0; i < 3; ++i) { @@ -129,15 +129,15 @@ public class LocationCluster extends BaseCluster { private void updateTemporalHistogram(long time, long duration) { HashMap<String, String> timeFeatures = TimeStatsAggregator.getAllTimeFeatures(time); + String timeOfWeek = timeFeatures.get(TimeStatsAggregator.TIME_OF_WEEK); + long totalDuration = (mNewHistogram.containsKey(timeOfWeek)) ? + mNewHistogram.get(timeOfWeek) + duration : duration; + mNewHistogram.put(timeOfWeek, totalDuration); + String timeOfDay = timeFeatures.get(TimeStatsAggregator.TIME_OF_DAY); - long totalDuration = (mNewHistogram.containsKey(timeOfDay)) ? + totalDuration = (mNewHistogram.containsKey(timeOfDay)) ? mNewHistogram.get(timeOfDay) + duration : duration; mNewHistogram.put(timeOfDay, totalDuration); - - String periodOfDay = timeFeatures.get(TimeStatsAggregator.PERIOD_OF_DAY); - totalDuration = (mNewHistogram.containsKey(periodOfDay)) ? - mNewHistogram.get(periodOfDay) + duration : duration; - mNewHistogram.put(periodOfDay, totalDuration); } private void consolidateHistogram(double weight, long newDuration) { diff --git a/bordeaux/service/src/android/bordeaux/services/LocationStatsAggregator.java b/bordeaux/service/src/android/bordeaux/services/LocationStatsAggregator.java index 967bb6d1e..0c4dddbb5 100644 --- a/bordeaux/service/src/android/bordeaux/services/LocationStatsAggregator.java +++ b/bordeaux/service/src/android/bordeaux/services/LocationStatsAggregator.java @@ -40,7 +40,7 @@ public class LocationStatsAggregator extends Aggregator { public static final String UNKNOWN_LOCATION = "Unknown Location"; // TODO: Collect location on every minute - private static final long MINIMUM_TIME = 60000; // milliseconds + private static final long MINIMUM_TIME = 30000; // milliseconds // reset best location provider on every 5 minutes private static final int BEST_PROVIDER_DURATION = 300000; |