From 377f4c00c22e7caf3bd877a182722fd2387b6f05 Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 11 May 2020 14:56:49 +0200 Subject: [PATCH] Version19.223.3 --- swad_changelog.h | 2 +- swad_exam_print.c | 29 +++++++++++++++++------------ swad_figure.c | 2 +- swad_test.c | 45 ++++++++++++++++++++++----------------------- swad_test_print.c | 29 +++++++++++++++++------------ swad_test_type.h | 2 +- 6 files changed, 59 insertions(+), 50 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 29f93180..81ef724f 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ ps2pdf source.ps destination.pdf #define JS_FILE "swad19.223.js" /* Version 19.223.4: May 11, 2020 Stored unique/multiple choice questions in exam print. (? lines) - Version 19.223.3: May 11, 2020 Fixed bug in test exam print, reported by Julio Ortega Lopera. (303043 lines) + Version 19.223.3: May 11, 2020 Fixed bug in test exam print, reported by Julio Ortega Lopera. (303050 lines) Version 19.223.2: May 11, 2020 Stored T/F answers in exam print. (303034 lines) Version 19.223.1: May 11, 2020 Code refactoring in exam print. Stored float and text answers. (303023 lines) Version 19.223: May 11, 2020 Store int answer and refresh exam print. (303024 lines) diff --git a/swad_exam_print.c b/swad_exam_print.c index 0d58b232..9b6109de 100644 --- a/swad_exam_print.c +++ b/swad_exam_print.c @@ -465,18 +465,17 @@ static void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print) "SELECT exa_print_questions.QstCod," // row[0] "exa_print_questions.SetCod," // row[1] "tst_questions.AnsType," // row[2] - "exa_print_questions.Indexes," // row[3] - "exa_print_questions.Answers" // row[4] - " FROM exa_print_questions,tst_questions" + "exa_print_questions.Score," // row[3] + "exa_print_questions.Indexes," // row[4] + "exa_print_questions.Answers" // row[5] + " FROM exa_print_questions LEFT JOIN tst_questions" + " ON (exa_print_questions.QstCod=tst_questions.QstCod)" " WHERE exa_print_questions.PrnCod=%ld" - " AND exa_print_questions.QstCod=tst_questions.QstCod" " ORDER BY exa_print_questions.QstInd", Print->PrnCod); /***** Get questions *****/ - // Some questions may be deleted, so the number of questions retrieved - // could be lower than the original number of questions in the exam print - if (NumQsts <= Print->NumQsts) + if (NumQsts == Print->NumQsts) for (NumQst = 0; NumQst < NumQsts; NumQst++) @@ -494,12 +493,18 @@ static void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print) /* Get answer type (row[2]) */ AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[2]); - /* Get indexes for this question (row[3]) */ - Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[3], + /* Get score (row[3]) */ + Str_SetDecimalPointToUS (); // To get the decimal point as a dot + if (sscanf (row[3],"%lf",&Print->PrintedQuestions[NumQst].Score) != 1) + Lay_ShowErrorAndExit ("Wrong question score."); + Str_SetDecimalPointToLocal (); // Return to local system + + /* Get indexes for this question (row[4]) */ + Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[4], Tst_MAX_BYTES_INDEXES_ONE_QST); - /* Get answers selected by user for this question (row[4]) */ - Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[4], + /* Get answers selected by user for this question (row[5]) */ + Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[5], Tst_MAX_BYTES_ANSWERS_ONE_QST); /* Replace each comma by a separator of multiple parameters */ @@ -514,7 +519,7 @@ static void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); - if (NumQsts > Print->NumQsts) + if (NumQsts != Print->NumQsts) Lay_WrongExamExit (); } diff --git a/swad_figure.c b/swad_figure.c index a44cb028..e639c7e3 100644 --- a/swad_figure.c +++ b/swad_figure.c @@ -3218,7 +3218,7 @@ static void Fig_GetAndShowTestsStats (void) } /***** Get the stats about test questions from this location *****/ - Tst_GetTestStats (Tst_ANS_ALL,&Stats); + Tst_GetTestStats (Tst_ANS_UNKNOWN,&Stats); /***** Write number of assignments *****/ HTM_TR_Begin (NULL); diff --git a/swad_test.c b/swad_test.c index d2cd1e90..27b14882 100644 --- a/swad_test.c +++ b/swad_test.c @@ -4972,8 +4972,7 @@ Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD) if (!strcmp (StrAnsTypeBD,Tst_StrAnswerTypesDB[AnsType])) return AnsType; - Lay_ShowErrorAndExit ("Wrong type of answer. 1"); - return (Tst_AnswerType_t) 0; // Not reached + return Tst_ANS_UNKNOWN; } /*****************************************************************************/ @@ -5059,9 +5058,9 @@ static void Tst_GetQstFromForm (struct Tst_Question *Question) Par_GetParToUnsignedLong ("AnswerType", 0, Tst_NUM_ANS_TYPES - 1, - (unsigned long) Tst_ANS_ALL); - if (Question->Answer.Type == Tst_ANS_ALL) - Lay_ShowErrorAndExit ("Wrong type of answer. 4"); + (unsigned long) Tst_ANS_UNKNOWN); + if (Question->Answer.Type == Tst_ANS_UNKNOWN) + Lay_ShowErrorAndExit ("Wrong type of answer."); /***** Get question tags *****/ for (NumTag = 0; @@ -6383,7 +6382,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy switch (Scope) { case Hie_SYS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of test questions", "SELECT COUNT(*),SUM(NumHits),SUM(Score)" " FROM tst_questions"); @@ -6395,7 +6394,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy Tst_StrAnswerTypesDB[AnsType]); break; case Hie_CTY: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of test questions", "SELECT COUNT(*),SUM(NumHits),SUM(Score)" " FROM institutions,centres,degrees,courses,tst_questions" @@ -6419,7 +6418,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy Tst_StrAnswerTypesDB[AnsType]); break; case Hie_INS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of test questions", "SELECT COUNT(*),SUM(NumHits),SUM(Score)" " FROM centres,degrees,courses,tst_questions" @@ -6441,7 +6440,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy Tst_StrAnswerTypesDB[AnsType]); break; case Hie_CTR: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of test questions", "SELECT COUNT(*),SUM(NumHits),SUM(Score)" " FROM degrees,courses,tst_questions" @@ -6461,7 +6460,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy Tst_StrAnswerTypesDB[AnsType]); break; case Hie_DEG: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of test questions", "SELECT COUNT(*),SUM(NumHits),SUM(Score)" " FROM courses,tst_questions" @@ -6479,7 +6478,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy Tst_StrAnswerTypesDB[AnsType]); break; case Hie_CRS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of test questions", "SELECT COUNT(*),SUM(NumHits),SUM(Score)" " FROM tst_questions" @@ -6541,7 +6540,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT switch (Scope) { case Hie_SYS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with test questions", "SELECT COUNT(DISTINCT CrsCod)" @@ -6555,7 +6554,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT Tst_StrAnswerTypesDB[AnsType]); break; case Hie_CTY: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6581,7 +6580,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT Tst_StrAnswerTypesDB[AnsType]); break; case Hie_INS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6605,7 +6604,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT Tst_StrAnswerTypesDB[AnsType]); break; case Hie_CTR: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6627,7 +6626,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT Tst_StrAnswerTypesDB[AnsType]); break; case Hie_DEG: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with test questions", "SELECT COUNTDISTINCT (tst_questions.CrsCod)" @@ -6647,7 +6646,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT Tst_StrAnswerTypesDB[AnsType]); break; case Hie_CRS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with test questions", "SELECT COUNT(DISTINCT CrsCod)" @@ -6697,7 +6696,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts switch (Scope) { case Hie_SYS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with pluggable test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6717,7 +6716,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); break; case Hie_CTY: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with pluggable test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6749,7 +6748,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); break; case Hie_INS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with pluggable test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6779,7 +6778,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); break; case Hie_CTR: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with pluggable test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6807,7 +6806,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); break; case Hie_DEG: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with pluggable test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" @@ -6833,7 +6832,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); break; case Hie_CRS: - if (AnsType == Tst_ANS_ALL) + if (AnsType == Tst_ANS_UNKNOWN) // Any type DB_QuerySELECT (&mysql_res,"can not get number of courses" " with pluggable test questions", "SELECT COUNT(DISTINCT tst_questions.CrsCod)" diff --git a/swad_test_print.c b/swad_test_print.c index 5b6f6508..0edd5b12 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -2274,18 +2274,17 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print) " of a test exam", "SELECT tst_exam_questions.QstCod," // row[0] "tst_questions.AnsType," // row[1] - "tst_exam_questions.Indexes," // row[2] - "tst_exam_questions.Answers" // row[3] - " FROM tst_exam_questions,tst_questions" + "tst_exam_questions.Score," // row[2] + "tst_exam_questions.Indexes," // row[3] + "tst_exam_questions.Answers" // row[4] + " FROM tst_exam_questions LEFT JOIN tst_questions" + " ON (tst_exam_questions.QstCod=tst_questions.QstCod)" " WHERE tst_exam_questions.ExaCod=%ld" - " AND tst_exam_questions.QstCod=tst_questions.QstCod" " ORDER BY tst_exam_questions.QstInd", Print->PrnCod); /***** Get questions *****/ - // Some questions may be deleted, so the number of questions retrieved - // could be lower than the original number of questions in the exam print - if (NumQsts <= Print->NumQsts) + if (NumQsts == Print->NumQsts) for (NumQst = 0; NumQst < NumQsts; NumQst++) @@ -2299,12 +2298,18 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print) /* Get answer type (row[1]) */ AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[1]); - /* Get indexes for this question (row[2]) */ - Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[2], + /* Get score (row[2]) */ + Str_SetDecimalPointToUS (); // To get the decimal point as a dot + if (sscanf (row[2],"%lf",&Print->PrintedQuestions[NumQst].Score) != 1) + Lay_ShowErrorAndExit ("Wrong question score."); + Str_SetDecimalPointToLocal (); // Return to local system + + /* Get indexes for this question (row[3]) */ + Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[3], Tst_MAX_BYTES_INDEXES_ONE_QST); - /* Get answers selected by user for this question (row[3]) */ - Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[3], + /* Get answers selected by user for this question (row[4]) */ + Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[4], Tst_MAX_BYTES_ANSWERS_ONE_QST); /* Replace each comma by a separator of multiple parameters */ @@ -2319,7 +2324,7 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); - if (NumQsts > Print->NumQsts) + if (NumQsts != Print->NumQsts) Lay_WrongExamExit (); } diff --git a/swad_test_type.h b/swad_test_type.h index e369afb4..8ab03d89 100644 --- a/swad_test_type.h +++ b/swad_test_type.h @@ -68,7 +68,7 @@ typedef enum Tst_ANS_UNIQUE_CHOICE = 3, Tst_ANS_MULTIPLE_CHOICE = 4, Tst_ANS_TEXT = 5, - Tst_ANS_ALL = 6, // All/any type of answer + Tst_ANS_UNKNOWN = 6, // Unknown/all/any type of answer } Tst_AnswerType_t; struct Tst_Question