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.
|
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 CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.6.2.js"
|
#define JS_FILE "swad20.6.2.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
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.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.68: Apr 26, 2021 New module swad_error. (309853 lines)
|
||||||
Version 20.67.11: Apr 26, 2021 Fixed bug in departments. (309677 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;
|
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 **********/
|
/********** Get number of sessions and check is edition is possible **********/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -93,9 +93,6 @@ void Exa_PutParamQstInd (unsigned QstInd);
|
||||||
unsigned Exa_GetParamQstInd (void);
|
unsigned Exa_GetParamQstInd (void);
|
||||||
long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd);
|
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);
|
bool Exa_CheckIfEditable (const struct Exa_Exam *Exam);
|
||||||
|
|
||||||
unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope);
|
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_SELECTED_QUESTIONS 10000
|
||||||
#define ExaSet_MAX_BYTES_LIST_SELECTED_QUESTIONS (ExaSet_MAX_SELECTED_QUESTIONS * (Cns_MAX_DECIMAL_DIGITS_LONG + 1))
|
#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 *******************************/
|
/******************************* Private types *******************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -848,7 +850,7 @@ static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
return DB_QuerySELECTUnsigned ("can not get previous set index",
|
return DB_QuerySELECTUnsigned ("can not get previous set index",
|
||||||
"SELECT MAX(SetInd)"
|
"SELECT COALESCE(MAX(SetInd),0)"
|
||||||
" FROM exa_sets"
|
" FROM exa_sets"
|
||||||
" WHERE ExaCod=%ld"
|
" WHERE ExaCod=%ld"
|
||||||
" AND SetInd<%u",
|
" AND SetInd<%u",
|
||||||
|
@ -864,22 +866,17 @@ static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
|
||||||
|
|
||||||
static unsigned ExaSet_GetNextSetIndexInExam (long ExaCod,unsigned SetInd)
|
static unsigned ExaSet_GetNextSetIndexInExam (long ExaCod,unsigned SetInd)
|
||||||
{
|
{
|
||||||
unsigned NextSetInd;
|
|
||||||
|
|
||||||
/***** Get next set index in an exam from database *****/
|
/***** Get next set index in an exam from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
NextSetInd = DB_QuerySELECTUnsigned ("can not get next set index",
|
return DB_QuerySELECTUnsigned ("can not get next set index",
|
||||||
"SELECT MIN(SetInd)"
|
"SELECT COALESCE(MIN(SetInd),%u)"
|
||||||
" FROM exa_sets"
|
" FROM exa_sets"
|
||||||
" WHERE ExaCod=%ld"
|
" WHERE ExaCod=%ld"
|
||||||
" AND SetInd>%u",
|
" AND SetInd>%u",
|
||||||
ExaCod,
|
ExaSet_AFTER_LAST_SET, // End of sets has been reached
|
||||||
SetInd);
|
ExaCod,
|
||||||
if (NextSetInd == 0)
|
SetInd);
|
||||||
NextSetInd = ExaSes_AFTER_LAST_QUESTION; // End of sets has been reached
|
|
||||||
|
|
||||||
return NextSetInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1866,7 +1863,7 @@ void ExaSet_MoveUpSet (void)
|
||||||
{
|
{
|
||||||
/* Indexes of sets to be exchanged */
|
/* Indexes of sets to be exchanged */
|
||||||
SetIndTop = ExaSet_GetPrevSetIndexInExam (Exam.ExaCod,SetIndBottom);
|
SetIndTop = ExaSet_GetPrevSetIndexInExam (Exam.ExaCod,SetIndBottom);
|
||||||
if (!SetIndTop)
|
if (SetIndTop == 0)
|
||||||
Err_ShowErrorAndExit ("Wrong set index.");
|
Err_ShowErrorAndExit ("Wrong set index.");
|
||||||
|
|
||||||
/* Exchange sets */
|
/* Exchange sets */
|
||||||
|
@ -1917,7 +1914,7 @@ void ExaSet_MoveDownSet (void)
|
||||||
{
|
{
|
||||||
/* Indexes of sets to be exchanged */
|
/* Indexes of sets to be exchanged */
|
||||||
SetIndBottom = ExaSet_GetNextSetIndexInExam (Exam.ExaCod,SetIndTop);
|
SetIndBottom = ExaSet_GetNextSetIndexInExam (Exam.ExaCod,SetIndTop);
|
||||||
if (!SetIndBottom)
|
if (SetIndBottom == ExaSet_AFTER_LAST_SET)
|
||||||
Err_ShowErrorAndExit ("Wrong set index.");
|
Err_ShowErrorAndExit ("Wrong set index.");
|
||||||
|
|
||||||
/* Exchange sets */
|
/* 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...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
||||||
"SELECT MAX(QstInd)"
|
"SELECT COALESCE(MAX(QstInd),0)"
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld"
|
" WHERE GamCod=%ld"
|
||||||
" AND QstInd<%u",
|
" 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 ************/
|
/************* Get next question index to a given index in a game ************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
// Input question index can be 0, 1, 2, 3... n-1
|
// 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 Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
unsigned NextQstInd;
|
|
||||||
|
|
||||||
/***** Get next question index in a game from database *****/
|
/***** Get next question index in a game from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
NextQstInd = DB_QuerySELECTUnsigned ("can not get next question index",
|
return DB_QuerySELECTUnsigned ("can not get next question index",
|
||||||
"SELECT MIN(QstInd)"
|
"SELECT COALESCE(MIN(QstInd),%u)"
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld"
|
" WHERE GamCod=%ld"
|
||||||
" AND QstInd>%u",
|
" AND QstInd>%u",
|
||||||
GamCod,
|
Gam_AFTER_LAST_QUESTION, // End of questions has been reached
|
||||||
QstInd);
|
GamCod,
|
||||||
if (NextQstInd == 0)
|
QstInd);
|
||||||
NextQstInd = Mch_AFTER_LAST_QUESTION; // End of questions has been reached
|
|
||||||
|
|
||||||
return NextQstInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2467,7 +2462,7 @@ void Gam_MoveDownQst (void)
|
||||||
{
|
{
|
||||||
/* Indexes of questions to be exchanged */
|
/* Indexes of questions to be exchanged */
|
||||||
QstIndBottom = Gam_GetNextQuestionIndexInGame (Game.GamCod,QstIndTop);
|
QstIndBottom = Gam_GetNextQuestionIndexInGame (Game.GamCod,QstIndTop);
|
||||||
if (!QstIndBottom)
|
if (QstIndBottom == Gam_AFTER_LAST_QUESTION)
|
||||||
Err_WrongQuestionIndexExit ();
|
Err_WrongQuestionIndexExit ();
|
||||||
|
|
||||||
/* Exchange questions */
|
/* Exchange questions */
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
#define Gam_MAX_CHARS_TITLE (128 - 1) // 127
|
#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_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
|
#define Gam_NUM_ORDERS 3
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -74,7 +76,7 @@ struct Gam_Games
|
||||||
long GamCod; // Selected/current game code
|
long GamCod; // Selected/current game code
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
long Selected; // Current match code
|
long Selected; // Current match code
|
||||||
long Current;
|
long Current;
|
||||||
} MchCod;
|
} MchCod;
|
||||||
unsigned QstInd; // Current question index
|
unsigned QstInd; // Current question index
|
||||||
|
|
|
@ -1806,7 +1806,8 @@ static void Mch_CreateIndexes (long GamCod,long MchCod)
|
||||||
"gam_questions.QstInd," // row[1]
|
"gam_questions.QstInd," // row[1]
|
||||||
"tst_questions.AnsType," // row[2]
|
"tst_questions.AnsType," // row[2]
|
||||||
"tst_questions.Shuffle" // row[3]
|
"tst_questions.Shuffle" // row[3]
|
||||||
" FROM gam_questions,tst_questions"
|
" FROM gam_questions,"
|
||||||
|
"tst_questions"
|
||||||
" WHERE gam_questions.GamCod=%ld"
|
" WHERE gam_questions.GamCod=%ld"
|
||||||
" AND gam_questions.QstCod=tst_questions.QstCod"
|
" AND gam_questions.QstCod=tst_questions.QstCod"
|
||||||
" ORDER BY gam_questions.QstInd",
|
" ORDER BY gam_questions.QstInd",
|
||||||
|
@ -2436,7 +2437,7 @@ static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match)
|
||||||
Match->Status.QstInd);
|
Match->Status.QstInd);
|
||||||
|
|
||||||
/***** Get question code *****/
|
/***** 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.QstCod = Gam_GetQstCodFromQstInd (Match->GamCod,
|
||||||
Match->Status.QstInd);
|
Match->Status.QstInd);
|
||||||
|
@ -2452,7 +2453,7 @@ static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match)
|
||||||
|
|
||||||
static void Mch_SetMatchStatusToEnd (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.QstCod = -1L;
|
||||||
Match->Status.Playing = false;
|
Match->Status.Playing = false;
|
||||||
Match->Status.Showing = Mch_END;
|
Match->Status.Showing = Mch_END;
|
||||||
|
|
|
@ -41,8 +41,6 @@
|
||||||
|
|
||||||
#define Mch_NEW_MATCH_SECTION_ID "new_match"
|
#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
|
#define Mch_NUM_SHOWING 5
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -1494,7 +1494,7 @@ static long Pho_GetTimeAvgPhotoWasComputed (long DegCod)
|
||||||
/***** Get last time an average photo was computed from database *****/
|
/***** Get last time an average photo was computed from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get last time"
|
if (DB_QuerySELECT (&mysql_res,"can not get last time"
|
||||||
" an average photo was computed",
|
" an average photo was computed",
|
||||||
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" // row[0]
|
"SELECT COALESCE(MIN(UNIX_TIMESTAMP(TimeAvgPhoto)),0)" // row[0]
|
||||||
" FROM sta_degrees"
|
" FROM sta_degrees"
|
||||||
" WHERE DegCod=%ld",
|
" WHERE DegCod=%ld",
|
||||||
DegCod) == 1)
|
DegCod) == 1)
|
||||||
|
|
Loading…
Reference in New Issue