Version 21.45.1: Oct 25, 2021 Code refactoring in test questions.

This commit is contained in:
acanas 2021-10-25 22:35:24 +02:00
parent 12bb423b13
commit 352de7c69d
8 changed files with 54 additions and 52 deletions

View File

@ -5223,7 +5223,7 @@ int swad__getMatchStatus (struct soap *soap,
case Mch_STEM: // Showing only the question stem case Mch_STEM: // Showing only the question stem
case Mch_ANSWERS: // Showing the question stem and the answers case Mch_ANSWERS: // Showing the question stem and the answers
case Mch_RESULTS: // Showing the results case Mch_RESULTS: // Showing the results
getMatchStatusOut->numAnswers = (int) Qst_GetNumAnswersQst (Match.Status.QstCod); getMatchStatusOut->numAnswers = (int) Qst_DB_GetNumAnswersQst (Match.Status.QstCod);
Mch_GetQstAnsFromDB (Match.MchCod, Mch_GetQstAnsFromDB (Match.MchCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Match.Status.QstInd, Match.Status.QstInd,

View File

@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/ */
#define Log_PLATFORM_VERSION "SWAD 21.45 (2021-10-25)" #define Log_PLATFORM_VERSION "SWAD 21.45.1 (2021-10-25)"
#define CSS_FILE "swad20.45.css" #define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js" #define JS_FILE "swad20.69.1.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 21.45.1: Oct 25, 2021 Code refactoring in test questions. (320932 lines)
Version 21.45: Oct 25, 2021 Functions moved to module swad_question. (320930 lines) Version 21.45: Oct 25, 2021 Functions moved to module swad_question. (320930 lines)
Version 21.44: Oct 25, 2021 Functions moved to module swad_question. (320928 lines) Version 21.44: Oct 25, 2021 Functions moved to module swad_question. (320928 lines)
Version 21.43: Oct 25, 2021 New module swad_question for test/exam/game questions. (320919 lines) Version 21.43: Oct 25, 2021 New module swad_question for test/exam/game questions. (320919 lines)

View File

@ -2013,7 +2013,7 @@ static void Fig_GetAndShowTestsStats (void)
AnsType++) AnsType++)
{ {
/***** Get the stats about test questions from this location *****/ /***** Get the stats about test questions from this location *****/
Tst_GetTestStats (AnsType,&Stats); Qst_GetTestStats (AnsType,&Stats);
/***** Write number of assignments *****/ /***** Write number of assignments *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -2062,7 +2062,7 @@ static void Fig_GetAndShowTestsStats (void)
} }
/***** Get the stats about test questions from this location *****/ /***** Get the stats about test questions from this location *****/
Tst_GetTestStats (Qst_ANS_UNKNOWN,&Stats); Qst_GetTestStats (Qst_ANS_UNKNOWN,&Stats);
/***** Write number of assignments *****/ /***** Write number of assignments *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);

View File

@ -3018,7 +3018,7 @@ static void Mch_ShowQuestionAndAnswersStd (const struct Mch_Match *Match,
char *Class; char *Class;
/***** Get number of options in this question *****/ /***** Get number of options in this question *****/
NumOptions = Qst_GetNumAnswersQst (Match->Status.QstCod); NumOptions = Qst_DB_GetNumAnswersQst (Match->Status.QstCod);
/***** Begin table *****/ /***** Begin table *****/
HTM_TABLE_BeginWidePadding (8); HTM_TABLE_BeginWidePadding (8);

View File

@ -1408,10 +1408,10 @@ void Qst_PutParamsEditQst (void *Questions)
} }
/*****************************************************************************/ /*****************************************************************************/
/*************** Get answers of a test question from database ****************/ /************ Get number of answers of a question from database **************/
/*****************************************************************************/ /*****************************************************************************/
unsigned Qst_GetNumAnswersQst (long QstCod) unsigned Qst_DB_GetNumAnswersQst (long QstCod)
{ {
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of answers of a question", DB_QueryCOUNT ("can not get number of answers of a question",
@ -1421,6 +1421,10 @@ unsigned Qst_GetNumAnswersQst (long QstCod)
QstCod); QstCod);
} }
/*****************************************************************************/
/***************** Get answers of a question from database *******************/
/*****************************************************************************/
void Qst_GetAnswersQst (struct Qst_Question *Question,MYSQL_RES **mysql_res, void Qst_GetAnswersQst (struct Qst_Question *Question,MYSQL_RES **mysql_res,
bool Shuffle) bool Shuffle)
{ {
@ -3518,7 +3522,7 @@ void Qst_RemoveOneQstFromDB (long CrsCod,long QstCod)
/***** Remove the question from all the tables *****/ /***** Remove the question from all the tables *****/
/* Remove answers and tags from this test question */ /* Remove answers and tags from this test question */
Qst_RemAnsFromQst (QstCod); Qst_DB_RemAnsFromQst (QstCod);
Tag_DB_RemTagsFromQst (QstCod); Tag_DB_RemTagsFromQst (QstCod);
Tag_DB_RemoveUnusedTagsFromCrs (CrsCod); Tag_DB_RemoveUnusedTagsFromCrs (CrsCod);
@ -3694,7 +3698,7 @@ void Qst_InsertOrUpdateQstIntoDB (struct Qst_Question *Question)
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
/* Remove answers and tags from this test question */ /* Remove answers and tags from this test question */
Qst_RemAnsFromQst (Question->QstCod); Qst_DB_RemAnsFromQst (Question->QstCod);
Tag_DB_RemTagsFromQst (Question->QstCod); Tag_DB_RemTagsFromQst (Question->QstCod);
} }
} }
@ -3823,7 +3827,7 @@ void Qst_RemoveCrsQsts (long CrsCod)
/******************** Remove answers from a test question ********************/ /******************** Remove answers from a test question ********************/
/*****************************************************************************/ /*****************************************************************************/
void Qst_RemAnsFromQst (long QstCod) void Qst_DB_RemAnsFromQst (long QstCod)
{ {
/***** Remove answers *****/ /***** Remove answers *****/
DB_QueryDELETE ("can not remove the answers of a question", DB_QueryDELETE ("can not remove the answers of a question",
@ -4519,3 +4523,32 @@ unsigned Qst_GetNumCoursesWithPluggableQuestions (HieLvl_Level_t Scope,Qst_Answe
return 0; return 0;
} }
} }
/*****************************************************************************/
/*********************** Get stats about test questions **********************/
/*****************************************************************************/
void Qst_GetTestStats (Qst_AnswerType_t AnsType,struct Qst_Stats *Stats)
{
Stats->NumQsts = 0;
Stats->NumCoursesWithQuestions = Stats->NumCoursesWithPluggableQuestions = 0;
Stats->AvgQstsPerCourse = 0.0;
Stats->NumHits = 0L;
Stats->AvgHitsPerCourse = 0.0;
Stats->AvgHitsPerQuestion = 0.0;
Stats->TotalScore = 0.0;
Stats->AvgScorePerQuestion = 0.0;
if (Qst_GetNumQuestions (Gbl.Scope.Current,AnsType,Stats))
{
if ((Stats->NumCoursesWithQuestions = Qst_GetNumCoursesWithQuestions (Gbl.Scope.Current,AnsType)) != 0)
{
Stats->NumCoursesWithPluggableQuestions = Qst_GetNumCoursesWithPluggableQuestions (Gbl.Scope.Current,AnsType);
Stats->AvgQstsPerCourse = (double) Stats->NumQsts / (double) Stats->NumCoursesWithQuestions;
Stats->AvgHitsPerCourse = (double) Stats->NumHits / (double) Stats->NumCoursesWithQuestions;
}
Stats->AvgHitsPerQuestion = (double) Stats->NumHits / (double) Stats->NumQsts;
if (Stats->NumHits)
Stats->AvgScorePerQuestion = Stats->TotalScore / (double) Stats->NumHits;
}
}

View File

@ -181,7 +181,7 @@ void Qst_WriteQuestionRowForSelection (unsigned QstInd,
void Qst_PutParamsEditQst (void *Questions); void Qst_PutParamsEditQst (void *Questions);
unsigned Qst_GetNumAnswersQst (long QstCod); unsigned Qst_DB_GetNumAnswersQst (long QstCod);
void Qst_GetAnswersQst (struct Qst_Question *Question,MYSQL_RES **mysql_res, void Qst_GetAnswersQst (struct Qst_Question *Question,MYSQL_RES **mysql_res,
bool Shuffle); bool Shuffle);
@ -273,7 +273,7 @@ void Qst_InsertOrUpdateQstIntoDB (struct Qst_Question *Question);
void Qst_InsertAnswersIntoDB (struct Qst_Question *Question); void Qst_InsertAnswersIntoDB (struct Qst_Question *Question);
void Qst_RemoveCrsQsts (long CrsCod); void Qst_RemoveCrsQsts (long CrsCod);
void Qst_RemAnsFromQst (long QstCod); void Qst_DB_RemAnsFromQst (long QstCod);
void Qst_RemoveMediaFromStemOfQst (long CrsCod,long QstCod); void Qst_RemoveMediaFromStemOfQst (long CrsCod,long QstCod);
void Qst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod); void Qst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod);
void Qst_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod); void Qst_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod);
@ -286,4 +286,6 @@ unsigned Qst_GetNumQuestions (HieLvl_Level_t Scope,Qst_AnswerType_t AnsType,stru
unsigned Qst_GetNumCoursesWithQuestions (HieLvl_Level_t Scope,Qst_AnswerType_t AnsType); unsigned Qst_GetNumCoursesWithQuestions (HieLvl_Level_t Scope,Qst_AnswerType_t AnsType);
unsigned Qst_GetNumCoursesWithPluggableQuestions (HieLvl_Level_t Scope,Qst_AnswerType_t AnsType); unsigned Qst_GetNumCoursesWithPluggableQuestions (HieLvl_Level_t Scope,Qst_AnswerType_t AnsType);
void Qst_GetTestStats (Qst_AnswerType_t AnsType,struct Qst_Stats *Stats);
#endif #endif

View File

@ -96,8 +96,8 @@ static void TstPrn_GetAnswersFromForm (struct TstPrn_Print *Print);
static bool Tst_CheckIfNextTstAllowed (void); static bool Tst_CheckIfNextTstAllowed (void);
static unsigned Tst_GetNumTstExamsGeneratedByMe (void); static unsigned Tst_GetNumTstExamsGeneratedByMe (void);
static void Tst_IncreaseMyNumTstExams (void); static void Tst_DB_IncreaseMyNumTstExams (void);
static void Tst_UpdateLastAccTst (unsigned NumQsts); static void Tst_DB_UpdateLastAccTst (unsigned NumQsts);
static void Tst_PutIconsTests (__attribute__((unused)) void *Args); static void Tst_PutIconsTests (__attribute__((unused)) void *Args);
@ -242,7 +242,7 @@ void Tst_ShowNewTest (void)
if (Print.NumQsts.All) if (Print.NumQsts.All)
{ {
/***** Increase number of exams generated (answered or not) by me *****/ /***** Increase number of exams generated (answered or not) by me *****/
Tst_IncreaseMyNumTstExams (); Tst_DB_IncreaseMyNumTstExams ();
NumTstExamsGeneratedByMe = Tst_GetNumTstExamsGeneratedByMe (); NumTstExamsGeneratedByMe = Tst_GetNumTstExamsGeneratedByMe ();
/***** Create new test exam in database *****/ /***** Create new test exam in database *****/
@ -255,7 +255,7 @@ void Tst_ShowNewTest (void)
/***** Update date-time of my next allowed access to test *****/ /***** Update date-time of my next allowed access to test *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_STD) if (Gbl.Usrs.Me.Role.Logged == Rol_STD)
Tst_UpdateLastAccTst (Questions.NumQsts); Tst_DB_UpdateLastAccTst (Questions.NumQsts);
} }
else // No questions found else // No questions found
{ {
@ -544,7 +544,7 @@ static unsigned Tst_GetNumTstExamsGeneratedByMe (void)
/*********** Update my number of accesses to test in this course *************/ /*********** Update my number of accesses to test in this course *************/
/*****************************************************************************/ /*****************************************************************************/
static void Tst_IncreaseMyNumTstExams (void) static void Tst_DB_IncreaseMyNumTstExams (void)
{ {
/***** Trivial check *****/ /***** Trivial check *****/
if (!Gbl.Usrs.Me.IBelongToCurrentCrs) if (!Gbl.Usrs.Me.IBelongToCurrentCrs)
@ -564,7 +564,7 @@ static void Tst_IncreaseMyNumTstExams (void)
/************ Update date-time of my next allowed access to test *************/ /************ Update date-time of my next allowed access to test *************/
/*****************************************************************************/ /*****************************************************************************/
static void Tst_UpdateLastAccTst (unsigned NumQsts) static void Tst_DB_UpdateLastAccTst (unsigned NumQsts)
{ {
/***** Update date-time and number of questions of this test *****/ /***** Update date-time and number of questions of this test *****/
DB_QueryUPDATE ("can not update time and number of questions of this test", DB_QueryUPDATE ("can not update time and number of questions of this test",
@ -1273,32 +1273,3 @@ void Tst_RemoveCrsTests (long CrsCod)
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
CrsCod); CrsCod);
} }
/*****************************************************************************/
/*********************** Get stats about test questions **********************/
/*****************************************************************************/
void Tst_GetTestStats (Qst_AnswerType_t AnsType,struct Qst_Stats *Stats)
{
Stats->NumQsts = 0;
Stats->NumCoursesWithQuestions = Stats->NumCoursesWithPluggableQuestions = 0;
Stats->AvgQstsPerCourse = 0.0;
Stats->NumHits = 0L;
Stats->AvgHitsPerCourse = 0.0;
Stats->AvgHitsPerQuestion = 0.0;
Stats->TotalScore = 0.0;
Stats->AvgScorePerQuestion = 0.0;
if (Qst_GetNumQuestions (Gbl.Scope.Current,AnsType,Stats))
{
if ((Stats->NumCoursesWithQuestions = Qst_GetNumCoursesWithQuestions (Gbl.Scope.Current,AnsType)) != 0)
{
Stats->NumCoursesWithPluggableQuestions = Qst_GetNumCoursesWithPluggableQuestions (Gbl.Scope.Current,AnsType);
Stats->AvgQstsPerCourse = (double) Stats->NumQsts / (double) Stats->NumCoursesWithQuestions;
Stats->AvgHitsPerCourse = (double) Stats->NumHits / (double) Stats->NumCoursesWithQuestions;
}
Stats->AvgHitsPerQuestion = (double) Stats->NumHits / (double) Stats->NumQsts;
if (Stats->NumHits)
Stats->AvgScorePerQuestion = Stats->TotalScore / (double) Stats->NumHits;
}
}

View File

@ -74,9 +74,4 @@ unsigned Tst_CountNumQuestionsInList (const char *ListQuestions);
void Tst_RemoveCrsTests (long CrsCod); void Tst_RemoveCrsTests (long CrsCod);
void Tst_GetTestStats (Qst_AnswerType_t AnsType,struct Qst_Stats *Stats);
unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res,
const struct Qst_Question *Question);
#endif #endif