From 1d0afd2ef85424167c722b12674e0d8a7151e14c Mon Sep 17 00:00:00 2001 From: Laurens Van Houtven Date: Sat, 7 Feb 2009 12:23:32 +0100 Subject: [PATCH] Small client delta cleanups Assorted small cleanups. --- code/breadcrumb/client/deltas.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/code/breadcrumb/client/deltas.py b/code/breadcrumb/client/deltas.py index 29106d5..faba469 100644 --- a/code/breadcrumb/client/deltas.py +++ b/code/breadcrumb/client/deltas.py @@ -22,7 +22,7 @@ import geopy thresholds = consts.DEFAULT_THRESHOLDS class DataPoint: - """ A container for GPS data. + """A container for GPS data. Provides data scrubbing for GPS data and syntactic sugar for comparison: p1 < p2 means that the deltas between p1 and p2 are significant (at least @@ -32,14 +32,13 @@ class DataPoint: self.data = data def update(self, other): - """ Updates the data in this point with data from a new point. """ + """Updates the data in this point with data from a new point.""" self.data.update(other.data) def clear_message(self): - """ Clears the handler message. """ - keys = ['handlerid', 'handlermessage'] - - for key in keys: + """Clears the handler message.""" + + for key in ['handlerid', 'handlermessage']: if key in self.data: del self.data[key] @@ -56,6 +55,7 @@ class DataPoint: def __delitem__(self, key): """ Deletes an entry from the point's dict. """ + del self.data[key] def __lt__(self, other): """ Decides if a point is significantly different from another. """ @@ -72,14 +72,13 @@ class DataPoint: logging.debug("Didn't pass threshold %s (diff=%2f, thresh=%2f)" % (key, diff, threshold)) - return False # Thresholds exhausted, none triggered def __gt__(self, other): raise NotImplementedError def delta(p1, p2, attribute): - """ Returns the difference in attribute between this point and another. + """Returns the difference in attribute between this point and another. Differences are returned in SI units (seconds, meters...), except for any angle (usually, this means true heading). Angles are returned in @@ -140,7 +139,7 @@ def delta(p1, p2, attribute): return int(delta_attr) def get_attr_as_floats(p1, p2, attribute): - """ Gets attributes from two data points as floats. + """Gets attributes from two data points as floats. These attributes might be in string form depending on where they come from (different sentences encode differently, unfortunately). This does @@ -155,12 +154,12 @@ def get_attr_as_floats(p1, p2, attribute): # XXX: I'm not entirely sure if anyone uses this... - lvh def _default_thresholds(): - """ Gets the default thresholds from the consts module. """ + """Gets the default thresholds from the consts module.""" reload(consts) return consts.DEFAULT_THRESHOLDS def update_tresholds(new_thresholds = None): - """ Updates the thresholds with the threshold data in the argument. + """Updates the thresholds with the threshold data in the argument. If no argument is supplied, it uses the default values. @@ -172,14 +171,13 @@ def update_tresholds(new_thresholds = None): This will cause the dict to be updated, not replaced. Old thresholds will not be overwritten. (If you want this instead, see set_thresholds.) """ - if new_thresholds == {}: - logging.error("Updating with empty dict, resetting thresholds... Are \ -you sure this is what you wanted?") + if not new_thresholds: + logging.error("Updating with empty dict, resetting thresholds...) thresholds.update(new_thresholds or _default_thresholds()) def set_thresholds(new_thresholds = None): - """ Sets the thresolds. + """Sets the thresolds. If no argument is supplied, it uses the default values. -- 2.11.4.GIT