#include "student.h"
Student::Student(QString name)
{
s_name = name;
s_number = 0;
s_score = 0;
s_maxscore = 0;
s_ready = false;
s_results = new QMap<QString, QuestionAnswer>;
s_passed = true;
}
Student::Student(Client * client)
{
s_name = client->name();
s_number = client->number();
s_score = client->score();
s_maxscore = client->maximumScore();
s_ready = client->isReady();
s_results = new QMap<QString, QuestionAnswer> (*(client->results()));
s_passed = client->passed();
}
Student::Student(Student * student)
{
s_name = student->name();
s_number = student->number();
s_score = student->score();
s_maxscore = student->maximumScore();
s_ready = student->isReady();
s_results = new QMap<QString, QuestionAnswer> (*(student->results()));
s_passed = student->passed();
}
Student::~Student()
{
if (s_results) delete s_results;
}
void Student::setName(QString name) { s_name = name; }
QString Student::name() { return s_name; }
void Student::setNumber(int number) { s_number = number; }
int Student::number() { return s_number; }
int Student::numCorrectAnswers(ScoringSystem sys)
{
int num = 0; QuestionAnswer qans;
QMapIterator<QString, QuestionAnswer> i(*s_results);
while (i.hasNext()) { i.next();
qans = i.value();
if (qans.score(sys) > 0.0) { num++; }
}
return num;
}
float Student::score() { return s_score; }
float Student::maximumScore() { return s_maxscore; }
void Student::setReady(bool ready) { s_ready = ready; }
bool Student::isReady() { return s_ready; }
void Student::setResults(QMap<QString, QuestionAnswer> * results)
{
delete s_results;
s_results = results;
}
QMap<QString, QuestionAnswer> * Student::results() { return s_results; }
void Student::updateScore(ScoringSystem sys)
{
s_score = 0; s_maxscore = 0; QuestionAnswer qans;
QMapIterator<QString, QuestionAnswer> i(*s_results);
while (i.hasNext()) { i.next();
qans = i.value();
s_score += qans.score(sys);
s_maxscore += qans.maximumScore(sys);
}
}
void Student::setPassed(bool passed) { s_passed = passed; }
bool Student::passed() { return s_passed; }
QString Student::studentData()
{
QString out;
out.append("[STUDENT]\n");
out.append(s_name);
out.append(s_ready ? "\ntrue" : "\nfalse");
out.append(s_passed ? "\ntrue" : "\nfalse");
out.append(QString("\n%1\n").arg(s_number));
out.append(QString("%1").arg(s_results->count()));
QMapIterator<QString, QuestionAnswer> i(*s_results); QuestionAnswer qans;
while (i.hasNext()) { i.next();
qans = i.value();
out.append(QString("\n%1").arg(i.key()));
out.append(QString("\n%1").arg(qans.flag()));
out.append(QString("\n%1").arg(qans.difficulty()));
out.append(QString("\n%1").arg(qans.selectionType()));
out.append(QString("\n%1").arg(qans.answered()));
out.append(QString("\n%1").arg(qans.correctAnswer()));
}
return out;
}
QString Student::studentArchiveData()
{
QString out;
out.append("[STUDENT]\n");
out.append(s_name);
out.append(s_ready ? "\ntrue" : "\nfalse");
out.append(QString("\n%1\n").arg(s_number));
out.append(QString("%1\n").arg((int)s_score));
out.append(QString("%1").arg(s_results->count()));
QMapIterator<QString, QuestionAnswer> i(*s_results); QuestionAnswer qans;
while (i.hasNext()) { i.next();
qans = i.value();
out.append(QString("\n%1").arg(i.key()));
out.append(QString("\n%1").arg(Question::convertToOldAnsNumber(qans.answered())));
out.append(QString("\n%1").arg(Question::convertToOldAnsNumber(qans.correctAnswer())));
}
return out;
}
bool Student::wasAsked(QString qname)
{
QMapIterator<QString, QuestionAnswer> i(*s_results);
while (i.hasNext()) { i.next();
if (i.key() == qname) { return true; }
}
return false;
}
uint Student::replaceOccurrences(QString old_qname, QString new_qname)
{
QuestionAnswer qans = s_results->value(old_qname, QuestionAnswer());
uint n = s_results->remove(old_qname);
if (n > 0) { s_results->insert(new_qname, qans); }
return n;
}