gpa grade gradient, cleartable on get gpa

This commit is contained in:
liranbg 2014-10-13 04:31:36 +03:00
parent a33939c93b
commit 10f53aa3f3
8 changed files with 237 additions and 219 deletions

View file

@ -53,9 +53,9 @@ void coursesTableManager::insertJceCoursesIntoTable()
*/ */
void coursesTableManager::setCoursesList(QString &html) void coursesTableManager::setCoursesList(QString &html)
{ {
if (gp != NULL) clearTable();
gp->~GradePage();
gp = new GradePage(html); gp = new GradePage(html);
insertJceCoursesIntoTable();
} }
/** /**
* @brief coursesTableManager::changes when user changes the table manually it updates it * @brief coursesTableManager::changes when user changes the table manually it updates it
@ -119,16 +119,20 @@ bool coursesTableManager::changes(QString change, int row, int col)
} }
case (gradeCourse::CourseScheme::GRADE): case (gradeCourse::CourseScheme::GRADE):
{ {
change.toDouble(&isNumFlag); change.toDouble(&isNumFlag);
if (!isNumFlag) if (!isNumFlag) //not a number
{ {
courseTBL->item(row,col)->setText(QString::number(c->getGrade())); courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
} }
else else
{ {
if ((change.toDouble() >= 0) && (change.toDouble() <= 100)) if ((change.toDouble() >= 0) && (change.toDouble() <= 100))
{
c->setGrade(change.toDouble()); c->setGrade(change.toDouble());
colorTheGrade(row);
}
else else
courseTBL->item(row,col)->setText(QString::number(c->getGrade())); courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
} }
@ -212,28 +216,11 @@ void coursesTableManager::addRow(const gradeCourse *courseToAdd)
courseTBL->setItem(i,j++,type); courseTBL->setItem(i,j++,type);
courseTBL->setItem(i,j++,points); courseTBL->setItem(i,j++,points);
courseTBL->setItem(i,j++,hours); courseTBL->setItem(i,j++,hours);
courseTBL->setItem(i,j,grade); courseTBL->setItem(i,j++,grade);
//FIXME : make it a function, add it when cell has changed
if(c->getGrade() < 55 && c->getGrade() != 0)
{
courseTBL->item(i, j)->setBackground(Qt::darkRed);
courseTBL->item(i,j)->setTextColor(Qt::white);
}
else if(55 <= c->getGrade() && c->getGrade() < 70 )
{
courseTBL->item(i, j)->setBackground(Qt::darkYellow);
courseTBL->item(i,j)->setTextColor(Qt::white);
}
// else if(70 < c->getGrade() && c->getGrade() <= 80 )
// courseTBL->item(i, j)->setBackground(Qt::darkGreen); //They Look Bad!!
// else if(c->getGrade() > 80)
// courseTBL->item(i, j)->setBackground(Qt::green);
j++;
courseTBL->setItem(i,j,addition); courseTBL->setItem(i,j,addition);
colorTheGrade(i);
} }
} }
else else
@ -252,17 +239,16 @@ double coursesTableManager::getAvg()
return 0; return 0;
} }
void coursesTableManager::showGraph() bool coursesTableManager::showGraph()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (gp != NULL) if (gp != NULL)
{ {
this->graph->showGraph(gp); this->graph->showGraph(gp);
return true;
} }
else
{
qWarning() << Q_FUNC_INFO << "open with null grade page"; qWarning() << Q_FUNC_INFO << "open with null grade page";
} return false;
} }
@ -299,9 +285,12 @@ void coursesTableManager::clearTable()
int i = 0; //starting point int i = 0; //starting point
while (courseTBL->rowCount() > i) while (courseTBL->rowCount() > i)
{ {
if (gp != NULL)
gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text()); gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text());
courseTBL->removeRow(i); courseTBL->removeRow(i);
} }
if (gp != NULL)
delete gp;
gp = NULL; gp = NULL;
courseTBL->repaint(); courseTBL->repaint();
} }
@ -339,3 +328,28 @@ bool coursesTableManager::isCourseInfluence(const gradeCourse *courseToCheck)
return false; return false;
} }
/**
* @brief coursesTableManager::colorTheGrade - color the course grade
* @param rowIndex - course's row index
*/
void coursesTableManager::colorTheGrade(int rowIndex)
{
gradeCourse * temp = getCourseByRow(rowIndex);
if (temp != NULL)
{
if (temp->getGrade() != 0)
{
float green,red, blue = 0;
float grade = ((float)temp->getGrade());
green = qRound(grade * 255 / 100);
red = qRound((255 * (100 - grade) / 100));
blue = 0;
//higher the grade -> the greener it is
courseTBL->item(rowIndex,gradeCourse::CourseScheme::GRADE)->setBackground(QColor(red,green,blue));
courseTBL->item(rowIndex,gradeCourse::CourseScheme::GRADE)->setTextColor(Qt::black);
}
}
}

