From b4bc3aa6ef3996fefba3b21fa0c3c5491cff22fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 24 Sep 2019 01:41:51 +0200 Subject: [PATCH] Version19.12 --- sql/cambios.sql | 17 +++- sql/swad.sql | 11 ++- swad_changelog.h | 7 +- swad_database.c | 8 +- swad_game.c | 16 ++-- swad_match.c | 232 +++++++++++++++++++++++++++-------------------- swad_match.h | 2 + swad_parameter.c | 6 +- swad_parameter.h | 1 + swad_test.c | 78 ++++++++-------- 10 files changed, 221 insertions(+), 157 deletions(-) diff --git a/sql/cambios.sql b/sql/cambios.sql index e5f1fb4a..1ca83a61 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -12878,4 +12878,19 @@ REPLACE gam_time (MchCod,QstInd,ElapsedTime) VALUES (61,1,ADDTIME(ElapsedTime,SE INSERT INTO gam_time (MchCod,QstInd) VALUES (61,1,SEC_TO_TIME(1)) ON DUPLICATE KEY UPDATE ElapsedTime=ADDTIME(ElapsedTime,SEC_TO_TIME(1)); - + + +---------------- + +SELECT gam_questions.QstCod, + gam_questions.QstInd, + mch_indexes.Indexes + FROM mch_matches,gam_questions,mch_indexes + WHERE mch_matches.MchCod=69 + AND mch_matches.GamCod=gam_questions.GamCod + AND mch_matches.MchCod=mch_indexes.MchCod + AND gam_questions.QstInd=mch_indexes.QstInd + ORDER BY gam_questions.QstInd; + + + SELECT Correct FROM tst_answers WHERE QstCod=1787 ORDER BY AnsInd; diff --git a/sql/swad.sql b/sql/swad.sql index 32b65e08..0828ef14 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -613,11 +613,12 @@ CREATE TABLE IF NOT EXISTS gam_games ( -- -- Table mch_answers: stores the users' answers to the matches -- -CREATE TABLE IF NOT EXISTS mch_answers (" - MchCod INT NOT NULL," - UsrCod INT NOT NULL," - QstInd INT NOT NULL," - AnsInd TINYINT NOT NULL," +CREATE TABLE IF NOT EXISTS mch_answers ( + MchCod INT NOT NULL, + UsrCod INT NOT NULL, + QstInd INT NOT NULL, + NumOpt TINYINT NOT NULL, + AnsInd TINYINT NOT NULL, UNIQUE INDEX(MchCod,UsrCod,QstInd)); -- -- Table mch_groups: stores the groups associated to each match in a game diff --git a/swad_changelog.h b/swad_changelog.h index 8ce2bec0..73e9fd35 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -470,10 +470,15 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.11 (2019-09-23)" +#define Log_PLATFORM_VERSION "SWAD 19.12 (2019-09-24)" #define CSS_FILE "swad19.3.css" #define JS_FILE "swad18.130.2.js" /* + * + Version 19.12: Sep 24, 2019 View matches results. Not finished. (245973 lines) + 1 change necessary in database: +ALTER TABLE mch_answers ADD COLUMN NumOpt TINYINT NOT NULL AFTER QstInd; + Version 19.11: Sep 23, 2019 Create indexes when a match is created. (245933 lines) Version 19.10.3: Sep 23, 2019 View matches results. Not finished. (245815 lines) Version 19.10.2: Sep 23, 2019 View matches results. Not finished. (245812 lines) diff --git a/swad_database.c b/swad_database.c index 392d3160..9135efd2 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1339,15 +1339,17 @@ mysql> DESCRIBE mch_answers; | MchCod | int(11) | NO | PRI | NULL | | | UsrCod | int(11) | NO | PRI | NULL | | | QstInd | int(11) | NO | PRI | NULL | | -| AnsInd | tinyint(4) | NO | PRI | NULL | | +| NumOpt | tinyint(4) | NO | | NULL | | +| AnsInd | tinyint(4) | NO | | NULL | | +--------+------------+------+-----+---------+-------+ -4 rows in set (0.00 sec) +5 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_answers (" "MchCod INT NOT NULL," "UsrCod INT NOT NULL," "QstInd INT NOT NULL," - "AnsInd TINYINT NOT NULL," + "NumOpt TINYINT NOT NULL," // Number of button on screen (Always ordered: 0,1,2,3) + "AnsInd TINYINT NOT NULL," // Answer index (Can be shuffled: 0,3,1,2) "UNIQUE INDEX(MchCod,UsrCod,QstInd))"); /***** Table mch_groups *****/ diff --git a/swad_game.c b/swad_game.c index 5aeefd9a..b5169c41 100644 --- a/swad_game.c +++ b/swad_game.c @@ -1382,13 +1382,13 @@ void Gam_PutParamQstInd (unsigned QstInd) unsigned Gam_GetParamQstInd (void) { - long LongNum; + long QstInd; - LongNum = Par_GetParToLong ("QstInd"); - if (LongNum < 0) + QstInd = Par_GetParToLong ("QstInd"); + if (QstInd < 0) Lay_ShowErrorAndExit ("Wrong question index."); - return (unsigned) LongNum; + return (unsigned) QstInd; } /*****************************************************************************/ @@ -1397,11 +1397,11 @@ unsigned Gam_GetParamQstInd (void) unsigned Gam_GetQstIndFromStr (const char *UnsignedStr) { - long LongNum; + long QstInd; - LongNum = Str_ConvertStrCodToLongCod (UnsignedStr); - return (LongNum > 0) ? (unsigned) LongNum : - 0; + QstInd = Str_ConvertStrCodToLongCod (UnsignedStr); + return (QstInd > 0) ? (unsigned) QstInd : + 0; } /*****************************************************************************/ diff --git a/swad_match.c b/swad_match.c index c8ff76ab..2952ebd2 100644 --- a/swad_match.c +++ b/swad_match.c @@ -99,6 +99,12 @@ struct Match } Status; }; +struct Mch_UsrAnswer + { + int NumOpt; // < 0 ==> no answer selected + int AnsInd; // < 0 ==> no answer selected + }; + /*****************************************************************************/ /***************************** Private constants *****************************/ /*****************************************************************************/ @@ -177,8 +183,8 @@ static void Mch_ShowMatchTitle (struct Match *Match); static void Mch_ShowQuestionAndAnswersTch (struct Match *Match); static void Mch_ShowQuestionAndAnswersStd (struct Match *Match); -static void Mch_PutParamAnswer (unsigned AnsInd); -static unsigned Mch_GetParamAnswer (void); +static void Mch_PutParamNumOpt (unsigned NumOpt); +static unsigned Mch_GetParamNumOpt (void); static void Mch_PutBigButton (Act_Action_t NextAction,long MchCod, const char *Icon,const char *Txt); @@ -194,7 +200,8 @@ static bool Mch_GetIfMatchIsBeingPlayed (long MchCod); static void Mch_RegisterMeAsPlayerInMatch (long MchCod); static void Mch_GetNumPlayers (struct Match *Match); -static int Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd); +static void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd, + struct Mch_UsrAnswer *UsrAnswer); static void Mch_ComputeScore (struct Match *Match,unsigned NumQsts,long UsrCod, unsigned *NumQstsNotBlank,double *TotalScore); @@ -1088,7 +1095,7 @@ static void Mch_CreateIndexes (long GamCod,long MchCod) DB_QuerySELECT (&mysql_res,"can not get questions of a game", "SELECT gam_questions.QstCod," // row[0] "gam_questions.QstInd," // row[1] - "tst_questions.AnsType" // row[2] + "tst_questions.AnsType," // row[2] "tst_questions.Shuffle" // row[3] " FROM gam_questions,tst_questions" " WHERE gam_questions.GamCod=%ld" @@ -1153,10 +1160,10 @@ static void Mch_ReorderAnswer (long MchCod,unsigned QstInd, DB_QuerySELECT (&mysql_res,"can not get questions of a game", "SELECT AnsInd" // row[0] " FROM tst_answers" - " WHERE GamCod=%ld" + " WHERE QstCod=%ld" " ORDER BY %s", QstCod, - Shuffle ? "RAND(NOW())" : + Shuffle ? "RAND()" : // Use RAND() because is really random; RAND(NOW()) repeats order "AnsInd"); /***** For each answer in question... *****/ @@ -1170,10 +1177,10 @@ static void Mch_ReorderAnswer (long MchCod,unsigned QstInd, if ((LongNum = Str_ConvertStrCodToLongCod (row[0])) < 0) Lay_ShowErrorAndExit ("Wrong answer index."); AnsInd = (unsigned) LongNum; + snprintf (StrOneAnswer,sizeof (StrOneAnswer), + "%u",AnsInd); /* Concatenate answer index to list of answers */ - snprintf (StrOneAnswer,10 + 1, - "%u",AnsInd); if (NumAns) Str_Concat (StrAnswersOneQst,",", Tst_MAX_BYTES_ANSWERS_ONE_QST); @@ -1193,6 +1200,38 @@ static void Mch_ReorderAnswer (long MchCod,unsigned QstInd, MchCod,QstInd,StrAnswersOneQst); } +/*****************************************************************************/ +/***************** Get indexes for a question from database ******************/ +/*****************************************************************************/ + +void Mch_GetIndexes (long MchCod,unsigned QstInd, + unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + char StrIndexesOneQst[Tst_MAX_BYTES_INDEXES_ONE_QST + 1]; + + /***** Get indexes for a question from database *****/ + if (!DB_QuerySELECT (&mysql_res,"can not get data of a question", + "SELECT Indexes" // row[0] + " FROM mch_indexes" + " WHERE MchCod=%ld AND QstInd=%u", + MchCod,QstInd)) + Lay_ShowErrorAndExit ("No indexes found for a question."); + row = mysql_fetch_row (mysql_res); + + /* Get indexes (row[0]) */ + Str_Copy (StrIndexesOneQst,row[0], + Tst_MAX_BYTES_INDEXES_ONE_QST); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + /***** Get indexes from string *****/ + Par_ReplaceCommaBySeparatorMultiple (StrIndexesOneQst); + Tst_GetIndexesFromStr (StrIndexesOneQst,Indexes); + } + /*****************************************************************************/ /******************* Create groups associated to a match *********************/ /*****************************************************************************/ @@ -1976,7 +2015,10 @@ static void Mch_ShowQuestionAndAnswersTch (struct Match *Match) "TEST_MED_EDIT_LIST_STEM_CONTAINER", "TEST_MED_EDIT_LIST_STEM"); - /* Write answers? */ + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + /***** Write answers? *****/ switch (Match->Status.Showing) { case Mch_NOTHING: @@ -2013,14 +2055,9 @@ static void Mch_ShowQuestionAndAnswersTch (struct Match *Match) static void Mch_ShowQuestionAndAnswersStd (struct Match *Match) { - bool Shuffle = false; // TODO: Read shuffle from question - MYSQL_RES *mysql_res; - MYSQL_ROW row; - int StdAnsInd; + struct Mch_UsrAnswer UsrAnswer; unsigned NumOptions; unsigned NumOpt; - unsigned Index; - bool ErrorInIndex = false; /***** Show question *****/ /* Write buttons for answers? */ @@ -2030,24 +2067,14 @@ static void Mch_ShowQuestionAndAnswersStd (struct Match *Match) { /***** Get student's answer to this question (<0 ==> no answer) *****/ - StdAnsInd = Mch_GetQstAnsFromDB (Match->MchCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - Match->Status.QstInd); + Mch_GetQstAnsFromDB (Match->MchCod, + Gbl.Usrs.Me.UsrDat.UsrCod, + Match->Status.QstInd, + &UsrAnswer); /***** Get number of options in this question *****/ NumOptions = Tst_GetNumAnswersQst (Match->Status.QstCod); - /***** Get answers of question from database *****/ - Shuffle = false; - NumOptions = Tst_GetAnswersQst (Match->Status.QstCod,&mysql_res,Shuffle); - /* - row[0] AnsInd - row[1] Answer - row[2] Feedback - row[3] MedCod - row[4] Correct - */ - /***** Start table *****/ Tbl_StartTableWide (8); @@ -2055,24 +2082,7 @@ static void Mch_ShowQuestionAndAnswersStd (struct Match *Match) NumOpt < NumOptions; NumOpt++) { - /***** Get next answer *****/ - row = mysql_fetch_row (mysql_res); - - /***** Assign index (row[0]). - Index is 0,1,2,3... if no shuffle - or 1,3,0,2... (example) if shuffle *****/ - if (sscanf (row[0],"%u",&Index) == 1) - { - if (Index >= Tst_MAX_OPTIONS_PER_QUESTION) - ErrorInIndex = true; - } - else - ErrorInIndex = true; - if (ErrorInIndex) - Lay_ShowErrorAndExit ("Wrong index of answer when showing a test."); - /***** Start row *****/ - // if (NumOpt % 2 == 0) fprintf (Gbl.F.Out,""); /***** Write letter for this option *****/ @@ -2086,12 +2096,12 @@ static void Mch_ShowQuestionAndAnswersStd (struct Match *Match) Frm_StartForm (ActAnsMchQstStd); Mch_PutParamMchCod (Match->MchCod); // Current match being played Gam_PutParamQstInd (Match->Status.QstInd); // Current question index shown - Mch_PutParamAnswer (Index); // Index for this option + Mch_PutParamNumOpt (NumOpt); // Number of button fprintf (Gbl.F.Out,"