/
icansweranalyzer.cpp
47 lines (43 loc) · 1.3 KB
/
icansweranalyzer.cpp
1
2
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
41
42
43
44
45
46
47
#include "icansweranalyzer.h"
#include "icconfig.h"
#include <QObject>
#include <QSet>
ICAnswerAnalyzer::ICAnswerAnalyzer(const ICQuestion& theQuestion) : question(theQuestion)
{
int type = question.getType().toInt();
switch (type) {
case UNDERSTAND:
map.insert("A", QObject::tr("A.Understand"));
map.insert("B", QObject::tr("B.Nope"));
map.insert("C", QObject::tr("C.Is it edible?"));
break;
case TOF:
map.insert("A", QObject::tr("A.Yes"));
map.insert("B", QObject::tr("B.No"));
break;
}
}
const QMap<QString, int> ICAnswerAnalyzer::analyze(const QList<ICAnswer>& answers)
{
QMap<QString, int> result;
QSet<QString> answeredUid;
QListIterator<ICAnswer> i(answers);
i.toBack();
while (i.hasPrevious()) {
const ICAnswer& answer = i.previous();
QString uid = answer.getUid();
if (!answeredUid.contains(uid)) {
answeredUid.insert(uid);
QString text = answer.getAnswer().trimmed();
QString as;
if (text.isEmpty()) {
as = QObject::tr("Empty Answer");
} else {
as = map.value(text, text);
}
int count = result.value(as, 0);
result.insert(as, ++count);
}
}
return result;
}