Commit 0effabf8 authored by 曹高翔's avatar 曹高翔
Browse files

为查看历史记录页面添加功能

parent 4db98d18
......@@ -38,7 +38,8 @@ displayLanguage = {
'passed': '通过',
'wrong answer': '答案错误',
'runtime error': '运行时错误',
"": '未知错误'
'time limit exceeds': "超时",
"": '正在评测'
}
dataLanguage = {val: key for key, val in displayLanguage.items()}
......@@ -297,6 +298,7 @@ def frameQuestionInit():
str(questionInfo['viewerStatus']['passedCount']) + '/' +
str(questionInfo['viewerStatus']['totalCount']))
uiMain.comboBoxLanguage.clear()
uiMain.comboBoxLanguage.addItem('请选择提交语言')
languages = [displayLanguage[lan] for lan in variables['exerciseInfo']['supportedLanguages']]
uiMain.comboBoxLanguage.addItems(languages)
uiMain.labelSubmitStatus.setText(uiMain.labelQuestionStatus.text())
......@@ -312,9 +314,9 @@ def frameQuestionInit():
uiMain.progressBarExercise.hide()
frameQuestionInitWorking = False
questionInfo = GetExercise(pid=requests_var['p'], eid=requests_var['e'],
lang='CPP', InfoRecv=ExerciseInfoRecv,
ErrorRecv=ErrorRecv)
GetExercise(pid=requests_var['p'], eid=requests_var['e'],
lang='CPP', InfoRecv=ExerciseInfoRecv,
ErrorRecv=ErrorRecv)
# 初始化任务,为做题窗口信号绑定槽函数
......@@ -361,9 +363,10 @@ def BeginMain(callback=None):
uiMain.pushButtonSubmitBack.clicked.connect(SubmitReturn)
uiMain.pushButtonSubmitFile.clicked.connect(SubmitFile)
uiMain.pushButtonReadFromFile.clicked.connect(
lambda : ReadFromFile(uiMain.comboBoxLanguageSubmit.currentText())
lambda: ReadFromFile(uiMain.comboBoxLanguageSubmit.currentText())
)
uiMain.pushButtonHistory.clicked.connect(frameHistoryInit)
uiMain.pushButtonHistoryBack.clicked.connect(HistoryReturn)
for i in range(0, variables['packPerPage']):
AddItemToPackList(uiMain.listWidgetPack, colorName=['white', 'lightgray'][i % 2])
......@@ -373,12 +376,46 @@ def BeginMain(callback=None):
callback and callback()
def HistoryReturn():
uiMain.frameHistory.hide()
uiMain.frameQuestion.show()
def frameHistoryInit():
results = get_data(requests_var['e'], requests_var['p'],
variables['exerciseListInfo'][variables['currentExerciseRow']]['viewerStatus']['totalCount']):
totalCount = variables['exerciseListInfo'][variables['currentExerciseRow']]['viewerStatus']['totalCount']
try:
results = get_data(requests_var['e'], requests_var['p'], totalCount)
except codiaError as e:
ErrorDisplay(e, error_translate, "获取失败")
return
results.reverse()
variables['submitHistory'] = results
uiMain.listWidgetPackHistory.clear()
for data in results:
AddItemToHistoryList(data)
uiMain.frameQuestion.hide()
uiMain.frameHistory.show()
def AddItemToHistoryList(data: dict):
item = QListWidgetItem()
item.setSizeHint(QSize(960, 65))
widget = GetHistoryWidget(data)
uiMain.listWidgetPackHistory.addItem(item)
uiMain.listWidgetPackHistory.setItemWidget(item, widget)
def GetHistoryWidget(data: dict):
if not data:
widget = QWidget()
layout = QHBoxLayout()
labelStatus = QLabel('评测中')
labelStatus.setAlignment(Qt.AlignCenter)
layout.addWidget(labelStatus)
widget.setLayout(layout)
return widget
mainLayout = QHBoxLayout()
elapseLayout = QVBoxLayout()
statusLabel = QLabel()
......@@ -386,25 +423,71 @@ def GetHistoryWidget(data: dict):
timeLabel = QLabel()
codeLengthLabel = QLabel()
timeElapsedLabel = QLabel()
spaceELapsedLabel = QLabel()
spaceElapsedLabel = QLabel()
if variables['submitHistory']['scoreRate'] == 1:
if data['scoreRate'] == 1:
statusLabel.setText('通过')
statusLabel.setPalette(Palette[QPalette.Text]["green"])
else:
errorType = ""
for i in variables['submitHistory']['submission']['reports']:
for i in data['submission']['reports']:
if i['key'] == 'error':
errorType = i['value']
statusLabel.setText(translation[errorType])
if not errorType:
for i in data['submission']['reports']:
if (i['value'] != 'passed' and i['value'] != 'memory consumed'
and i['value'] != 'time elapsed' and i['value'] != 'score'):
errorType = i['value']
break
statusLabel.setText(displayLanguage[errorType])
SetErrorColor(statusLabel)
languageLabel.setText(displayLanguage[data['solution']['lang']])
timeLabel.setText('提交时间:' +
(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']:
if i['key'] == 'memory consumed':
spaceElapsedLabel.setText('空间消耗:' + i['value'])
elif i['key'] == 'time elapsed':
timeElapsedLabel.setText('时间消耗:' + i['value'])
statusLabel.setAlignment(Qt.AlignCenter)
elapseLayout.addWidget(timeElapsedLabel)
elapseLayout.addWidget(spaceElapsedLabel)
mainLayout.addWidget(statusLabel)
mainLayout.addWidget(languageLabel)
mainLayout.addWidget(timeLabel)
mainLayout.addWidget(codeLengthLabel)
mainLayout.addLayout(elapseLayout)
mainLayout.setStretchFactor(statusLabel, 2)
mainLayout.setStretchFactor(languageLabel, 1)
mainLayout.setStretchFactor(timeLabel, 4)
mainLayout.setStretchFactor(codeLengthLabel, 2)
mainLayout.setStretchFactor(elapseLayout, 4)
widget = QWidget()
widget.setLayout(mainLayout)
widget.setCursor(Qt.PointingHandCursor)
return widget
def SetErrorColor(statusLabel: QLabel):
pass
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"])
else:
statusLabel.setPalette(Palette[QPalette.Text]["gray"])
def ReadFromFile(lang: str):
if uiMain.comboBoxLanguage.currentText() == '请选择提交语言':
QMessageBox.information(None, '提示', '请选择一种提交语言。', QMessageBox.Ok)
return
fileWindow = QFileDialog()
if lang == 'C++':
fileWindow.setNameFilter('C++ 源文件(*.cpp *.cc *.C *.cxx *.c++)')
......@@ -435,6 +518,9 @@ def ReadFromFile(lang: str):
def SubmitFile():
if uiMain.comboBoxLanguage.currentText() == '请选择提交语言':
QMessageBox.information(None, '提示', '请选择一种提交语言。', QMessageBox.Ok)
return
codeSubmit = ReadFromFile(uiMain.comboBoxLanguage.currentText())
if codeSubmit:
SubmitCode(uiMain.comboBoxLanguage.currentText(), codeSubmit)
......@@ -446,6 +532,9 @@ def SubmitReturn():
def SubmitCode(lang: str, code: str):
if lang == '请选择提交语言':
QMessageBox.information(None, '提示', '请选择一种提交语言。', QMessageBox.Ok)
return
try:
submit_result = submit(requests_var['e'], requests_var['p'], dataLanguage[lang], code)
except codiaError as e:
......@@ -462,6 +551,7 @@ def SubmitCode(lang: str, code: str):
def SubmitInit():
languages = [displayLanguage[lang] for lang in variables['exerciseInfo']['supportedLanguages']]
uiMain.comboBoxLanguageSubmit.clear()
uiMain.comboBoxLanguageSubmit.addItem('请选择提交语言')
uiMain.comboBoxLanguageSubmit.addItems(languages)
uiMain.frameQuestion.hide()
uiMain.frameSubmit.show()
......
......@@ -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.
......@@ -142,7 +142,7 @@ class Ui_windowMain(object):
self.pushButtonSubmitBack = NewPushButton(self.frameSubmit)
self.pushButtonSubmitBack.setGeometry(QtCore.QRect(890, 630, 120, 32))
self.pushButtonSubmitBack.setObjectName("pushButtonSubmitBack")
self.pushButtonReadFromFile = NewPushButton(self.frameSubmit)
self.pushButtonReadFromFile = QtWidgets.QPushButton(self.frameSubmit)
self.pushButtonReadFromFile.setGeometry(QtCore.QRect(690, 630, 120, 32))
self.pushButtonReadFromFile.setObjectName("pushButtonReadFromFile")
self.frameHistory = QtWidgets.QFrame(self.centralwidget)
......@@ -150,14 +150,24 @@ class Ui_windowMain(object):
self.frameHistory.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frameHistory.setFrameShadow(QtWidgets.QFrame.Raised)
self.frameHistory.setObjectName("frameHistory")
self.frameHistory.raise_()
self.frameQuestion.raise_()
self.listWidgetPackHistory = QtWidgets.QListWidget(self.frameHistory)
self.listWidgetPackHistory.setGeometry(QtCore.QRect(28, 30, 1024, 531))
self.listWidgetPackHistory.setMaximumSize(QtCore.QSize(1280, 768))
self.listWidgetPackHistory.setObjectName("listWidgetPackHistory")
self.pushButtonSubmitCodeDetails = NewPushButton(self.frameHistory)
self.pushButtonSubmitCodeDetails.setGeometry(QtCore.QRect(480, 630, 120, 32))
self.pushButtonSubmitCodeDetails.setObjectName("pushButtonSubmitCodeDetails")
self.pushButtonHistoryBack = NewPushButton(self.frameHistory)
self.pushButtonHistoryBack.setGeometry(QtCore.QRect(890, 630, 120, 32))
self.pushButtonHistoryBack.setObjectName("pushButtonHistoryBack")
self.framePack.raise_()
self.frameExercise.raise_()
self.frameSubmit.raise_()
self.frameQuestion.raise_()
self.frameHistory.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)
......@@ -189,4 +199,6 @@ class Ui_windowMain(object):
self.pushButtonSubmitCode.setText(_translate("windowMain", "提交"))
self.pushButtonSubmitBack.setText(_translate("windowMain", "返回"))
self.pushButtonReadFromFile.setText(_translate("windowMain", "从文件中读取"))
self.pushButtonSubmitCodeDetails.setText(_translate("windowMain", "详细信息"))
self.pushButtonHistoryBack.setText(_translate("windowMain", "返回"))
from codiaclientgui.utils import NewProgressBar, NewPushButton
......@@ -471,7 +471,7 @@
<string>返回</string>
</property>
</widget>
<widget class="NewPushButton" name="pushButtonReadFromFile">
<widget class="QPushButton" name="pushButtonReadFromFile">
<property name="geometry">
<rect>
<x>690</x>
......@@ -500,12 +500,54 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QListWidget" name="listWidgetPackHistory">
<property name="geometry">
<rect>
<x>28</x>
<y>30</y>
<width>1024</width>
<height>531</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>1280</width>
<height>768</height>
</size>
</property>
</widget>
<widget class="NewPushButton" name="pushButtonSubmitCodeDetails">
<property name="geometry">
<rect>
<x>480</x>
<y>630</y>
<width>120</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>详细信息</string>
</property>
</widget>
<widget class="NewPushButton" name="pushButtonHistoryBack">
<property name="geometry">
<rect>
<x>890</x>
<y>630</y>
<width>120</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>返回</string>
</property>
</widget>
</widget>
<zorder>frameHistory</zorder>
<zorder>frameQuestion</zorder>
<zorder>framePack</zorder>
<zorder>frameExercise</zorder>
<zorder>frameSubmit</zorder>
<zorder>frameQuestion</zorder>
<zorder>frameHistory</zorder>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
......@@ -513,7 +555,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