Skip to content

Commit

Permalink
GUI: Add running time of algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
RozeQz committed Apr 14, 2024
1 parent d183898 commit fef6880
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 37 deletions.
22 changes: 22 additions & 0 deletions client/gui/graph_page.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import List
import os
import time
import numpy as np
import networkx as nx

from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import (
QVBoxLayout,
QWidget,
Expand All @@ -29,6 +31,16 @@ def __init__(self, parent=None):

self.graph = None

# Путь к ассетам
path = os.getcwd() + "/client/gui/resources/"

# Отображение картинок
self.ui.lbl_clock.setPixmap(QPixmap(path + "img/clock.png"))

# Изначально время скрыто
self.ui.lbl_clock.setVisible(False)
self.ui.lbl_time.setVisible(False)

# Добавляем место для графа на страницу
self.graph_layout = QVBoxLayout()
self.ui.horizontalLayout.insertLayout(0, self.graph_layout)
Expand Down Expand Up @@ -91,6 +103,9 @@ def embed_graph(self):
self.canvas.axes.cla()

alogithm = self.ui.cbx_algorithm.currentIndex()

start = time.time()

# Гамма-алгоритм
if alogithm == 0:
gr = GammaAlgorithm(self.graph)
Expand Down Expand Up @@ -124,3 +139,10 @@ def embed_graph(self):
nx.draw(G, pos=pos, ax=self.canvas.axes,
with_labels=True, node_color="#0C8CE9")
self.canvas.draw()

finish = time.time()
res = finish - start
res_msec = res * 1000
self.ui.lbl_time.setText(f"Время работы: {res_msec:.2f} миллисекунд")
self.ui.lbl_time.setVisible(True)
self.ui.lbl_clock.setVisible(True)
5 changes: 5 additions & 0 deletions client/gui/resources/styles/main.qss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ GraphPage QLabel {
font-weight: 75;
color: rgb(0, 0, 0);
text-align: left;
margin-left: 0;
}

TestPage QLabel {
Expand All @@ -71,24 +72,28 @@ TestStartPage QLabel {
font-weight: 75;
color: rgb(0, 0, 0);
margin-bottom: 40px;
margin-left: 0;
}

ProfilePage QLabel {
font-size: 16pt;
font-weight: 75;
color: rgb(0, 0, 0);
margin-left: 0;
}

StudentProfilePage QLabel {
font-size: 16pt;
font-weight: 75;
color: rgb(0, 0, 0);
margin-left: 0;
}

TaskPage QLabel {
font-size: 16pt;
font-weight: 75;
color: rgb(0, 0, 0);
margin-left: 0;
}

QWidget QLabel:hover {
Expand Down
33 changes: 30 additions & 3 deletions client/gui/ui_graph_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ def setupUi(self, GraphPage):
self.btn_draw = QtWidgets.QPushButton(GraphPage)
self.btn_draw.setObjectName("btn_draw")
self.verticalLayout.addWidget(self.btn_draw)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.lbl_algorithm = QtWidgets.QLabel(GraphPage)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lbl_algorithm.sizePolicy().hasHeightForWidth())
self.lbl_algorithm.setSizePolicy(sizePolicy)
self.lbl_algorithm.setObjectName("lbl_algorithm")
self.verticalLayout.addWidget(self.lbl_algorithm)
self.horizontalLayout_4.addWidget(self.lbl_algorithm)
self.cbx_algorithm = QtWidgets.QComboBox(GraphPage)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
Expand All @@ -63,7 +65,31 @@ def setupUi(self, GraphPage):
self.cbx_algorithm.addItem("")
self.cbx_algorithm.addItem("")
self.cbx_algorithm.addItem("")
self.verticalLayout.addWidget(self.cbx_algorithm)
self.horizontalLayout_4.addWidget(self.cbx_algorithm)
self.verticalLayout.addLayout(self.horizontalLayout_4)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.lbl_clock = QtWidgets.QLabel(GraphPage)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lbl_clock.sizePolicy().hasHeightForWidth())
self.lbl_clock.setSizePolicy(sizePolicy)
self.lbl_clock.setMaximumSize(QtCore.QSize(20, 20))
self.lbl_clock.setText("")
self.lbl_clock.setPixmap(QtGui.QPixmap("resources/img/clock.png"))
self.lbl_clock.setScaledContents(True)
self.lbl_clock.setObjectName("lbl_clock")
self.horizontalLayout_3.addWidget(self.lbl_clock)
self.lbl_time = QtWidgets.QLabel(GraphPage)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lbl_time.sizePolicy().hasHeightForWidth())
self.lbl_time.setSizePolicy(sizePolicy)
self.lbl_time.setObjectName("lbl_time")
self.horizontalLayout_3.addWidget(self.lbl_time)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.btn_embed = QtWidgets.QPushButton(GraphPage)
self.btn_embed.setObjectName("btn_embed")
self.verticalLayout.addWidget(self.btn_embed)
Expand All @@ -83,4 +109,5 @@ def retranslateUi(self, GraphPage):
self.cbx_algorithm.setItemText(0, _translate("GraphPage", "Гамма-алгоритм"))
self.cbx_algorithm.setItemText(1, _translate("GraphPage", "Алгоритм, основанный на методе отжига"))
self.cbx_algorithm.setItemText(2, _translate("GraphPage", "Алгоритм на PQ-деревьях"))
self.lbl_time.setText(_translate("GraphPage", "Время работы алгоритма:"))
self.btn_embed.setText(_translate("GraphPage", "Уложить граф"))
112 changes: 79 additions & 33 deletions client/gui/ui_graph_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,91 @@
</widget>
</item>
<item>
<widget class="QLabel" name="lbl_algorithm">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Выберите алгоритм:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbx_algorithm">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<property name="text">
<string>Гамма-алгоритм</string>
</property>
<widget class="QLabel" name="lbl_algorithm">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Выберите алгоритм:</string>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Алгоритм, основанный на методе отжига</string>
</property>
<widget class="QComboBox" name="cbx_algorithm">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Гамма-алгоритм</string>
</property>
</item>
<item>
<property name="text">
<string>Алгоритм, основанный на методе отжига</string>
</property>
</item>
<item>
<property name="text">
<string>Алгоритм на PQ-деревьях</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<property name="text">
<string>Алгоритм на PQ-деревьях</string>
</property>
<widget class="QLabel" name="lbl_clock">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>resources/img/clock.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</widget>
<item>
<widget class="QLabel" name="lbl_time">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Время работы алгоритма:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="btn_embed">
Expand Down
2 changes: 1 addition & 1 deletion client/src/education/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ def is_misspell(correct_text, text) -> bool:
dl = textdistance.DamerauLevenshtein()
result = dl.normalized_distance(correct_text, text)

if result > 0.20:
if result > 0.3:
return False
return True

0 comments on commit fef6880

Please sign in to comment.