From a6dae83d814ef400bd5b302b4fda8bae6d2de991 Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 20 May 2021 12:16:49 +0200 Subject: [PATCH] =?UTF-8?q?Version=2020.78.1:=20=20May=2020,=202021=20=20F?= =?UTF-8?q?ixed=20bug=20in=20matches.=20Reported=20by=20Jes=C3=BAs=20Garri?= =?UTF-8?q?do=20Alc=C3=A1zar.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/cambios.sql | 6 +++- swad_changelog.h | 3 +- swad_exam.c | 27 ---------------- swad_exam.h | 2 -- swad_game.c | 47 ++++++++++++++++++--------- swad_match.c | 84 +++++++++++++++++++++++++----------------------- 6 files changed, 81 insertions(+), 88 deletions(-) diff --git a/sql/cambios.sql b/sql/cambios.sql index 8d6d84728..9507913fe 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -13503,5 +13503,9 @@ RENAME TABLE pho_clicks_without_photo TO usr_clicks_without_photo; SELECT gam_questions.QstCod,gam_questions.QstInd,tst_questions.AnsType,tst_questions.Shuffle FROM gam_questions,tst_questions WHERE gam_questions.GamCod=7 AND gam_questions.QstCod=tst_questions.QstCod ORDER BY gam_questions.QstInd; - + +--------------------------- + +SELECT COUNT(tst_answers.AnsInd) AS N FROM tst_answers,gam_questions WHERE gam_questions.GamCod=8 AND gam_questions.QstCod=tst_answers.QstCod GROUP BY tst_answers.QstCod; + \ No newline at end of file diff --git a/swad_changelog.h b/swad_changelog.h index 271f4d37d..2409e1d24 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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. */ -#define Log_PLATFORM_VERSION "SWAD 20.78 (2021-05-19)" +#define Log_PLATFORM_VERSION "SWAD 20.78.1 (2021-05-20)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 20.78.1: May 20, 2021 Fixed bug in matches. Reported by Jesús Garrido Alcázar. (311317 lines) Version 20.78: May 19, 2021 New module swad_chat_database for database queries related to chat. (311327 lines) Version 20.77: May 18, 2021 New module swad_banner_database for database queries related to banners. (311249 lines) Version 20.76: May 11, 2021 New module swad_atendance_database for database queries related to attendance events. (311109 lines) diff --git a/swad_exam.c b/swad_exam.c index f71419e6c..3e8485cc5 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -1975,30 +1975,3 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope) return 0.0; // Not reached } } - -/*****************************************************************************/ -/*************** Get maximum score of an exam from database *******************/ -/*****************************************************************************/ - -void Exa_GetScoreRange (long ExaCod,double *MinScore,double *MaxScore) - { - unsigned NumAnswers; - - /***** Get number of answers of exam from database *****/ - NumAnswers = (unsigned) - DB_QueryCOUNT ("can not get data of a question", - "SELECT COUNT(tst_answers.AnsInd)" - " FROM tst_answers," - "exa_set_questions" - " WHERE exa_set_questions.ExaCod=%ld" - " AND exa_set_questions.QstCod=tst_answers.QstCod" - " GROUP BY tst_answers.QstCod", - ExaCod); - if (NumAnswers < 2) - Err_ShowErrorAndExit ("Wrong number of answers."); - - /***** Set minimum and maximum scores *****/ - *MinScore = *MaxScore = 0.0; - *MinScore += -1.0 / (double) (NumAnswers - 1); - *MaxScore += 1.0; - } diff --git a/swad_exam.h b/swad_exam.h index 7a99703ed..93dc4f70a 100644 --- a/swad_exam.h +++ b/swad_exam.h @@ -95,6 +95,4 @@ unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope); unsigned Exa_GetNumExams (Hie_Lvl_Level_t Scope); double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope); -void Exa_GetScoreRange (long ExaCod,double *MinScore,double *MaxScore); - #endif diff --git a/swad_game.c b/swad_game.c index c3461f277..5e3e350fd 100644 --- a/swad_game.c +++ b/swad_game.c @@ -2879,23 +2879,38 @@ void Gam_ShowTstTagsPresentInAGame (long GamCod) void Gam_GetScoreRange (long GamCod,double *MinScore,double *MaxScore) { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumQsts; + unsigned NumQst; unsigned NumAnswers; - /***** Get number of answers of a game from database *****/ - NumAnswers = (unsigned) - DB_QueryCOUNT ("can not number of answers of a question", - "SELECT COUNT(tst_answers.AnsInd)" - " FROM tst_answers," - "gam_questions" - " WHERE gam_questions.GamCod=%ld" - " AND gam_questions.QstCod=tst_answers.QstCod" - " GROUP BY tst_answers.QstCod", - GamCod); - if (NumAnswers < 2) - Err_WrongAnswerExit (); + /***** Get maximum score of a game from database *****/ + NumQsts = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get data of a question", + "SELECT COUNT(tst_answers.AnsInd) AS N" // row[0] + " FROM tst_answers,gam_questions" + " WHERE gam_questions.GamCod=%ld" + " AND gam_questions.QstCod=tst_answers.QstCod" + " GROUP BY tst_answers.QstCod", + GamCod); + for (NumQst = 0, *MinScore = *MaxScore = 0.0; + NumQst < NumQsts; + NumQst++) + { + row = mysql_fetch_row (mysql_res); - /***** Set minimum and maximum scores *****/ - *MinScore = *MaxScore = 0.0; - *MinScore += -1.0 / (double) (NumAnswers - 1); - *MaxScore += 1.0; + /* Get number of answers (row[0]) for this question */ + if (sscanf (row[0],"%u",&NumAnswers) != 1) + NumAnswers = 0; + + /* Accumulate minimum and maximum score */ + if (NumAnswers < 2) + Err_ShowErrorAndExit ("Wrong number of answers."); + *MinScore += -1.0 / (double) (NumAnswers - 1); + *MaxScore += 1.0; + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); } diff --git a/swad_match.c b/swad_match.c index 2f7b97cea..2f50b2885 100644 --- a/swad_match.c +++ b/swad_match.c @@ -1733,7 +1733,7 @@ void Mch_ResumeMatch (void) /***** Show current match status *****/ HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\""); - Mch_ShowMatchStatusForTch (&Match); + Mch_ShowMatchStatusForTch (&Match); HTM_DIV_End (); } @@ -2852,14 +2852,14 @@ static void Mch_ShowRightColumnTch (const struct Mch_Match *Match) /***** Start right container *****/ HTM_DIV_Begin ("class=\"MCH_RIGHT_TCH\""); - /***** Top row: match title *****/ - Mch_ShowMatchTitleTch (Match); + /***** Top row: match title *****/ + Mch_ShowMatchTitleTch (Match); - /***** Bottom row: current question and possible answers *****/ - if (Match->Status.Showing == Mch_END) // Match over - Mch_ShowMatchScore (Match); - else // Match not over - Mch_ShowQuestionAndAnswersTch (Match); + /***** Bottom row: current question and possible answers *****/ + if (Match->Status.Showing == Mch_END) // Match over + Mch_ShowMatchScore (Match); + else // Match not over + Mch_ShowQuestionAndAnswersTch (Match); /***** End right container *****/ HTM_DIV_End (); @@ -3516,6 +3516,7 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match) Range = MaxScore - MinScore; if (Range == 0.0) return; + NumRowsPerScorePoint = (double) Mch_NUM_ROWS_SCORE / Range; /***** Get maximum number of users *****/ @@ -3531,7 +3532,7 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match) /***** Get scores from database *****/ NumScores = (unsigned) DB_QuerySELECT (&mysql_res,"can not get scores", - "SELECT Score," // row[0] + "SELECT Score," // row[0] "COUNT(*) AS NumUsrs" // row[1] " FROM mch_results" " WHERE MchCod=%ld" @@ -3542,43 +3543,44 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match) /***** Begin table ****/ HTM_TABLE_BeginWide (); - /***** Get and draw scores *****/ - for (NumScore = 0, NumRow = 0; - NumScore < NumScores; - NumScore++) - { - /***** Get score and number of users from database *****/ - row = mysql_fetch_row (mysql_res); + /***** Get and draw scores *****/ + for (NumScore = 0, NumRow = 0; + NumScore < NumScores; + NumScore++) + { + /***** Get score and number of users from database *****/ + row = mysql_fetch_row (mysql_res); - /* Get score (row[0]) */ - Str_SetDecimalPointToUS (); // To get the decimal point as a dot - if (sscanf (row[0],"%lf",&Score) != 1) - Score = 0.0; - Str_SetDecimalPointToLocal (); // Return to local system + /* Get score (row[0]) */ + Str_SetDecimalPointToUS (); // To get the decimal point as a dot + if (sscanf (row[0],"%lf",&Score) != 1) + Score = 0.0; + Str_SetDecimalPointToLocal (); // Return to local system - /* Get number of users (row[1]) *****/ - if (sscanf (row[1],"%u",&NumUsrs) != 1) - NumUsrs = 0; + /* Get number of users (row[1]) *****/ + if (sscanf (row[1],"%u",&NumUsrs) != 1) + NumUsrs = 0; - /***** Draw empty rows until reaching the adequate row *****/ - NumRowForThisScore = (unsigned) ((MaxScore - Score) * NumRowsPerScorePoint); - if (NumRowForThisScore == Mch_NUM_ROWS_SCORE) - NumRowForThisScore = Mch_NUM_ROWS_SCORE - 1; + /***** Draw empty rows until reaching the adequate row *****/ + NumRowForThisScore = (unsigned) ((MaxScore - Score) * NumRowsPerScorePoint); + if (NumRowForThisScore == Mch_NUM_ROWS_SCORE) + NumRowForThisScore = Mch_NUM_ROWS_SCORE - 1; + for (; + NumRow < NumRowForThisScore; + NumRow++) + Mch_DrawEmptyScoreRow (NumRow,MinScore,MaxScore); + + /***** Draw row for this score *****/ + Mch_DrawScoreRow (Score,MinScore,MaxScore,NumRow,NumUsrs,MaxUsrs); + + NumRow++; + } + + /***** Draw final empty rows *****/ for (; - NumRow < NumRowForThisScore; + NumRow < Mch_NUM_ROWS_SCORE; NumRow++) - Mch_DrawEmptyScoreRow (NumRow,MinScore,MaxScore); - - /***** Draw row for this score *****/ - Mch_DrawScoreRow (Score,MinScore,MaxScore,NumRow,NumUsrs,MaxUsrs); - NumRow++; - } - - /***** Draw final empty rows *****/ - for (; - NumRow < Mch_NUM_ROWS_SCORE; - NumRow++) - Mch_DrawEmptyScoreRow (NumRow,MinScore,MaxScore); + Mch_DrawEmptyScoreRow (NumRow,MinScore,MaxScore); /***** End table *****/ HTM_TABLE_End ();