3
3
from PyQt5 .QtWidgets import QMainWindow , QApplication
4
4
from PyQt5 .QtCore import QUrl , QThread , pyqtSignal
5
5
from PyQt5 .QtWidgets import QApplication , QFileDialog
6
-
6
+ import pyqtgraph as pg
7
7
import numpy as np
8
8
from time import sleep
9
9
@@ -21,6 +21,7 @@ def __init__(self):
21
21
self .loadButton .clicked .connect (self .chooseFile )
22
22
self .clearButton .clicked .connect (self .clear )
23
23
self .solveButton .clicked .connect (self .solveSudoku )
24
+ self .compareButton .clicked .connect (self .compareSudoku )
24
25
25
26
def chooseFile (self ):
26
27
self .filePath , self .filetype = QFileDialog .getOpenFileName (
@@ -87,6 +88,15 @@ def setInfo(self, msg):
87
88
"main: {}\n " .format (msg ))
88
89
self .logScreen .ensureCursorVisible ()
89
90
91
+ def compareSudoku (self ):
92
+ con = False
93
+ with open ('fiveThreadLog.txt' , 'r' ) as file :
94
+ con = True if file .readline () else False
95
+ with open ('tenThreadLog.txt' , 'r' ) as file :
96
+ con = True if file .readline () else False
97
+ if con :
98
+ graphObject = CompareSudokuGraph (self )
99
+
90
100
def startLoad (self ):
91
101
if self .threadRadioButton5 .isChecked ():
92
102
self .fiveThreadObject = FiveThreadOptions (self )
@@ -121,7 +131,7 @@ def solveSudoku(self):
121
131
if self .threadCount == 5 :
122
132
self .fiveThreadObject .solveSudoku ()
123
133
elif self .threadCount == 10 :
124
- pass
134
+ self . tenThreadObject . solveSudoku ()
125
135
else :
126
136
self .setInfo ("Unknow Error!" )
127
137
@@ -131,6 +141,63 @@ def setClickables(self, status):
131
141
self .clearButton .setEnabled (status )
132
142
self .threadRadioButton5 .setEnabled (status )
133
143
self .threadRadioButton10 .setEnabled (status )
144
+ self .compareButton .setEnabled (status )
145
+
146
+
147
+ class CompareSudokuGraph ():
148
+ def __init__ (self , GUI ):
149
+ self .gui = GUI
150
+ self .SEC_AXIS_RANGE = 7
151
+ self .fiveTGraphSeconds = []
152
+ self .tenTGraphSeconds = []
153
+ self .fiveTGraphCount = []
154
+ self .tenTGraphCount = []
155
+ self .getDatafromTxt ()
156
+ self .createGraphics ()
157
+
158
+ def getDatafromTxt (self ):
159
+ with open ('fiveThreadLog.txt' , 'r' ) as file :
160
+ line = file .readline ()
161
+ if line [0 ] == 'g' :
162
+ self .fiveTGraphSeconds .append (line .split ("_" )[1 ])
163
+ self .fiveTGraphCount .append (line .split ("_" )[2 ])
164
+ with open ('tenThreadLog.txt' , 'r' ) as file :
165
+ line = file .readline ()
166
+ if line [0 ] == 'g' :
167
+ self .tenTGraphSeconds .append (float (line .split ("_" )[1 ]))
168
+ self .tenTGraphCount .append (float (line .split ("_" )[2 ]))
169
+
170
+ def createGraphics (self ):
171
+ self .createAxisLabels ()
172
+ self .createPlotWidgets ()
173
+
174
+ def createAxisLabels (self ):
175
+ self .gui .sudokuGraph .setLabel (
176
+ axis = 'left' , text = 'Count' )
177
+ self .gui .sudokuGraph .setLabel (
178
+ axis = 'bottom' , text = 'Second' )
179
+
180
+ def createPlotWidgets (self ):
181
+ self .pen = pg .mkPen ('r' , width = 3 )
182
+ self .pen2 = pg .mkPen ('b' , width = 3 )
183
+ self .sudokuGW = self .gui .sudokuGraph
184
+
185
+ # five thread
186
+ self .secondFT = self .fiveTGraphSeconds
187
+ self .cellCountFT = self .fiveTGraphCount
188
+ self .dataLine = self .sudokuGW .plot (
189
+ self .secondFT , self .cellCountFT , pen = self .pen )
190
+
191
+ # ten threads
192
+ self .secondTT = self .tenTGraphSeconds
193
+ self .cellCountTT = self .tenTGraphCount
194
+ self .dataLine = self .sudokuGW .plot (
195
+ self .secondTT , self .cellCountTT , pen = self .pen2 )
196
+
197
+ if len (self .fiveTGraphSeconds ) > len (self .tenTGraphSeconds ):
198
+ self .sudokuGW .setXRange (0 , len (self .fiveTGraphSeconds ))
199
+ else :
200
+ self .sudokuGW .setXRange (0 , len (self .tenTGraphSeconds ))
134
201
135
202
136
203
class ClearCellWorker (QThread ):
0 commit comments