Commit 91508a74 authored by 曹高翔's avatar 曹高翔
Browse files

完成历史记录页面

parent 3ac382d4
from datetime import datetime, timedelta
from re import search
from sys import platform
from PyQt5.QtCore import Qt, QSize, QThread, pyqtSignal
from PyQt5.QtGui import QFont
......@@ -10,10 +11,10 @@ from PyQt5.QtWidgets import QMessageBox, QMainWindow, QApplication
from codiaclient import net_var
from codiaclient.network import get_pack, show_pack, start_pack, logined, get_exercise
from codiaclient.network import submit,get_data
from codiaclient.network import submit, get_data
from codiaclient.report import Error as codiaError, error_translate
from codiaclient.requests import variables as requests_var
from codiaclientgui.utils import QPalette, Font, Palette, Style, Color, ErrorDisplay, NewListWidget
from codiaclientgui.utils import QPalette, Font, Palette, Style, ErrorDisplay, NewListWidget
from mainWindow import Ui_windowMain
variables = {
......@@ -23,8 +24,11 @@ variables = {
"firstPid": None,
"hasNext": True,
"packInfo": {},
"currentPackRow": None,
"currentPackRow": 0,
"currentHistoryRow": 0,
"exerciseInfo": None,
"submitHistory": [],
"testDataCount": 0,
"workingStatus": {
"frameExerciseInit": False,
"frameQuestionInit": False,
......@@ -47,6 +51,7 @@ toDisplay = {
}
toData = {val: key for key, val in toDisplay.items()}
class MyThread(QThread):
infoSignal = pyqtSignal([dict], [list])
errorSignal = pyqtSignal(codiaError)
......@@ -312,11 +317,17 @@ def BeginMain(callback=None):
uiMain.frameQuestion.hide()
uiMain.frameHistory.hide()
uiMain.frameSubmit.hide()
uiMain.frameExercise.hide()
uiMain.frameCode.hide()
uiMain.frameTestData.hide()
uiMain.progressBarPack.setStyleSheet(Style["progressBar"])
uiMain.progressBarExercise.setStyleSheet(Style["progressBar"])
uiMain.progressBarSubmit.setStyleSheet(Style["progressBar"])
uiMain.progressBarHistory.setStyleSheet(Style["progressBar"])
uiMain.textEditSubmit.setTabStopWidth(uiMain.textEditSubmit.font().pointSize() * 2)
if platform == 'win32':
uiMain.textEditSubmit.setTabStopWidth(uiMain.textEditSubmit.font().pointSize() * 4)
else:
uiMain.textEditSubmit.setTabStopWidth(uiMain.textEditSubmit.font().pointSize() * 2)
codeFont = QFont()
codeFont.setFamily('Consolas')
uiMain.textEditSubmit.setFont(codeFont)
......@@ -328,6 +339,7 @@ def BeginMain(callback=None):
uiMain.pushButtonExerciseBegin.clicked.connect(BeginPack)
# uiMain.listWidgetExercise.itemClicked.connect(getSelectedEid)
uiMain.listWidgetExercise.itemDoubleClicked.connect(frameQuestionInit)
uiMain.listWidgetPackHistory.itemDoubleClicked.connect(frameTestDataInit)
uiMain.pushButtonExerciseOK.clicked.connect(frameQuestionInit)
uiMain.pushButtonQuestionReturn.clicked.connect(QuestionReturn)
uiMain.pushButtonSubmit.clicked.connect(SubmitInit)
......@@ -341,19 +353,109 @@ def BeginMain(callback=None):
)
uiMain.pushButtonHistory.clicked.connect(frameHistoryInit)
uiMain.pushButtonHistoryBack.clicked.connect(HistoryReturn)
uiMain.pushButtonCodeBack.clicked.connect(CodeReturn)
uiMain.pushButtonTestDataBack.clicked.connect(TestDataReturn)
uiMain.pushButtonShowCode.clicked.connect(ShowCode)
uiMain.pushButtonShowTestData.clicked.connect(ShowTestData)
uiMain.pushButtonSubmitCodeDetails.clicked.connect(frameTestDataInit)
for i in range(0, variables['packPerPage']):
AddItemToPackList(uiMain.listWidgetPack)
uiMain.frameExercise.hide()
uiMain.framePack.show()
callback and callback()
def frameCodeInit():
code = variables['submitHistory'][variables['currentHistoryRow']]['solution']['asset']['content']
uiMain.textEditCode.setText(code)
if platform == 'win32':
uiMain.textEditCode.setTabStopWidth(uiMain.textEditSubmit.font().pointSize() * 4)
else:
uiMain.textEditCode.setTabStopWidth(uiMain.textEditSubmit.font().pointSize() * 2)
def frameTestDataInit():
if not uiMain.listWidgetPackHistory.selectedItems():
QMessageBox.information(None, '提示', '请选中一条历史记录', QMessageBox.Ok)
return
variables['currentHistoryRow'] = uiMain.listWidgetPackHistory.selectedIndexes()[0].row()
testData = variables['submitHistory'][variables['currentHistoryRow']]['submission']['reports']
index = 1
for data in testData:
if data['key'] == 'score':
variables['testDataCount'] = int(data['value'].split('/')[1])
uiMain.listWidgetData.clear()
for data in testData:
if data['key'] != 'score' and data['key'] != 'time elapsed' and data['key'] != 'memory consumed':
AddItemToTestDataList(index, data['value'])
index += 1
uiMain.frameHistory.hide()
uiMain.frameTestData.show()
def AddItemToTestDataList(index: int, status: str):
item = QListWidgetItem()
item.setSizeHint(QSize(960, 65))
widget = GetTestDataWidGet(index, status)
uiMain.listWidgetData.addItem(item)
uiMain.listWidgetData.setItemWidget(item, widget)
def GetTestDataWidGet(index: int, status: str):
mainLayout = QHBoxLayout()
statusLabel = QLabel()
testDataLabel = QLabel()
getScoreLabel = QLabel()
statusLabel.setText(toDisplay[status])
SetStatusColor(statusLabel)
testDataLabel.setText(f"测试点 {index}")
if status == 'passed':
getScoreLabel.setText("得分:%.1f" % (100/variables['testDataCount']))
else:
getScoreLabel.setText("得分:0")
mainLayout.addWidget(testDataLabel)
mainLayout.addWidget(statusLabel)
mainLayout.addWidget(getScoreLabel)
mainLayout.setStretchFactor(testDataLabel, 1)
mainLayout.setStretchFactor(statusLabel, 2)
mainLayout.setStretchFactor(getScoreLabel, 1)
widget = QWidget()
widget.setLayout(mainLayout)
widget.setCursor(Qt.PointingHandCursor)
return widget
def ShowCode():
frameCodeInit()
uiMain.frameTestData.hide()
uiMain.frameCode.show()
def ShowTestData():
uiMain.frameCode.hide()
uiMain.frameTestData.show()
def CodeReturn():
uiMain.frameCode.hide()
uiMain.frameHistory.show()
def TestDataReturn():
uiMain.frameTestData.hide()
uiMain.frameHistory.show()
def HistoryReturn():
uiMain.frameHistory.hide()
uiMain.frameQuestion.show()
def GetHistory(eid, pid, cnt, InfoRecv=lambda: None, ErrorRecv=lambda: None):
global threadGetHistory # extremely essential!
threadGetHistory = MyThread(RunMethod=lambda: get_data(eid=eid, pid=pid, codecnt=cnt))
......@@ -362,6 +464,7 @@ def GetHistory(eid, pid, cnt, InfoRecv=lambda: None, ErrorRecv=lambda: None):
uiMain.progressBarHistory.setValue(90)
threadGetHistory.start()
def frameHistoryInit():
totalCount = variables['exerciseListInfo'][variables['currentExerciseRow']]['viewerStatus']['totalCount']
uiMain.progressBarHistory.setValue(0)
......@@ -383,7 +486,8 @@ def frameHistoryInit():
ErrorDisplay(e, error_translate, "获取失败")
uiMain.progressBarHistory.hide()
GetHistory(eid=requests_var['e'], pid=requests_var['p'], cnt=totalCount, InfoRecv = historyInfoRecv, ErrorRecv=ErrorRecv)
GetHistory(eid=requests_var['e'], pid=requests_var['p'], cnt=totalCount, InfoRecv=historyInfoRecv,
ErrorRecv=ErrorRecv)
def AddItemToHistoryList(data: dict):
......@@ -405,6 +509,7 @@ def GetHistoryWidget(data: dict):
codeLengthLabel = QLabel()
timeElapsedLabel = QLabel()
spaceElapsedLabel = QLabel()
scoreLabel = QLabel()
if data['scoreRate'] == 1:
statusLabel.setText('通过')
......@@ -421,10 +526,11 @@ def GetHistoryWidget(data: dict):
errorType = i['value']
break
statusLabel.setText(toDisplay[errorType])
SetErrorColor(statusLabel)
SetStatusColor(statusLabel)
languageLabel.setText(toDisplay[data['solution']['lang']])
scoreLabel.setText('得分:%.1f' % (data['scoreRate'] * 100))
timeLabel.setText('提交时间:' +
(datetime.strptime(search(r"^[^.]*", data["time"].replace("T", " ")).group(),
(datetime.strptime(search(r"^[^.]*", data["time"].replace("T", " ")).group(),
"%Y-%m-%d %H:%M:%S") + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S"))
codeLengthLabel.setText('代码长度:' + str(len(data['solution']['asset']['content'])) + ' B')
for i in data['submission']['reports']:
......@@ -441,12 +547,14 @@ def GetHistoryWidget(data: dict):
mainLayout.addWidget(timeLabel)
mainLayout.addWidget(codeLengthLabel)
mainLayout.addLayout(elapseLayout)
mainLayout.addWidget(scoreLabel)
mainLayout.setStretchFactor(statusLabel, 2)
mainLayout.setStretchFactor(languageLabel, 1)
mainLayout.setStretchFactor(timeLabel, 4)
mainLayout.setStretchFactor(codeLengthLabel, 2)
mainLayout.setStretchFactor(elapseLayout, 4)
mainLayout.setStretchFactor(elapseLayout, 3)
mainLayout.setStretchFactor(scoreLabel, 2)
widget = QWidget()
widget.setLayout(mainLayout)
......@@ -456,13 +564,15 @@ def GetHistoryWidget(data: dict):
return widget
def SetErrorColor(statusLabel: QLabel):
def SetStatusColor(statusLabel: QLabel):
if statusLabel.text() == '答案错误':
statusLabel.setPalette(Palette[QPalette.Text]["red"])
elif statusLabel.text() == '运行时错误':
statusLabel.setPalette(Palette[QPalette.Text]["purple"])
elif statusLabel.text() == '超时':
statusLabel.setPalette(Palette[QPalette.Text]["darkblue"])
elif statusLabel.text() == '通过':
statusLabel.setPalette(Palette[QPalette.Text]["green"])
else:
statusLabel.setPalette(Palette[QPalette.Text]["gray"])
......@@ -513,6 +623,7 @@ def SubmitReturn():
uiMain.frameSubmit.hide()
uiMain.frameQuestion.show()
def Submit(pid, eid, lang, code, InfoRecv=lambda: None, ErrorRecv=lambda: None):
global threadSubmit # extremely essential!
threadSubmit = MyThread(RunMethod=lambda: submit(eid=eid, pid=pid, lang=lang, solutioncode=code))
......@@ -521,6 +632,7 @@ def Submit(pid, eid, lang, code, InfoRecv=lambda: None, ErrorRecv=lambda: None):
uiMain.progressBarSubmit.setValue(90)
threadSubmit.start()
def SubmitCode(lang: str, code: str):
if lang == '请选择提交语言':
QMessageBox.information(None, '提示', '请选择一种提交语言。', QMessageBox.Ok)
......@@ -536,14 +648,15 @@ def SubmitCode(lang: str, code: str):
def submitInfoRecv(submitInfo):
if submitInfo:
QMessageBox.information(None, '提交成功', '提交成功,请在历史记录中查看评测结果', QMessageBox.Ok)
variables['exerciseListInfo'][variables['currentExerciseRow']]['viewerStatus']['totalCount']
variables['exerciseListInfo'][variables['currentExerciseRow']]['viewerStatus']['totalCount'] += 1
uiMain.frameSubmit.hide()
uiMain.frameQuestion.show()
else:
QMessageBox.critical(None, '提交失败', '请检查语言选择是否正确', QMessageBox.Ok)
uiMain.progressBarSubmit.hide()
Submit(pid=requests_var['p'], eid=requests_var['e'], lang=toData[lang], code=code, InfoRecv=submitInfoRecv, ErrorRecv=ErrorRecv)
Submit(pid=requests_var['p'], eid=requests_var['e'], lang=toData[lang], code=code, InfoRecv=submitInfoRecv,
ErrorRecv=ErrorRecv)
def SubmitInit():
......@@ -593,7 +706,7 @@ def GetPack(before=None, after=None, InfoRecv=lambda: None, ErrorRecv=lambda: No
# 翻页
def GetPage(before=None, after=None):
if before and after:
return False
return False
uiMain.progressBarPack.setValue(0)
uiMain.progressBarPack.show()
uiMain.pushButtonPackNext.setEnabled(False)
......
......@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'mainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
......@@ -170,14 +170,49 @@ class Ui_windowMain(object):
self.pushButtonHistoryBack = NewPushButton(self.frameHistory)
self.pushButtonHistoryBack.setGeometry(QtCore.QRect(890, 630, 120, 32))
self.pushButtonHistoryBack.setObjectName("pushButtonHistoryBack")
self.frameCode = QtWidgets.QFrame(self.centralwidget)
self.frameCode.setGeometry(QtCore.QRect(0, 0, 1080, 768))
self.frameCode.setMinimumSize(QtCore.QSize(1080, 768))
self.frameCode.setMaximumSize(QtCore.QSize(1280, 768))
self.frameCode.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frameCode.setFrameShadow(QtWidgets.QFrame.Raised)
self.frameCode.setObjectName("frameCode")
self.textEditCode = QtWidgets.QTextEdit(self.frameCode)
self.textEditCode.setGeometry(QtCore.QRect(28, 30, 1024, 531))
self.textEditCode.setReadOnly(True)
self.textEditCode.setObjectName("textEditCode")
self.pushButtonShowTestData = NewPushButton(self.frameCode)
self.pushButtonShowTestData.setGeometry(QtCore.QRect(390, 630, 120, 32))
self.pushButtonShowTestData.setObjectName("pushButtonShowTestData")
self.pushButtonCodeBack = NewPushButton(self.frameCode)
self.pushButtonCodeBack.setGeometry(QtCore.QRect(700, 630, 120, 32))
self.pushButtonCodeBack.setObjectName("pushButtonCodeBack")
self.frameTestData = QtWidgets.QFrame(self.centralwidget)
self.frameTestData.setGeometry(QtCore.QRect(0, 0, 1080, 768))
self.frameTestData.setMinimumSize(QtCore.QSize(1080, 768))
self.frameTestData.setMaximumSize(QtCore.QSize(1280, 768))
self.frameTestData.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frameTestData.setFrameShadow(QtWidgets.QFrame.Raised)
self.frameTestData.setObjectName("frameTestData")
self.pushButtonShowCode = NewPushButton(self.frameTestData)
self.pushButtonShowCode.setGeometry(QtCore.QRect(390, 630, 120, 32))
self.pushButtonShowCode.setObjectName("pushButtonShowCode")
self.pushButtonTestDataBack = NewPushButton(self.frameTestData)
self.pushButtonTestDataBack.setGeometry(QtCore.QRect(700, 630, 120, 32))
self.pushButtonTestDataBack.setObjectName("pushButtonTestDataBack")
self.listWidgetData = NewListWidget(self.frameTestData)
self.listWidgetData.setGeometry(QtCore.QRect(28, 30, 1024, 531))
self.listWidgetData.setObjectName("listWidgetData")
self.framePack.raise_()
self.frameExercise.raise_()
self.frameSubmit.raise_()
self.frameQuestion.raise_()
self.frameHistory.raise_()
self.frameQuestion.raise_()
self.frameSubmit.raise_()
self.frameCode.raise_()
self.frameTestData.raise_()
windowMain.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(windowMain)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1080, 26))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1080, 24))
self.menubar.setObjectName("menubar")
windowMain.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(windowMain)
......@@ -208,7 +243,11 @@ class Ui_windowMain(object):
self.labelSubmitStatus.setText(_translate("windowMain", "通过/尝试"))
self.pushButtonSubmitCode.setText(_translate("windowMain", "提交"))
self.pushButtonSubmitBack.setText(_translate("windowMain", "返回"))
self.pushButtonReadFromFile.setText(_translate("windowMain", "从文件中读取"))
self.pushButtonSubmitCodeDetails.setText(_translate("windowMain", "详细信息"))
self.pushButtonReadFromFile.setText(_translate("windowMain", "读取文件"))
self.pushButtonSubmitCodeDetails.setText(_translate("windowMain", "确认"))
self.pushButtonHistoryBack.setText(_translate("windowMain", "返回"))
self.pushButtonShowTestData.setText(_translate("windowMain", "测试点"))
self.pushButtonCodeBack.setText(_translate("windowMain", "返回"))
self.pushButtonShowCode.setText(_translate("windowMain", "代码"))
self.pushButtonTestDataBack.setText(_translate("windowMain", "返回"))
from codiaclientgui.utils import NewListWidget, NewProgressBar, NewPushButton
......@@ -497,7 +497,7 @@
</rect>
</property>
<property name="text">
<string>从文件中读取</string>
<string>读取文件</string>
</property>
</widget>
</widget>
......@@ -558,7 +558,7 @@
</rect>
</property>
<property name="text">
<string>详细信息</string>
<string>确认</string>
</property>
</widget>
<widget class="NewPushButton" name="pushButtonHistoryBack">
......@@ -575,11 +575,144 @@
</property>
</widget>
</widget>
<widget class="QFrame" name="frameCode">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1080</width>
<height>768</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>1080</width>
<height>768</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1280</width>
<height>768</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QTextEdit" name="textEditCode">
<property name="geometry">
<rect>
<x>28</x>
<y>30</y>
<width>1024</width>
<height>531</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="NewPushButton" name="pushButtonShowTestData">
<property name="geometry">
<rect>
<x>390</x>
<y>630</y>
<width>120</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>测试点</string>
</property>
</widget>
<widget class="NewPushButton" name="pushButtonCodeBack">
<property name="geometry">
<rect>
<x>700</x>
<y>630</y>
<width>120</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>返回</string>
</property>
</widget>
</widget>
<widget class="QFrame" name="frameTestData">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1080</width>
<height>768</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>1080</width>
<height>768</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1280</width>
<height>768</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="NewPushButton" name="pushButtonShowCode">
<property name="geometry">
<rect>
<x>390</x>
<y>630</y>
<width>120</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>代码</string>
</property>
</widget>
<widget class="NewPushButton" name="pushButtonTestDataBack">
<property name="geometry">
<rect>
<x>700</x>
<y>630</y>
<width>120</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>返回</string>
</property>
</widget>
<widget class="NewListWidget" name="listWidgetData">
<property name="geometry">
<rect>
<x>28</x>
<y>30</y>
<width>1024</width>
<height>531</height>
</rect>
</property>
</widget>
</widget>
<zorder>framePack</zorder>
<zorder>frameExercise</zorder>
<zorder>frameSubmit</zorder>
<zorder>frameQuestion</zorder>
<zorder>frameHistory</zorder>
<zorder>frameQuestion</zorder>
<zorder>frameSubmit</zorder>
<zorder>frameCode</zorder>
<zorder>frameTestData</zorder>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
......@@ -587,7 +720,7 @@
<x>0</x>
<y>0</y>
<width>1080</width>
<height>26</height>
<height>24</height>
</rect>
</property>
</widget>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment