mirror of https://github.com/acanas/swad-core.git
Version 20.68.2: Apr 26, 2021 Code optimization in games and exams.
This commit is contained in:
parent
40a4e56125
commit
8565264e1f
|
@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
|
|||
|
||||
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.68.1 (2021-04-26)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.68.2 (2021-04-26)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.6.2.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 20.68.2: Apr 26, 2021 Code optimization in games and exams. (309807 lines)
|
||||
Version 20.68.1: Apr 26, 2021 Code refactoring in exams and tests. (309862 lines)
|
||||
Version 20.68: Apr 26, 2021 New module swad_error. (309853 lines)
|
||||
Version 20.67.11: Apr 26, 2021 Fixed bug in departments. (309677 lines)
|
||||
|
|
57
swad_exam.c
57
swad_exam.c
|
@ -1774,63 +1774,6 @@ long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
|
|||
return QstCod;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get previous question index to a given index in an exam **********/
|
||||
/*****************************************************************************/
|
||||
// Input question index can be 1, 2, 3... n-1
|
||||
// Return question index will be 1, 2, 3... n if previous question exists, or 0 if no previous question
|
||||
|
||||
unsigned Exa_GetPrevQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
||||
{
|
||||
/***** Get previous question index in an exam from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
||||
"SELECT MAX(QstInd)"
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd<%u",
|
||||
ExaCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************* Get next question index to a given index in an exam ************/
|
||||
/*****************************************************************************/
|
||||
// Input question index can be 0, 1, 2, 3... n-1
|
||||
// Return question index will be 1, 2, 3... n if next question exists, or big number if no next question
|
||||
|
||||
unsigned Exa_GetNextQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
||||
{
|
||||
unsigned NextQstInd;
|
||||
|
||||
/***** Get next question index in an exam from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
NextQstInd = DB_QuerySELECTUnsigned ("can not get next question index",
|
||||
"SELECT MIN(QstInd)"
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
ExaCod,QstInd);
|
||||
if (NextQstInd == 0)
|
||||
NextQstInd = ExaSes_AFTER_LAST_QUESTION; // End of questions has been reached
|
||||
|
||||
return NextQstInd;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Put parameter with set code to edit, remove... **************/
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
static void Exa_PutParamSetCod (void *SetCod) // Should be a pointer to long
|
||||
{
|
||||
if (SetCod)
|
||||
if (*((long *) SetCod) > 0) // If set exists
|
||||
Par_PutHiddenParamLong (NULL,"SetCod",*((long *) SetCod));
|
||||
}
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Get number of sessions and check is edition is possible **********/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -93,9 +93,6 @@ void Exa_PutParamQstInd (unsigned QstInd);
|
|||
unsigned Exa_GetParamQstInd (void);
|
||||
long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd);
|
||||
|
||||
unsigned Exa_GetPrevQuestionIndexInExam (long ExaCod,unsigned QstInd);
|
||||
unsigned Exa_GetNextQuestionIndexInExam (long ExaCod,unsigned QstInd);
|
||||
|
||||
bool Exa_CheckIfEditable (const struct Exa_Exam *Exam);
|
||||
|
||||
unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope);
|
||||
|
|
|
@ -65,6 +65,8 @@ extern struct Globals Gbl;
|
|||
#define ExaSet_MAX_SELECTED_QUESTIONS 10000
|
||||
#define ExaSet_MAX_BYTES_LIST_SELECTED_QUESTIONS (ExaSet_MAX_SELECTED_QUESTIONS * (Cns_MAX_DECIMAL_DIGITS_LONG + 1))
|
||||
|
||||
#define ExaSet_AFTER_LAST_SET ((unsigned)((1UL << 31) - 1)) // 2^31 - 1, don't change this number because it is used in database to indicate that a session is finished
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Private types *******************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -848,7 +850,7 @@ static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get previous set index",
|
||||
"SELECT MAX(SetInd)"
|
||||
"SELECT COALESCE(MAX(SetInd),0)"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd<%u",
|
||||
|
@ -864,22 +866,17 @@ static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
|
|||
|
||||
static unsigned ExaSet_GetNextSetIndexInExam (long ExaCod,unsigned SetInd)
|
||||
{
|
||||
unsigned NextSetInd;
|
||||
|
||||
/***** Get next set index in an exam from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
NextSetInd = DB_QuerySELECTUnsigned ("can not get next set index",
|
||||
"SELECT MIN(SetInd)"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd>%u",
|
||||
ExaCod,
|
||||
SetInd);
|
||||
if (NextSetInd == 0)
|
||||
NextSetInd = ExaSes_AFTER_LAST_QUESTION; // End of sets has been reached
|
||||
|
||||
return NextSetInd;
|
||||
return DB_QuerySELECTUnsigned ("can not get next set index",
|
||||
"SELECT COALESCE(MIN(SetInd),%u)"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd>%u",
|
||||
ExaSet_AFTER_LAST_SET, // End of sets has been reached
|
||||
ExaCod,
|
||||
SetInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1866,7 +1863,7 @@ void ExaSet_MoveUpSet (void)
|
|||
{
|
||||
/* Indexes of sets to be exchanged */
|
||||
SetIndTop = ExaSet_GetPrevSetIndexInExam (Exam.ExaCod,SetIndBottom);
|
||||
if (!SetIndTop)
|
||||
if (SetIndTop == 0)
|
||||
Err_ShowErrorAndExit ("Wrong set index.");
|
||||
|
||||
/* Exchange sets */
|
||||
|
@ -1917,7 +1914,7 @@ void ExaSet_MoveDownSet (void)
|
|||
{
|
||||
/* Indexes of sets to be exchanged */
|
||||
SetIndBottom = ExaSet_GetNextSetIndexInExam (Exam.ExaCod,SetIndTop);
|
||||
if (!SetIndBottom)
|
||||
if (SetIndBottom == ExaSet_AFTER_LAST_SET)
|
||||
Err_ShowErrorAndExit ("Wrong set index.");
|
||||
|
||||
/* Exchange sets */
|
||||
|
|
27
swad_game.c
27
swad_game.c
|
@ -1892,7 +1892,7 @@ unsigned Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
||||
"SELECT MAX(QstInd)"
|
||||
"SELECT COALESCE(MAX(QstInd),0)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd<%u",
|
||||
|
@ -1904,26 +1904,21 @@ unsigned Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
|||
/************* Get next question index to a given index in a game ************/
|
||||
/*****************************************************************************/
|
||||
// Input question index can be 0, 1, 2, 3... n-1
|
||||
// Return question index will be 1, 2, 3... n if next question exists, or 0 if no next question
|
||||
// Return question index will be 1, 2, 3... n if next question exists, or big number if no next question
|
||||
|
||||
unsigned Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||
{
|
||||
unsigned NextQstInd;
|
||||
|
||||
/***** Get next question index in a game from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
NextQstInd = DB_QuerySELECTUnsigned ("can not get next question index",
|
||||
"SELECT MIN(QstInd)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
GamCod,
|
||||
QstInd);
|
||||
if (NextQstInd == 0)
|
||||
NextQstInd = Mch_AFTER_LAST_QUESTION; // End of questions has been reached
|
||||
|
||||
return NextQstInd;
|
||||
return DB_QuerySELECTUnsigned ("can not get next question index",
|
||||
"SELECT COALESCE(MIN(QstInd),%u)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
Gam_AFTER_LAST_QUESTION, // End of questions has been reached
|
||||
GamCod,
|
||||
QstInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2467,7 +2462,7 @@ void Gam_MoveDownQst (void)
|
|||
{
|
||||
/* Indexes of questions to be exchanged */
|
||||
QstIndBottom = Gam_GetNextQuestionIndexInGame (Game.GamCod,QstIndTop);
|
||||
if (!QstIndBottom)
|
||||
if (QstIndBottom == Gam_AFTER_LAST_QUESTION)
|
||||
Err_WrongQuestionIndexExit ();
|
||||
|
||||
/* Exchange questions */
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#define Gam_MAX_CHARS_TITLE (128 - 1) // 127
|
||||
#define Gam_MAX_BYTES_TITLE ((Gam_MAX_CHARS_TITLE + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047
|
||||
|
||||
#define Gam_AFTER_LAST_QUESTION ((unsigned)((1UL << 31) - 1)) // 2^31 - 1, don't change this number because it is used in database to indicate that a match is finished
|
||||
|
||||
#define Gam_NUM_ORDERS 3
|
||||
typedef enum
|
||||
{
|
||||
|
@ -74,7 +76,7 @@ struct Gam_Games
|
|||
long GamCod; // Selected/current game code
|
||||
struct
|
||||
{
|
||||
long Selected; // Current match code
|
||||
long Selected; // Current match code
|
||||
long Current;
|
||||
} MchCod;
|
||||
unsigned QstInd; // Current question index
|
||||
|
|
|
@ -1806,7 +1806,8 @@ static void Mch_CreateIndexes (long GamCod,long MchCod)
|
|||
"gam_questions.QstInd," // row[1]
|
||||
"tst_questions.AnsType," // row[2]
|
||||
"tst_questions.Shuffle" // row[3]
|
||||
" FROM gam_questions,tst_questions"
|
||||
" FROM gam_questions,"
|
||||
"tst_questions"
|
||||
" WHERE gam_questions.GamCod=%ld"
|
||||
" AND gam_questions.QstCod=tst_questions.QstCod"
|
||||
" ORDER BY gam_questions.QstInd",
|
||||
|
@ -2436,7 +2437,7 @@ static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match)
|
|||
Match->Status.QstInd);
|
||||
|
||||
/***** Get question code *****/
|
||||
if (Match->Status.QstInd < Mch_AFTER_LAST_QUESTION) // End of questions not reached
|
||||
if (Match->Status.QstInd < Gam_AFTER_LAST_QUESTION) // End of questions not reached
|
||||
{
|
||||
Match->Status.QstCod = Gam_GetQstCodFromQstInd (Match->GamCod,
|
||||
Match->Status.QstInd);
|
||||
|
@ -2452,7 +2453,7 @@ static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match)
|
|||
|
||||
static void Mch_SetMatchStatusToEnd (struct Mch_Match *Match)
|
||||
{
|
||||
Match->Status.QstInd = Mch_AFTER_LAST_QUESTION; // After last question
|
||||
Match->Status.QstInd = Gam_AFTER_LAST_QUESTION; // After last question
|
||||
Match->Status.QstCod = -1L;
|
||||
Match->Status.Playing = false;
|
||||
Match->Status.Showing = Mch_END;
|
||||
|
|
|
@ -41,8 +41,6 @@
|
|||
|
||||
#define Mch_NEW_MATCH_SECTION_ID "new_match"
|
||||
|
||||
#define Mch_AFTER_LAST_QUESTION ((unsigned)((1UL << 31) - 1)) // 2^31 - 1, don't change this number because it is used in database to indicate that a match is finished
|
||||
|
||||
#define Mch_NUM_SHOWING 5
|
||||
typedef enum
|
||||
{
|
||||
|
|
|
@ -1494,7 +1494,7 @@ static long Pho_GetTimeAvgPhotoWasComputed (long DegCod)
|
|||
/***** Get last time an average photo was computed from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get last time"
|
||||
" an average photo was computed",
|
||||
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" // row[0]
|
||||
"SELECT COALESCE(MIN(UNIX_TIMESTAMP(TimeAvgPhoto)),0)" // row[0]
|
||||
" FROM sta_degrees"
|
||||
" WHERE DegCod=%ld",
|
||||
DegCod) == 1)
|
||||
|
|
Loading…
Reference in New Issue