Newer
Older
SeeLook
committed
/***************************************************************************
* Copyright (C) 2011-2019 by Tomasz Bojczuk *
SeeLook
committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
* seelook@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "texamsummary.h"
#include "texamexecutor.h"
#include "texamview.h"
#include "dialogs/tlevelpreviewitem.h"
#include <exam/texam.h>
#include <exam/tqaunit.h>
#include <exam/textrans.h>
#include <exam/tlevel.h>
#include <tpath.h>
#if defined (Q_OS_ANDROID)
#include <Android/tandroid.h>
#endif
#include <QtCore/qtimer.h>
#include <QtCore/qdebug.h>
/**
* returns 2 columns row of table
*/
QString row2(const QString& S1, const QString& S2) {
return QString("<tr><td>%1: </td><td><b>%2</b></td></tr>").arg(S1, S2);
SeeLook
committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
}
TexamSummary::TexamSummary(QQuickItem* parent) :
QQuickItem(parent)
{
m_exam = EXECUTOR->exam();
/*
TroundedLabel *questNrLab = new TroundedLabel("<center>" + tr("Number of questions:") + QString("%2 %1</big></b>").arg(exam->count()).arg(font20) +
QString("<br>%1: %2%3</big></b>").arg(TexTrans::corrAnswersNrTxt()).arg(font20).
arg(exam->count() - exam->mistakes() - exam->halfMistaken()) +
QString("<br>%1: %2%3</big></b>").arg(TexTrans::mistakesNrTxt()).arg(font20).arg(exam->mistakes()) +
QString("<br>%1: %2%3</big></b>").arg(TexTrans::halfMistakenTxt()).arg(font20).arg(exam->halfMistaken())
,this);
QGroupBox *timeGr = new QGroupBox(tr("times:"), this);
TroundedLabel *timeLab = new TroundedLabel("<table>" +
row2(TexTrans::totalTimetxt(), TexamView::formatedTotalTime(exam->totalTime() * 1000)) +
row2(tr("Time taken to answer"), TexamView::formatedTotalTime(exam->workTime() * 1000)) +
row2(TexTrans::averAnsverTimeTxt(), QString("%1 s").
arg((qreal)exam->averageReactonTime()/10.0, 0, 'f', 1, '0')) +
"</table>", this);
*/
QString effStr;
if (m_exam->mistakes() || m_exam->halfMistaken()) {
float wAccid = 0.0, wKey = 0.0, wNote = 0.0, wOctave = 0.0, wStyle = 0.0, wPos = 0.0, wString = 0.0, wTotal;
float wInto = 0.0, wLittle = 0.0, wPoor = 0.0;
for(int i = 0; i < m_exam->count(); ++i) {
if (!m_exam->question(i)->isCorrect()) {
if(m_exam->question(i)->wrongAccid()) wAccid++;
if(m_exam->question(i)->wrongKey()) wKey++;
if(m_exam->question(i)->wrongNote()) wNote++;
if(m_exam->question(i)->wrongOctave()) wOctave++;
if(m_exam->question(i)->wrongStyle()) wStyle++;
if(m_exam->question(i)->wrongPos()) wPos++;
if(m_exam->question(i)->wrongString()) wString++;
if(m_exam->question(i)->wrongIntonation()) wInto++;
if(m_exam->question(i)->littleNotes()) wLittle++;
if(m_exam->question(i)->poorEffect()) wPoor++;
}
}
effStr += QLatin1String("<tr><td colspan=\"2\">-------- ") + tr("Kinds of mistakes") + QLatin1String(": --------</td></tr>");
SeeLook
committed
wTotal = wAccid + wKey + wNote + wOctave + wStyle + wPos + wString + wInto + wLittle + wPoor;
QString cp = QStringLiteral("%)"); // closing percent '%)'
SeeLook
committed
effStr += row2(tr("Wrong notes"), QString("%1 (").arg(wNote) + QString::number(qRound(wNote * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wNote);
}
if (wAccid) {
SeeLook
committed
effStr += row2(tr("Wrong accidentals"), QString("%1 (").arg(wAccid) + QString::number(qRound(wAccid * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wAccid);
}
if (wKey) {
SeeLook
committed
effStr += row2(tr("Wrong key signatures"), QString("%1 (").arg(wKey) + QString::number(qRound(wKey * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wKey);
}
if (wOctave){
SeeLook
committed
effStr += row2(tr("Wrong octaves"), QString("%1 (").arg(wOctave) + QString::number(qRound(wOctave * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wOctave);
}
if (wStyle) {
SeeLook
committed
effStr += row2(tr("Wrong note names"), QString("%1 (").arg(wStyle)) + QString::number(qRound(wStyle * 100.0 / wTotal)) + cp;
m_kindOfMistakes << static_cast<int>(wStyle);
}
if (wPos) {
SeeLook
committed
effStr += row2(tr("Wrong positions on guitar"), QString("%1 (").arg(wPos) + QString::number(qRound(wPos * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wPos);
}
if (wString) {
SeeLook
committed
effStr += row2(tr("Wrong strings"), QString("%1 (").arg(wString) + QString::number(qRound(wString * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wString);
}
if (wInto) {
SeeLook
committed
effStr += row2(tr("Out of tune"), QString("%1 (").arg(wInto) + QString::number(qRound(wInto * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wInto);
}
if (wLittle) {
SeeLook
committed
effStr += row2(QApplication::translate("AnswerText", "little valid notes", "the amount of correct notes in an answer is little"),
QString("%1 (").arg(wLittle) + QString::number(qRound(wLittle * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wLittle);
}
if (wPoor) {
SeeLook
committed
effStr += row2(QApplication::translate("AnswerText", "poor effectiveness"),
QString("%1 (").arg(wPoor) + QString::number(qRound(wPoor * 100.0 / wTotal)) + cp);
m_kindOfMistakes << static_cast<int>(wPoor);
}
SeeLook
committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
}
m_results = tr("Results:") + QLatin1String("<table>") +
row2(TexTrans::effectTxt(), QString::number(qRound(m_exam->effectiveness())) + QLatin1String("%")) + effStr + QLatin1String("</table>");
}
QString TexamSummary::title() const {
if (m_exam) {
if (m_exam->isExercise())
return tr("Progress of exercises");
else
return tr("Exam results");
}
return QString();
}
void TexamSummary::setLevelPreview(TlevelPreviewItem* lp) {
m_levelPreview = lp;
m_levelPreview->setLevel(m_exam->level());
}
QString TexamSummary::student() const {
return tr("student:") + QString("<font size=\"5\"><b> %1</b></font>").arg(m_exam->userName());
}
bool TexamSummary::isExercise() const {
return m_exam && m_exam->isExercise();
}
bool TexamSummary::continueExecutor() {
m_accepted = true;
if (m_exam->isExercise()) {
EXECUTOR->continueExercise();
return true;
} else
return EXECUTOR->continueInit();
}
void TexamSummary::exerciseToExam() {
m_accepted = true;
EXECUTOR->restoreExerciseAfterSummary();
EXECUTOR->exerciseToExam();
}
void TexamSummary::closeSummary() {
if (!m_accepted) {
if (EXECUTOR->summaryReason() == TexamExecutor::SumFinishExer)
QTimer::singleShot(10, [=]{ EXECUTOR->finishExerciseAfterSummary(); });
else
QTimer::singleShot(10, [=]{ EXECUTOR->closeExecutor(); });
}
}
bool TexamSummary::discardedAtBegin() const {
return EXECUTOR->summaryReason() == TexamExecutor::SumContExam && !EXECUTOR->isInitialized();
}
bool TexamSummary::enableContinue() const {
return m_exam->isExercise() || !EXECUTOR->isInitialized();
}
int TexamSummary::buttColumsCount() const {
return (!enableContinue() && isExercise()) || (enableContinue() && !isExercise()) ? 3 : 2;
}