View file

@ -2,17 +2,13 @@
#define COURSESTABLEMANAGER_H #define COURSESTABLEMANAGER_H
#include <QApplication> #include <QtGlobal>
#include <QDesktopWidget>
#include <QtCore/QCoreApplication>
#include <QHeaderView> #include <QHeaderView>
#include <QMessageBox> #include <QMessageBox>
#include <QTableWidget> #include <QTableWidget>
#include <QString> #include <QString>
#include <QMessageBox> #include <QMessageBox>
#include <list>
#include "./src/jceData/Grades/graph/gradegraph.h" #include "./src/jceData/Grades/graph/gradegraph.h"
#include "./src/jceData/Grades/gradePage.h" #include "./src/jceData/Grades/gradePage.h"
#include "./src/jceSettings/user.h" #include "./src/jceSettings/user.h"
@ -28,7 +24,7 @@ public:
void addRow(const gradeCourse * courseToAdd = 0); void addRow(const gradeCourse * courseToAdd = 0);
double getAvg(); double getAvg();
void showGraph(); bool showGraph();
void influnceCourseChanged(bool status); void influnceCourseChanged(bool status);
void clearTable(); void clearTable();
@ -42,6 +38,8 @@ private:
gradeCourse * getCourseByRow(int row); gradeCourse * getCourseByRow(int row);
bool isCourseAlreadyInserted(double courseID); bool isCourseAlreadyInserted(double courseID);
bool isCourseInfluence(const gradeCourse *courseToCheck); bool isCourseInfluence(const gradeCourse *courseToCheck);
void colorTheGrade(int rowIndex);
}; };
#endif // COURSESTABLEMANAGER_H #endif // COURSESTABLEMANAGER_H

View file

@ -59,6 +59,7 @@ bool loginHandler::makeConnection()
{ {
case jceLogin::JCE_YOU_ARE_IN: case jceLogin::JCE_YOU_ARE_IN:
{ {
statusBar->setIconConnectionStatus(jceStatusBar::LoggedIn);
logggedInFlag = true; logggedInFlag = true;
return logggedInFlag; return logggedInFlag;
} }
@ -145,7 +146,6 @@ int loginHandler::makeCalendarRequest(int year, int semester)
else else
return jceLogin::JCE_NOT_CONNECTED; return jceLogin::JCE_NOT_CONNECTED;
} }
int loginHandler::makeExamsScheduleRequest(int year, int semester) int loginHandler::makeExamsScheduleRequest(int year, int semester)
{ {

View file

@ -152,7 +152,6 @@ void MainScreen::on_ratesButton_clicked()
statusBar->setIconConnectionStatus(jceStatusBar::Inserting); statusBar->setIconConnectionStatus(jceStatusBar::Inserting);
pageString = loginHandel->getCurrentPageContect(); pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString); courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable();
statusBar->setIconConnectionStatus(jceStatusBar::Done); statusBar->setIconConnectionStatus(jceStatusBar::Done);
} }
else if (status == jceLogin::JCE_NOT_CONNECTED) else if (status == jceLogin::JCE_NOT_CONNECTED)
@ -231,7 +230,8 @@ void MainScreen::on_clearTableButton_clicked()
void MainScreen::on_graphButton_clicked() void MainScreen::on_graphButton_clicked()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
courseTableMgr->showGraph(); if (!courseTableMgr->showGraph())
QMessageBox::critical(this,tr("Error"),tr("You must to load GPA first\nClick on 'Get GPA'"));
} }

