Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/iframework.py @ 1163:fa9c358789ac
bug correction
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 19 Mar 2021 15:54:19 -0400 |
parents | efd52c55a72b |
children | f1a33f458d7e |
comparison
equal
deleted
inserted
replaced
1162:efd52c55a72b | 1163:fa9c358789ac |
---|---|
135 Column('lineIdx', Integer, ForeignKey('lines.idx'))) | 135 Column('lineIdx', Integer, ForeignKey('lines.idx'))) |
136 | 136 |
137 class Line(Base): | 137 class Line(Base): |
138 __tablename__ = 'lines' | 138 __tablename__ = 'lines' |
139 idx = Column(Integer, primary_key=True) | 139 idx = Column(Integer, primary_key=True) |
140 name = Column(String) | |
141 # todo define lines for access counting: add type? - AccessLine? | |
140 | 142 |
141 points = relationship('Point', secondary=pointLineAssociation) | 143 points = relationship('Point', secondary=pointLineAssociation) |
142 | 144 |
143 def __init__(self, x1, y1, x2, y2): | 145 def __init__(self, name, x1, y1, x2, y2): |
146 self.name = name | |
144 self.points = [Point(x1, y1), Point(x2, y2)] | 147 self.points = [Point(x1, y1), Point(x2, y2)] |
145 | 148 |
146 pointZoneAssociation = Table('pointzones', Base.metadata, | 149 pointZoneAssociation = Table('pointzones', Base.metadata, |
147 Column('pointIdx', Integer, ForeignKey('points.idx')), | 150 Column('pointIdx', Integer, ForeignKey('points.idx')), |
148 Column('zoneIdx', Integer, ForeignKey('zones.idx'))) | 151 Column('zoneIdx', Integer, ForeignKey('zones.idx'))) |
149 | 152 |
150 class Zone(Base): | 153 class Zone(Base): |
151 __tablename__ = 'zones' | 154 __tablename__ = 'zones' |
152 idx = Column(Integer, primary_key=True) | 155 idx = Column(Integer, primary_key=True) |
156 name = Column(String) | |
153 | 157 |
154 points = relationship('Point', secondary=pointZoneAssociation) | 158 points = relationship('Point', secondary=pointZoneAssociation) |
155 | 159 |
156 def __init__(self, xs = None, ys = None): | 160 def __init__(self, name, xs = None, ys = None): |
157 'xs and ys are the list of x and y coordinates' | 161 'xs and ys are the list of x and y coordinates' |
162 self.name = name | |
158 if xs is not None and ys is not None: | 163 if xs is not None and ys is not None: |
159 for x,y in zip(xs, ys): | 164 for x,y in zip(xs, ys): |
160 self.addPoint(x,y) | 165 self.addPoint(x,y) |
161 | 166 |
162 def addPoint(self, x, y): | 167 def addPoint(self, x, y): |
163 self.points.append(Point(x, y)) | 168 self.points.append(Point(x, y)) |
164 | 169 |
165 class AbstractPassing: | 170 class AbstractPassing: |
166 def initPersonGroupPassing(self, group, person, transport, vehicle): | 171 def initPersonGroupPassing(self, group, person, transport, vehicle): |
172 ''' initiates with the passing the group or person | |
173 | |
174 design question: what should be done about simple line counting, | |
175 without information about persons''' | |
167 if person is None and group is not None: # create group | 176 if person is None and group is not None: # create group |
168 self.group = group | 177 self.group = group |
169 if transport is not None: | 178 if transport is not None: |
170 Mode.initGroup(transport, group, vehicle) | 179 Mode.initGroup(transport, group, vehicle) |
171 elif person is not None and group is None: # create person | 180 elif person is not None and group is None: # create person |
270 # count example | 279 # count example |
271 p = Person(6, 'female', bag = True) | 280 p = Person(6, 'female', bag = True) |
272 veh1 = Vehicle('car') | 281 veh1 = Vehicle('car') |
273 modes = [Mode('cardriver', p, veh1), Mode('walking', p, startTime = datetime(2020,7,7,11,20))] | 282 modes = [Mode('cardriver', p, veh1), Mode('walking', p, startTime = datetime(2020,7,7,11,20))] |
274 | 283 |
275 line = Line(0.,0.,0.,10.) | 284 line = Line('line1', 0.,0.,0.,10.) |
276 zone = Zone([0., 0., 1., 1.], [0., 1., 1., 0.]) | 285 zone = Zone('zone1', [0., 0., 1., 1.], [0., 1., 1., 0.]) |
277 destination = Zone([10., 10., 11., 11.], [10., 11., 11., 10.]) | 286 destination = Zone('destination1', [10., 10., 11., 11.], [10., 11., 11., 10.]) |
278 counts = [LinePassing(line, datetime(2020,7,2,23,20+i), person = Person(20+i, 'female', disability = True), transport = 'walking') for i in range(5)] | 287 counts = [LinePassing(line, datetime(2020,7,2,23,20+i), person = Person(20+i, 'female', disability = True), transport = 'walking') for i in range(5)] |
279 group1 = Group([Person(13+i,'female', False, False, True, False) for i in range(3)]) | 288 group1 = Group([Person(13+i,'female', False, False, True, False) for i in range(3)]) |
280 groupMode1 = Mode.initGroup('walking', group1) | 289 groupMode1 = Mode.initGroup('walking', group1) |
281 activities = [Activity('walking', datetime(2020,7,2,23,0), datetime(2020,7,2,23,10), zone, person = Person(40, 'male', True, False, True, False)), | 290 activities = [Activity('walking', datetime(2020,7,2,23,0), datetime(2020,7,2,23,10), zone, person = Person(40, 'male', True, False, True, False)), |
282 Activity('eating', datetime(2020,7,2,23,10), datetime(2020,7,2,23,12), zone, person = Person(40, 'male', True, False, True, False)), | 291 Activity('eating', datetime(2020,7,2,23,10), datetime(2020,7,2,23,12), zone, person = Person(40, 'male', True, False, True, False)), |
283 Activity('playing', datetime(2020,7,2,22,0), datetime(2020,7,2,23,0), zone, group = group1)] | 292 Activity('playing', datetime(2020,7,2,22,0), datetime(2020,7,2,23,0), zone, group = group1)] |
284 counts.append(LinePassing(line, datetime(2020,7,2,23,5), group = group1)) | 293 counts.append(LinePassing(line, datetime(2020,7,2,23,5), group = group1)) |
285 counts.append(LinePassing(line, datetime(2020,7,2,23,7), person = Person(23, 'unknown'), transport = 'cardriver', vehicle = Vehicle('car'))) | 294 counts.append(LinePassing(line, datetime(2020,7,2,23,7), person = Person(23, 'unknown'), transport = 'cardriver', vehicle = Vehicle('car'))) |
286 counts.append(LinePassing(line, datetime(2020,7,2,23,9), person = Person('teen', 'unknown'), transport = 'scooter', vehicle = Vehicle('scooter'))) | 295 counts.append(LinePassing(line, datetime(2020,7,2,23,9), person = Person('teen', 'unknown'), transport = 'scooter', vehicle = Vehicle('scooter'))) |
287 counts.append(LinePassing(line, datetime(2020,7,2,23,11), person = Person(12, 'female'), transport = 'bike')) | 296 counts.append(LinePassing(line, datetime(2020,7,2,23,11), person = Person(12, 'female'), transport = 'bike')) |
288 counts.append(LinePassing(line, datetime(2020,7,2,23,13), person = Person(), transport = 'car')) # example of counting cars without knowing the driver and passenger's attributes | 297 counts.append(LinePassing(line, datetime(2020,7,2,23,13), person = Person(), transport = 'cardriver')) # example of counting cars without knowing the driver and passenger's attributes |
289 counts.append(LinePassing(line, datetime(2020,7,2,23,15), group = Group([Person(34+i) for i in range(3)]), transport = 'carpassenger')) | 298 counts.append(LinePassing(line, datetime(2020,7,2,23,15), group = Group([Person(34+i) for i in range(3)]), transport = 'carpassenger')) |
290 | 299 |
291 | 300 |
292 counts.append(ZonePassing(zone, datetime(2020,7,7,9,5), True, person = Person(33, 'male', False, False, True, False))) | 301 counts.append(ZonePassing(zone, datetime(2020,7,7,9,5), True, person = Person(33, 'male', False, False, True, False))) |
293 | 302 |