Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 1063:3c37d8d20e97 | 1064:cbc026dacf0b |
|---|---|
| 31 else: | 31 else: |
| 32 self.first=first | 32 self.first=first |
| 33 self.last=last | 33 self.last=last |
| 34 | 34 |
| 35 def __str__(self): | 35 def __str__(self): |
| 36 return '[{0}, {1}]'.format(self.first, self.last) | 36 return '{0}-{1}'.format(self.first, self.last) |
| 37 | 37 |
| 38 def __repr__(self): | 38 def __repr__(self): |
| 39 return self.__str__() | 39 return self.__str__() |
| 40 | 40 |
| 41 def __eq__(self, other): | 41 def __eq__(self, other): |
| 66 | 66 |
| 67 def shift(self, offset): | 67 def shift(self, offset): |
| 68 self.first += offset | 68 self.first += offset |
| 69 self.last += offset | 69 self.last += offset |
| 70 | 70 |
| 71 @classmethod | |
| 72 def parse(cls, s): | |
| 73 if '-' in s: | |
| 74 tmp = s.split('-') | |
| 75 if len(tmp) == 2: | |
| 76 return cls(int(tmp[0]), int(tmp[1])) # TODO with floats? | |
| 77 print(s+' is not a valid representation of an interval') | |
| 78 return None | |
| 79 | |
| 71 @classmethod | 80 @classmethod |
| 72 def union(cls, interval1, interval2): | 81 def union(cls, interval1, interval2): |
| 73 '''Smallest interval comprising self and interval2''' | 82 '''Smallest interval comprising self and interval2''' |
| 74 return cls(min(interval1.first, interval2.first), max(interval2.last, interval2.last)) | 83 return cls(min(interval1.first, interval2.first), max(interval2.last, interval2.last)) |
| 75 | 84 |
