Mercurial Hosting > traffic-intelligence
diff trafficintelligence/moving.py @ 1077:3939ae415be0
Merging
author | Wendlasida |
---|---|
date | Fri, 20 Jul 2018 14:03:34 -0400 |
parents | 108c5dc4e34a cbc026dacf0b |
children | 845d694af7b8 |
line wrap: on
line diff
--- a/trafficintelligence/moving.py Fri Jul 20 13:50:43 2018 -0400 +++ b/trafficintelligence/moving.py Fri Jul 20 14:03:34 2018 -0400 @@ -33,7 +33,7 @@ self.last=last def __str__(self): - return '[{0}, {1}]'.format(self.first, self.last) + return '{0}-{1}'.format(self.first, self.last) def __repr__(self): return self.__str__() @@ -69,6 +69,15 @@ self.last += offset @classmethod + def parse(cls, s): + if '-' in s: + tmp = s.split('-') + if len(tmp) == 2: + return cls(int(tmp[0]), int(tmp[1])) # TODO with floats? + print(s+' is not a valid representation of an interval') + return None + + @classmethod def union(cls, interval1, interval2): '''Smallest interval comprising self and interval2''' return cls(min(interval1.first, interval2.first), max(interval1.last, interval2.last))