2014-09-08 15:54:52 +00:00
|
|
|
#include "gradePage.h"
|
|
|
|
|
2014-09-17 01:08:38 +00:00
|
|
|
GradePage::GradePage(QString html) : Page()
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
2014-09-17 01:08:38 +00:00
|
|
|
courses = new std::list<gradeCourse*>();
|
|
|
|
tempHtml = getString(html);
|
|
|
|
tempHtml = tokenToLines(tempHtml);
|
|
|
|
coursesListInit(tempHtml);
|
2014-09-08 15:54:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
GradePage::~GradePage()
|
|
|
|
{
|
|
|
|
for(Course* c : *courses)
|
|
|
|
delete c;
|
|
|
|
delete courses;
|
|
|
|
}
|
|
|
|
|
2014-09-17 01:08:38 +00:00
|
|
|
void GradePage::removeCourse(QString courseSerialID)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
|
|
|
for(gradeCourse* c : *courses)
|
|
|
|
{
|
2014-09-17 01:08:38 +00:00
|
|
|
if (c->getSerialNum() == courseSerialID.toInt())
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
|
|
|
courses->remove(c);
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-09-17 01:08:38 +00:00
|
|
|
void GradePage::coursesListInit(QString &linesTokinzedString)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
2014-09-17 01:08:38 +00:00
|
|
|
std::list<QString> stringHolder;
|
|
|
|
QString temp;
|
2014-09-08 15:54:52 +00:00
|
|
|
gradeCourse* cTemp = NULL;
|
|
|
|
char* tok;
|
2014-09-17 01:08:38 +00:00
|
|
|
char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
|
2014-09-08 15:54:52 +00:00
|
|
|
tok = strtok(textToTok,"\n");
|
|
|
|
while (tok != NULL)
|
|
|
|
{
|
|
|
|
temp = tok;
|
|
|
|
stringHolder.push_back(temp);
|
|
|
|
tok = strtok(NULL, "\n");
|
|
|
|
}
|
2014-09-17 01:08:38 +00:00
|
|
|
for(QString temp: stringHolder)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
|
|
|
cTemp = lineToCourse(temp);
|
|
|
|
if (cTemp != NULL)
|
2014-09-17 01:08:38 +00:00
|
|
|
courses->push_back(cTemp);
|
2014-09-08 15:54:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-17 01:08:38 +00:00
|
|
|
QString GradePage::tokenToLines(QString &textToPhrase)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
|
|
|
int ctr = 0;
|
2014-09-17 01:08:38 +00:00
|
|
|
QString temp = "";
|
2014-09-08 15:54:52 +00:00
|
|
|
char *tok;
|
2014-09-17 01:08:38 +00:00
|
|
|
char* textToTok = strdup(textToPhrase.toStdString().c_str());
|
2014-09-08 15:54:52 +00:00
|
|
|
tok = strtok(textToTok, "\n");
|
|
|
|
while(tok != NULL)
|
|
|
|
{
|
|
|
|
//amount of data before the actual needed data and no empty lines
|
|
|
|
if (strcmp(tok," \t ") != 0)
|
|
|
|
{
|
|
|
|
temp += tok;
|
|
|
|
temp += "\n";
|
|
|
|
}
|
|
|
|
ctr++;
|
|
|
|
tok = strtok(NULL, "\n");
|
|
|
|
}
|
|
|
|
return temp;
|
|
|
|
|
|
|
|
}
|
2014-09-17 01:08:38 +00:00
|
|
|
gradeCourse* GradePage::lineToCourse(QString line)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
|
|
|
gradeCourse *tempC = NULL;
|
2014-09-17 01:08:38 +00:00
|
|
|
QString templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
|
2014-09-08 15:54:52 +00:00
|
|
|
int serial;
|
|
|
|
double points,hours,grade;
|
2014-09-17 01:08:38 +00:00
|
|
|
QString name,type, additions;
|
|
|
|
QString tempS = "";
|
2014-09-08 15:54:52 +00:00
|
|
|
int i = 0;
|
|
|
|
char* tok;
|
2014-09-17 01:08:38 +00:00
|
|
|
char* cLine = strdup(line.toStdString().c_str());
|
2014-09-08 15:54:52 +00:00
|
|
|
tok = strtok(cLine, "\t");
|
|
|
|
while(tok != NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
tempS = tok;
|
|
|
|
if (i == 1) //skip the tokenizing loop just once
|
|
|
|
{
|
|
|
|
tempS = "";
|
|
|
|
char *tokTemp;
|
|
|
|
tokTemp = tok;
|
|
|
|
while (!(isdigit((int)*tokTemp)))
|
|
|
|
tokTemp++;
|
|
|
|
|
|
|
|
while (isdigit((int)*tokTemp))
|
|
|
|
{
|
2014-09-17 01:08:38 +00:00
|
|
|
tempS += QString(*tokTemp);
|
2014-09-08 15:54:52 +00:00
|
|
|
tokTemp++;
|
|
|
|
}
|
|
|
|
templinearray[i-1] = tempS;
|
2014-09-17 01:08:38 +00:00
|
|
|
templinearray[i] = QString(tokTemp);
|
2014-09-08 15:54:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if (i > 1)
|
2014-09-17 01:08:38 +00:00
|
|
|
{
|
2014-09-08 15:54:52 +00:00
|
|
|
templinearray[i] = tempS;
|
2014-09-17 01:08:38 +00:00
|
|
|
}
|
2014-09-08 15:54:52 +00:00
|
|
|
i++;
|
|
|
|
tok=strtok(NULL, "\t");
|
|
|
|
}
|
|
|
|
if (templinearray[0] == "") //empty phrasing
|
|
|
|
return NULL;
|
|
|
|
|
2014-09-17 01:08:38 +00:00
|
|
|
serial = templinearray[gradeCourse::CourseScheme::SERIAL].toInt();
|
2014-09-08 15:54:52 +00:00
|
|
|
|
|
|
|
name = templinearray[gradeCourse::CourseScheme::NAME];
|
|
|
|
type = templinearray[gradeCourse::CourseScheme::TYPE];
|
|
|
|
|
2014-09-17 01:08:38 +00:00
|
|
|
points = templinearray[gradeCourse::CourseScheme::POINTS].toDouble();
|
|
|
|
hours = templinearray[gradeCourse::CourseScheme::HOURS].toDouble();
|
2014-09-08 15:54:52 +00:00
|
|
|
|
|
|
|
if (isGradedYet(templinearray[gradeCourse::CourseScheme::GRADE]))
|
2014-09-17 01:08:38 +00:00
|
|
|
grade = templinearray[gradeCourse::CourseScheme::GRADE].toDouble();
|
2014-09-08 15:54:52 +00:00
|
|
|
else
|
|
|
|
grade = NO_GRADE_YET;
|
|
|
|
|
|
|
|
additions = templinearray[gradeCourse::CourseScheme::ADDITION];
|
|
|
|
|
|
|
|
tempC = new gradeCourse(serial,name,type,points,hours,grade,additions);
|
|
|
|
return tempC;
|
|
|
|
}
|
|
|
|
|
|
|
|
//checking if one of the chars inside grade is not a number
|
2014-09-17 01:08:38 +00:00
|
|
|
bool GradePage::isGradedYet(QString grade)
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
2014-09-17 01:08:38 +00:00
|
|
|
if (strlen(grade.toStdString().c_str()) <= 1)
|
2014-09-08 15:54:52 +00:00
|
|
|
return false;
|
|
|
|
|
2014-09-17 01:08:38 +00:00
|
|
|
for (char c: grade.toStdString())
|
2014-09-08 15:54:52 +00:00
|
|
|
{
|
|
|
|
if (c == '\0')
|
|
|
|
break;
|
|
|
|
if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
double GradePage::getAvg()
|
|
|
|
{
|
|
|
|
double avg = 0;
|
|
|
|
double points = 0;
|
|
|
|
for(gradeCourse* c : *courses)
|
|
|
|
{
|
|
|
|
if ((c->getGrade() != 0))
|
|
|
|
{
|
|
|
|
avg += c->getGrade() * c->getPoints();
|
|
|
|
points += c->getPoints();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
avg /= points;
|
|
|
|
return avg;
|
|
|
|
}
|