std::vector<std::vector<QString> > Connector::getTeachersStudentsStats(QString teacher) { std::string query = "SELECT username, currentLevel, playedTime, wordsHit, wordsMissed, longestWordHit, longestStreak FROM User, Teaches where student = username and teacher = '" + teacher.toStdString() + "';"; mysql_query(connection, query.c_str()); MYSQL_RES *result = mysql_store_result(connection); MYSQL_ROW row; std::vector<std::vector<QString> > vRows(mysql_num_rows(result)); int j = 0; while((row = mysql_fetch_row(result)) != NULL) { std::vector<QString> vColumns(mysql_num_fields(result)); for(size_t i = 0; i < mysql_num_fields(result); i++) { vColumns[i] = row[i]; } vRows[j] = vColumns; j++; } return vRows; }
std::vector<std::vector<QString> > Connector::getEveryonesStats() { std::string query = "select username, currentLevel, playedTime, wordsHit, wordsMissed, longestWordHit, longestStreak from User;"; mysql_query(connection, query.c_str()); MYSQL_RES *result = mysql_store_result(connection); MYSQL_ROW row; std::vector<std::vector<QString> > vRows(mysql_num_rows(result)); int j = 0; while((row = mysql_fetch_row(result)) != NULL) { std::vector<QString> vColumns(mysql_num_fields(result)); for(size_t i = 0; i < mysql_num_fields(result); i++) { vColumns[i] = row[i]; } vRows[j] = vColumns; j++; } return vRows; }
/* converting a CellMatrix to a std::vector<string> */ vector<string> FromCellMatrixToVectorStr(const CellMatrix& aCM, const vector<bool>& aIsDate) { size_t vRows(aCM.RowsInStructure()), vCols(aCM.ColumnsInStructure()); vector<string> vVect(vRows*vCols); CellValue vTmpCell; double vTmpDbl; MG_Date vTmpDate; for(size_t i=0; i<vRows; ++i) { for(size_t j=0; j<vCols; ++j) { vTmpCell = aCM(i,j); if (vTmpCell.IsAString()) { vVect[j+i*vCols] = aCM(i,j); continue; } if (vTmpCell.IsANumber()) { vTmpDbl = aCM(i,j); if (aIsDate[j]) { vTmpDate = MG_Date(FromXLDateToJulianDay(vTmpDbl)); vVect[j+i*vCols] = vTmpDate.ToString('/'); continue; } vVect[j+i*vCols] = ftoa(vTmpDbl); continue; } } } return vVect; }
/* converting a CellMatrix to a MG_Matrix */ MG_Matrix FromCellMatrixToMGMatrix(const CellMatrix& aCM) { size_t vRows(aCM.RowsInStructure()), vCols(aCM.ColumnsInStructure()); MG_Matrix vMat(vRows, vCols); for(size_t i=0; i<vRows; ++i) for(size_t j=0; j<vCols; ++j) vMat(i, j) = aCM(i, j).NumericValue(); return vMat; }