View file

@ -172,7 +172,7 @@ bool jceSSLClient::recieveData(QString *str)
disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt())); disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
str->append(packet); str->append(packet);
// qDebug() << *str; //if you want to see the whole packet, unmark me qDebug() << *str; //if you want to see the whole packet, unmark me
qDebug() << Q_FUNC_INFO << "packet size: " << packetSizeRecieved << "received data lenght: " << str->length(); qDebug() << Q_FUNC_INFO << "packet size: " << packetSizeRecieved << "received data lenght: " << str->length();
qDebug() << Q_FUNC_INFO << "return with flag: " << recieveLastPacket; qDebug() << Q_FUNC_INFO << "return with flag: " << recieveLastPacket;

View file

@ -135,8 +135,10 @@ gradeCourse* GradePage::lineToCourse(QString line)
if (year >= maxYear) if (year >= maxYear)
maxYear = year; maxYear = year;
if (year <= minYear) if ((year <= minYear) && (points > 0)) //not graded yet isnt influced year!
{
minYear = year; minYear = year;
}
tempC = new gradeCourse(year,semester,courseNumInList,serial,name,type,points,hours,grade,additions); tempC = new gradeCourse(year,semester,courseNumInList,serial,name,type,points,hours,grade,additions);
return tempC; return tempC;
@ -152,11 +154,12 @@ bool GradePage::isGradedYet(QString grade)
if (strlen(grade.toStdString().c_str()) <= 1) if (strlen(grade.toStdString().c_str()) <= 1)
return false; return false;
for (char c: grade.toStdString()) for (QChar c: grade)
{ {
if (c == '\0') if (c == '\0')
break; break;
if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9
if (((!c.isDigit()) && (!c.isSpace()))) //48 = 0, 57 = 9
return false; return false;
} }

View file

@ -17,6 +17,7 @@ void gradegraph::showGraph(GradePage *gpPTR)
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
this->gp = gpPTR; this->gp = gpPTR;
if (ui->graphwidget->graphCount() > 0)
clearGraph(); clearGraph();
setVisualization(); setVisualization();
@ -34,7 +35,7 @@ gradegraph::~gradegraph()
void gradegraph::setGraphsData() void gradegraph::setGraphsData()
{ {
int minYearInList = gp->getMinYearInList(); int minYearInList = gp->getMinYearInList()-1;
int maxYearInList = gp->getMaxYearInList()+1; int maxYearInList = gp->getMaxYearInList()+1;
int xRangeForYear = (maxYearInList - minYearInList+2)*3; int xRangeForYear = (maxYearInList - minYearInList+2)*3;
QVector<double> SemesterialAvg(xRangeForYear),yearlyAvg(xRangeForYear),indicatorX(xRangeForYear); QVector<double> SemesterialAvg(xRangeForYear),yearlyAvg(xRangeForYear),indicatorX(xRangeForYear);
@ -134,8 +135,7 @@ void gradegraph::setVisualization()
ui->graphwidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red))); ui->graphwidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red)));
ui->graphwidget->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::red, 7)); ui->graphwidget->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::red, 7));
int minYearInList = gp->getMinYearInList()-1;
int minYearInList = gp->getMinYearInList();
int maxYearInList = gp->getMaxYearInList()+1; int maxYearInList = gp->getMaxYearInList()+1;
int xRangeForYear = (maxYearInList - minYearInList+2)*3; int xRangeForYear = (maxYearInList - minYearInList+2)*3;

View file

@ -325,7 +325,10 @@ void jceLogin::reValidation()
if (checkValidation()) if (checkValidation())
{ {
if (makeSecondVisit() == true) if (makeSecondVisit() == true)
{
statusBar->setIconConnectionStatus(jceStatusBar::LoggedIn);
qDebug() << Q_FUNC_INFO << "Validated"; qDebug() << Q_FUNC_INFO << "Validated";
}
else else
qWarning() << Q_FUNC_INFO << "Second visit finished with an error"; qWarning() << Q_FUNC_INFO << "Second visit finished with an error";
} }