-
Notifications
You must be signed in to change notification settings - Fork 1
/
Animations.py
416 lines (294 loc) · 20.8 KB
/
Animations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import copy #To copy objects
import functools #To give parameters to function connected by timers
from myWidgets import * #Import py file with my own widgets
from Scripts.Location import * # class
# from Main import * #Mode class
#The width will be recalculated according to the dimensions of the real network
# *************** Timers Functions *************************************** #
def personWalkingToBusStopTimer(stop,clockwise,person,myTimer,its,timerInterval,statusLbl, mainExperiment):
# person.icon.setPicture(path="Pictures/walkingWork.png")
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Caminando al paradero", statusLbl=statusLbl,
mainExperiment=mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Walking to bus stop", statusLbl=statusLbl, mainExperiment=mainExperiment)
myTimerCallBack = functools.partial(personMovingUI,person=person, destination=stop,clockwise=clockwise
,myTimer = myTimer, its = its, isWalking = True,statusLbl = statusLbl, mainExperiment = mainExperiment)
myTimer.timeout.connect(myTimerCallBack)
myTimer.start(timerInterval) #timerInterval in seconds
def personWalkingToBusStopInformationTimer(stop,clockwise,person,myTimer,its,timerInterval,targetedWaitingTime,statusLbl, mainExperiment):
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Caminando al paradero", statusLbl=statusLbl,
mainExperiment=mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Walking to bus stop", statusLbl=statusLbl, mainExperiment=mainExperiment)
myTimerCallBack = functools.partial(personMovingBusStopInformationUI,person=person
, stop=stop,clockwise=clockwise,myTimer = myTimer, its = its, isWalking = True
,remainingWaitingTime = targetedWaitingTime,statusLbl = statusLbl, mainExperiment = mainExperiment)
myTimer.timeout.connect(myTimerCallBack)
myTimer.start(timerInterval) #timerInterval in seconds
def personWalkingFromBusStopTimer(stop,clockwise,person,myTimer,its,timerInterval, mainExperiment):
# person.icon.setPicture(path="Pictures/walkingWork.png")
person.setWalkingDistanceFromStopToDestination(its.pathDistance(origin = person.position, destination = stop.position, clockwise = clockwise))
myTimerCallBack = functools.partial(personMovingUI,person=person, destination=stop.position,clockwise=clockwise
,myTimer = myTimer, its = its, isWalking = True, mainExperiment = mainExperiment)
myTimer.timeout.connect(myTimerCallBack)
myTimer.start(timerInterval) #timerInterval in seconds
def personWalkingToWestLocationTimer(destination,clockwise,person,myTimer,its,timerInterval, mainExperiment):
person.icon.setPicture(person.icons["eastToWest"].path)
person.setWalkingDistanceFromOriginToDestination(its.pathDistance(origin = person.position, destination = destination, clockwise = clockwise))
myTimerCallBack = functools.partial(personMovingUI,person=person, destination=destination,clockwise=clockwise,myTimer = myTimer, its = its, isWalking = True, mainExperiment = mainExperiment)
myTimer.timeout.connect(myTimerCallBack)
myTimer.start(timerInterval) #timerInterval in seconds
def personWalkingToEastLocationTimer(destination,clockwise,person,myTimer,its,timerInterval, mainExperiment):
person.icon.setPicture(person.icons["westToEast"].path)
person.setWalkingDistanceFromOriginToDestination(
its.pathDistance(origin=person.position, destination=destination, clockwise=clockwise))
myTimerCallBack = functools.partial(personMovingUI,person=person, destination=destination,clockwise=clockwise, myTimer = myTimer, its = its, isWalking = True, mainExperiment = mainExperiment)
myTimer.timeout.connect(myTimerCallBack)
myTimer.start(timerInterval) #timerInterval in seconds
def personDrivingTimer(destination,clockwise,person,its,car,myTimer,timerInterval):
person.icon.setPicture(car.icon.path)
person.speed = car.speed
myTimerCallBack = functools.partial(personMovingUI,person=person, destination=destination,clockwise=clockwise,myTimer = myTimer, its = its, isWalking = False)
myTimer.timeout.connect(myTimerCallBack)
myTimer.start(timerInterval) #timerInterval in seconds
def personBikingTimer(destination,clockwise,person,its,bike,myTimer,timerInterval):
person.icon.setPicture(path="Pictures/bikingRight.png")
person.icon.setPicture(bike.icon.path)
person.speed = bike.speed
myTimerCallBack = functools.partial(personMovingUI,person=person, destination=destination,clockwise=clockwise,myTimer = myTimer, its = its, isWalking = False)
myTimer.timeout.connect(myTimerCallBack)
myTimer.start(timerInterval) #timerInterval in seconds
def startBusTripTimer(trajectory,bus,its,myTimer, timerInterval, departureTime,person,personTimer
,ui,nextJourneyClicked, statusLbl,lastUpdateLearningPhase, mainExperiment):
# bus.icon.setPicture(bus.icon.path)
# bus.icon.raise_()
myTimerCallBack = functools.partial(completeBusTrip, trajectory=trajectory, bus=bus,
its=its, myTimer=myTimer, timerInterval = timerInterval
,person=person,personTimer = personTimer
,ui = ui
,nextJourneyClicked = nextJourneyClicked
, statusLbl = statusLbl
, lastUpdateLearningPhase = lastUpdateLearningPhase
, mainExperiment = mainExperiment
)
myTimer.timeout.connect(myTimerCallBack)
#Configure the timer for generate a random delay before the bus leave its departure terminal (setSingleshot)
myTimer.setInterval(departureTime*1000)
myTimer.setSingleShot(True)
myTimer.start() # The bus will move after the delay (method completeBusRun()). This will allow to generate different waiting times at the bus stop
# *************** Animations Functions *************************************** #
def busMovingUI(bus,destination,clockwise,timeInterval,its,busIcon):
if bus.moving == False:
busTrajectory = its.trajectory(origin=bus.position, destination=destination, clockwise=clockwise,timeInterval=timeInterval,speed=bus.speed)
bus.move(trajectory=busTrajectory,clockwise = clockwise)
bus.move(trajectory = bus.trajectory,clockwise = bus.clockwise) #if the bus is already moving there will be a trajectory and direction previously defined
busVirtualPosition = its.getVirtualPosition(position = bus.position)
busIcon.setGeometry(busVirtualPosition.x-busIcon.width()/2, busVirtualPosition.y-busIcon.height()/2, busIcon.width(), busIcon.height())
def personMovingUI(person,destination,clockwise,myTimer, its, isWalking,mainExperiment, statusLbl = None):
trajectoryPerson = its.createTrajectory(origin=person.position, destination=destination,
clockwise=clockwise,
speed=person.speed)['trajectory']
its.movePerson(person = person, trajectory = trajectoryPerson, isWalking = isWalking)
#When the person stop walking, the timer needs to be stopped
if person.moving == False: #Person has arrived to the first bus stop to take the bus
if isinstance(destination,BusStop):
destination.icon.setPicture("")
destination.icon.setText("?")
destination.icon.setFont(QFont(mainExperiment.fontLetter, mainExperiment.fontFactor * 24, QFont.Bold))
destination.icon.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
person.icon.setVisible(False)
# person.icon.setPicture(person.icons["waitingStop"].path)
if statusLbl is not None:
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Esperando en paradero", statusLbl=statusLbl,
mainExperiment=mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Waiting at bus stop", statusLbl=statusLbl,
mainExperiment=mainExperiment)
myTimer.stop()
def personWaitingTimer(person, remainingWaitingTime, stop, statusLbl, mainExperiment):
roundDigitsTime = 0
if mainExperiment.variableWaitingTimer == True:
unitLabel = "s"
unitLabel = ""
else:
unitLabel = " [s]"
remainingWaitingTime = int(remainingWaitingTime)
stop.icon.setPicture("")
person.icon.setPicture(person.icons["waitingStop"].path)
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(
status="Esperando en paradero (próximo bus en " + str(round(remainingWaitingTime, roundDigitsTime)) + " segundos)"
, statusLbl=statusLbl, mainExperiment=mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(
status="Waiting at bus stop (next bus in " + str(round(remainingWaitingTime, roundDigitsTime)) + " seconds)"
, statusLbl=statusLbl, mainExperiment=mainExperiment)
person.icon.setVisible(False)
stop.icon.setText(str(round(remainingWaitingTime,roundDigitsTime)) + unitLabel)
stop.icon.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
stop.icon.setFont(QFont(mainExperiment.fontLetter, mainExperiment.fontFactor*16, QFont.Bold))
def personMovingBusStopInformationUI(person, stop, clockwise, myTimer, remainingWaitingTime, its, isWalking,statusLbl, mainExperiment):
if stop.getNextBusTime() is None:
stop.setNextBusTime(nextBusTime= remainingWaitingTime)
trajectoryPerson = its.createTrajectory(origin=person.position, destination=stop.position,
clockwise=clockwise,
speed=person.speed
)['trajectory']
its.movePerson(person=person, trajectory=trajectoryPerson, isWalking=isWalking)
# This shows real time information when the person arrived to the bus stop.
if person.moving == False:
# a = stop.getNextBusTime()
# b = remainingWaitingTime-1
personWaitingTimer(person=person, remainingWaitingTime = stop.getNextBusTime() , stop=stop, statusLbl = statusLbl, mainExperiment = mainExperiment)
# True if the counter for waiting time decrease second by second
if mainExperiment.variableWaitingTimer == True:
myTimer.stop()
myTimer.setInterval(1000)
myTimer.start(1000)
stop.setNextBusTime(nextBusTime=stop.getNextBusTime()-1)
if stop.getNextBusTime() <= 0:
stop.setNextBusTime(nextBusTime=None)
myTimer.stop()
# stop.icon.setText(str(0))
else:
stop.setNextBusTime(nextBusTime=stop.getNextBusTime())
myTimer.stop()
#Receive object type trajectory
def completeBusTrip(trajectory, bus, its,myTimer,person, timerInterval,personTimer,ui,nextJourneyClicked, lastUpdateLearningPhase,statusLbl, mainExperiment):
nextJourneyButton = ui.nextJourneyButton
trajectoryBus = copy.copy(trajectory)
myTimer.setSingleShot(False) #The timer has been setted in one single shot to model the delay of a bus (a proxy for waiting time)
myTimer.start(timerInterval) #Now, the timer allows to simualte the trajectory of the bus between the departure and arrival terminal
firstBusStop = bus.route.busStops[1] #The first bus stop of the route, where the bus first will stop
lastBusStop = bus.route.busStops[2] #The bus stop where the passenger will get off
#If the bus has not arrived yet to the bus stop where the passenger is waiting (departing from terminal)
if its.isNextPositionAhead(trajectory = trajectory,currentPosition = bus.position, nextPosition = firstBusStop.position) == True:
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Bus llegando", statusLbl=statusLbl,mainExperiment = mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Bus arriving", statusLbl=statusLbl,mainExperiment = mainExperiment)
bus.icon.setVisible(True)
# firstBusStop.icon.setText("")
# person.icon.setVisible(True)
# person.icon.setPicture(person.icons["busArriving"].path)
# # firstBusStop.icon.setPicture(firstBusStop.icon.originalPath)
trajectoryToFirstBusStop = its.createTrajectory(origin = trajectory.origin,destination = firstBusStop.position,clockwise = trajectory.isClockwise(),speed = trajectory.speed)['trajectory']
trajectoryBus = copy.copy(trajectoryToFirstBusStop)
#Move the bus to the next position
its.moveBus(trajectory = trajectoryBus, bus = bus)
# If the bus has arrived to the bus stop where the passenger is waiting
elif its.equalPositions(bus.position,firstBusStop.position) == True and firstBusStop.visited == False: #The bus arrive to the stop where the passenger is waiting
person.icon.setVisible(True)
bus.icon.setVisible(False)
person.icon.setPicture(person.icons["busArriving"].path)
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Subiendo al bus", statusLbl=statusLbl,mainExperiment = mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Boarding the bus", statusLbl=statusLbl,mainExperiment = mainExperiment)
# trajectoryToFirstBusStop = its.createTrajectory(origin=trajectory.origin, destination=firstBusStop.position,
# clockwise=trajectory.isClockwise(), speed=trajectory.speed)['trajectory']
# trajectoryBus = copy.copy(trajectoryToFirstBusStop)
firstBusStop.icon.setPicture("")
person.icon.setVisible(True)
person.icon.raise_()
#This timer's operations allows to generate the dwell time at the bus stop
myTimer.setSingleShot(True)
myTimer.setInterval(firstBusStop.getDwellTime()*1000) #1 second of detention
myTimer.start()
firstBusStop.visited = True
#Create a new icon picture using the bus image
personBusIcon = PersonIcon(parent = bus.icon.parent,id = bus.icon.id, path = bus.icon.path
, realNetwork = bus.icon.realNetwork,virtualNetwork = bus.icon.virtualNetwork,
position = person.position,width = person.icon.width,height = person.icon.height)
personWalkingIcon = PersonIcon(parent = person.icon.parent,id = person.icon.id, path = person.icon.path
, realNetwork = person.icon.realNetwork,virtualNetwork = person.icon.virtualNetwork,
position = person.position,width = person.icon.width,height = person.icon.height)
person.addIcon(personBusIcon)
person.addIcon(personWalkingIcon)
# person.setPictureIcon(person.icons[personBusIcon.id].path)
# # Move the bus to the next position
# its.moveBus(trajectory=trajectoryBus, bus=bus)
#If the bus has not arrived yet to the bus stop where the passenger is getting off
elif its.isNextPositionAhead(trajectory = trajectory,currentPosition = bus.position, nextPosition = lastBusStop) == True:
bus.icon.setVisible(True)
person.icon.setPicture(person.icons["walking"].path)
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Viajando al destino", statusLbl=statusLbl,mainExperiment = mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Travelling to destination", statusLbl=statusLbl,mainExperiment = mainExperiment)
firstBusStop.icon.setPicture(firstBusStop.icon.originalPath)
person.icon.setVisible(False)
trajectoryToLastBusStop = its.createTrajectory(origin=trajectory.origin, destination=lastBusStop.position,
clockwise=trajectory.isClockwise(),
speed=trajectory.speed)['trajectory']
trajectoryBus = copy.copy(trajectoryToLastBusStop)
trajectoryPerson = copy.copy(trajectoryBus)
its.movePerson(trajectory=trajectoryPerson, person=person, isWalking=False)
# Move the bus to the next position
its.moveBus(trajectory=trajectoryBus, bus=bus)
# If the bus has arrived to the bus stop where the passenger is getting off
elif its.equalPositions(bus.position,lastBusStop.position) == True and lastBusStop.visited == False:
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Bajando del bus", statusLbl=statusLbl,mainExperiment = mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Getting off the bus", statusLbl=statusLbl,mainExperiment = mainExperiment)
person.icon.setVisible(True)
bus.icon.setVisible(False)
person.icon.setPicture(person.icons["alightingBus"].path)
lastBusStop.icon.setPicture("")
trajectoryToLastBusStop = its.createTrajectory(origin=trajectory.origin, destination=lastBusStop.position,
clockwise=trajectory.isClockwise(),
speed=trajectory.speed)['trajectory']
trajectoryBus = copy.copy(trajectoryToLastBusStop)
# myTimer.stop()
myTimer.setInterval(lastBusStop.getDwellTime()*1000) #1 second of detention
myTimer.setSingleShot(True)
myTimer.start()
lastBusStop.visited = True
#Update the picture of the passenger because it got off from the bus.
# person.setPictureIcon(person.icons[person.icon.id].path)
# Move the bus to the next position
its.moveBus(trajectory=trajectoryBus, bus=bus)
# If the bus is departing the last bus stop and arriving to the arrival terminal
else:
person.icon.setPicture(person.icons["walking"].path)
bus.icon.setVisible(False)
if mainExperiment.languageCondition == "spanish":
updateStatusSimulationExpPage(status="Caminando al destino", statusLbl=statusLbl,mainExperiment = mainExperiment)
if mainExperiment.languageCondition == "english":
updateStatusSimulationExpPage(status="Walking to destination", statusLbl=statusLbl,mainExperiment = mainExperiment)
lastBusStop.icon.setPicture(lastBusStop.icon.originalPath)
# Move the bus to the next position
trajectoryBus = copy.copy(trajectory)
its.moveBus(trajectory=trajectoryBus, bus=bus)
#Move the person
person.speed = person.walkingSpeed
personMovingUI(person, destination = person.finalLocation.position, clockwise = trajectoryBus.isClockwise(), myTimer = personTimer, its = its, isWalking = True, mainExperiment = mainExperiment)
#When the bus arrive to the bus terminal
if its.equalPositions(bus.position,bus.route.arrivalTerminal.position):
bus.icon.setVisible(False)
#When the person arrive to the final destination
if its.equalPositions(person.position, person.finalLocation.position):
myTimer.stop() #This stopped the timer for the bustrip. Then the thread will continue and will stop the timer of the person
#Reset values of booleans variables
firstBusStop.visited = False
lastBusStop.visited = False
person.icon.setVisible(False)
if not mainExperiment.isLastTrial(mainExperiment.currentExperiment):
nextJourneyButton.setVisible(False)
nextJourneyClicked()
else:
nextJourneyButton.setVisible(True)
lastUpdateLearningPhase(mainExperiment = mainExperiment, statusLbl = statusLbl)
ui.simulationExpGrid.itemAtPosition(0, 0).widget().setText("")
# completed = Fals
# stop.icon.setPicture("Pictures/stop1.png")
def updateStatusSimulationExpPage(status, statusLbl, mainExperiment):
# Update Status
if mainExperiment.languageCondition == "spanish":
statusLbl.setText("Estado: " + status)
if mainExperiment.languageCondition == "english":
statusLbl.setText("Status: " + status)