Mercurial Hosting > traffic-intelligence
diff trafficintelligence/moving.py @ 1064:cbc026dacf0b
changed interval string representation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 15 Jul 2018 22:52:26 -0400 |
parents | 75a6ad604cc5 |
children | 3939ae415be0 |
line wrap: on
line diff
--- a/trafficintelligence/moving.py Fri Jul 13 09:59:01 2018 -0400 +++ b/trafficintelligence/moving.py Sun Jul 15 22:52:26 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(interval2.last, interval2.last))