temps d arret

This commit is contained in:
leo 2022-05-05 16:49:53 +02:00
parent 48bb475e0b
commit 578c433f99
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
5 changed files with 37 additions and 9 deletions

6
Car.py
View File

@ -54,9 +54,10 @@ class Car():
self.v=0
self.a=10
self.b=20
self.minSpace=1
self.minSpace=10
self.leaderBefore=False
self.distToInter=0
self.timeStopped=0
self.vmax=0
@ -418,6 +419,9 @@ class Car():
self.conduiteKrauss(self.vmax,self.leader,dt)
if self.v == 0:
self.timeStopped += dt
lgt=self.v*dt
self.dir = atan2(self.laneShape[self.laneInd+1][1]-self.pos[1],self.laneShape[self.laneInd+1][0]-self.pos[0])

View File

@ -102,6 +102,8 @@ class CarController:
self.t=0
self.dt=1/60
self.spawnFailed = 0
self.totalStopped = 0
self.carsDestroyed = 0
self.infoWidget = None
@ -174,7 +176,7 @@ class CarController:
self.cars.append(flow.spawnCar())
else:
self.spawnFailed += 1
flow.addCar2Counter()
#flow.addCar2Counter()
flow.priority += 1
print(f"nope, y as déjà une voiture ici : n°{self.spawnFailed}")
@ -191,6 +193,8 @@ class CarController:
car.draw(painter)
def destroyCar(self, car):
self.carsDestroyed += 1
self.totalStopped += car.timeStopped
self.cars.remove(car)
def updateConstant(self, name, val):

View File

@ -78,6 +78,13 @@ class MainWindow(QMainWindow):
widget.setText(f"fps : {1000/t:.1f}")
widget.update()
widget = self.findChild(QLabel, "timeStopped")
controller = self.mainLoop.controller
if controller.carsDestroyed==0:
return
averageTimeStopped = controller.totalStopped / controller.carsDestroyed
widget.setText(f"temps d'arrêt : {averageTimeStopped:.2f}s/voiture \n nombre de voitures qui n'ont pas pu apparaitre : {controller.spawnFailed}")
@Slot(int)
def updatePhysicsFps(self,t):
widget = self.findChild(QLabel,"physicsFPS")

View File

@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'window.ui'
##
## Created by: Qt User Interface Compiler version 6.2.3
## Created by: Qt User Interface Compiler version 6.3.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
@ -27,7 +27,7 @@ class Ui_MainWindow(object):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(540, 360)
MainWindow.resize(886, 675)
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.gridLayout = QGridLayout(self.centralwidget)
@ -93,6 +93,11 @@ class Ui_MainWindow(object):
self.generalInfos.addLayout(self.horizontalLayout_4)
self.timeStopped = QLabel(self.centralwidget)
self.timeStopped.setObjectName(u"timeStopped")
self.generalInfos.addWidget(self.timeStopped)
self.horizontalLayout_2 = QHBoxLayout()
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.startButton = QPushButton(self.centralwidget)
@ -136,7 +141,7 @@ class Ui_MainWindow(object):
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MainWindow)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 540, 27))
self.menubar.setGeometry(QRect(0, 0, 886, 27))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QStatusBar(MainWindow)
self.statusbar.setObjectName(u"statusbar")
@ -154,6 +159,7 @@ class Ui_MainWindow(object):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.mainFps.setText(QCoreApplication.translate("MainWindow", u"Display fps", None))
self.physicsFPS.setText(QCoreApplication.translate("MainWindow", u"Physics FPS", None))
self.timeStopped.setText(QCoreApplication.translate("MainWindow", u"Time stopped", None))
self.startButton.setText(QCoreApplication.translate("MainWindow", u"Start", None))
self.stopButton.setText(QCoreApplication.translate("MainWindow", u"Stop", None))
# retranslateUi

View File

@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>360</height>
<width>886</width>
<height>675</height>
</rect>
</property>
<property name="windowTitle">
@ -42,7 +42,7 @@
<layout class="QVBoxLayout" name="constEdit"/>
</item>
<item>
<layout class="QVBoxLayout" name="generalInfos" stretch="0,0,0">
<layout class="QVBoxLayout" name="generalInfos" stretch="0,0,0,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="2,1">
<item>
@ -85,6 +85,13 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="timeStopped">
<property name="text">
<string>Time stopped</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
@ -132,7 +139,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<width>886</width>
<height>27</height>
</rect>
</property>