From 8e3a5e671b7dee0069ad0338dc4fbaf5215f2258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 23 Sep 2019 09:03:55 +0200 Subject: [PATCH] Version19.9.2 --- sql/swad.sql | 2 ++ swad_changelog.h | 7 +++++- swad_database.c | 24 +++++++++++--------- swad_match.c | 58 +++++++++++++++++++++++++++++++++++------------- 4 files changed, 64 insertions(+), 27 deletions(-) diff --git a/sql/swad.sql b/sql/swad.sql index 48c027120..f92eaaa05 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -663,6 +663,8 @@ CREATE TABLE IF NOT EXISTS mch_players ( CREATE TABLE IF NOT EXISTS mch_results ( MchCod INT NOT NULL, UsrCod INT NOT NULL, + StartTime DATETIME NOT NULL, + EndTime DATETIME NOT NULL, NumQsts INT NOT NULL DEFAULT 0, NumQstsNotBlank INT NOT NULL DEFAULT 0, Score DOUBLE PRECISION NOT NULL DEFAULT 0, diff --git a/swad_changelog.h b/swad_changelog.h index 50257ffc8..a8b8ef5d1 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -468,10 +468,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.9.1 (2019-09-23)" +#define Log_PLATFORM_VERSION "SWAD 19.9.2 (2019-09-23)" #define CSS_FILE "swad19.3.css" #define JS_FILE "swad18.130.2.js" /* + Version 19.9.2: Sep 23, 2019 View matches results. Not finished. (245598 lines) + 2 changes necessary in database: +DROP TABLE IF EXISTS mch_results; +CREATE TABLE IF NOT EXISTS mch_results (MchCod INT NOT NULL,UsrCod INT NOT NULL,StartTime DATETIME NOT NULL,EndTime DATETIME NOT NULL,NumQsts INT NOT NULL DEFAULT 0,NumQstsNotBlank INT NOT NULL DEFAULT 0,Score DOUBLE PRECISION NOT NULL DEFAULT 0,UNIQUE INDEX(MchCod,UsrCod)); + Version 19.9.1: Sep 23, 2019 View matches results. Not finished. (245562 lines) Version 19.9: Sep 23, 2019 View matches results. Not finished. (245579 lines) 2 changes necessary in database: diff --git a/swad_database.c b/swad_database.c index b8c0f53bc..7c265664e 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1436,20 +1436,24 @@ mysql> DESCRIBE mch_players; /***** Table mch_results *****/ /* mysql> DESCRIBE mch_results; -+-----------------+---------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+-----------------+---------+------+-----+---------+-------+ -| MchCod | int(11) | NO | PRI | NULL | | -| UsrCod | int(11) | NO | PRI | NULL | | -| NumQsts | int(11) | NO | | 0 | | -| NumQstsNotBlank | int(11) | NO | | 0 | | -| Score | double | NO | | 0 | | -+-----------------+---------+------+-----+---------+-------+ -5 rows in set (0.00 sec) ++-----------------+----------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-----------------+----------+------+-----+---------+-------+ +| MchCod | int(11) | NO | PRI | NULL | | +| UsrCod | int(11) | NO | PRI | NULL | | +| StartTime | datetime | NO | | NULL | | +| EndTime | datetime | NO | | NULL | | +| NumQsts | int(11) | NO | | 0 | | +| NumQstsNotBlank | int(11) | NO | | 0 | | +| Score | double | NO | | 0 | | ++-----------------+----------+------+-----+---------+-------+ +7 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_results (" "MchCod INT NOT NULL," "UsrCod INT NOT NULL," + "StartTime DATETIME NOT NULL," // Time this user started to answer + "EndTime DATETIME NOT NULL," // Time this user finished to answer "NumQsts INT NOT NULL DEFAULT 0," "NumQstsNotBlank INT NOT NULL DEFAULT 0," "Score DOUBLE PRECISION NOT NULL DEFAULT 0," diff --git a/swad_match.c b/swad_match.c index c41679a74..20661f6c0 100644 --- a/swad_match.c +++ b/swad_match.c @@ -2331,13 +2331,35 @@ void Mch_ReceiveQstAnsFromStd (void) Mch_ComputeScore (&Match,NumQsts,&NumQstsNotBlank,&TotalScore); Str_SetDecimalPointToUS (); // To print the floating point as a dot - DB_QueryREPLACE ("can not update match result", - "REPLACE mch_results" - " (MchCod,UsrCod,NumQsts,NumQstsNotBlank,Score)" - " VALUES" - " (%ld,%ld,%u,%u,'%lf')", - Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod, - NumQsts,NumQstsNotBlank,TotalScore); + if (DB_QueryCOUNT ("can not get if match result exists", + "SELECT COUNT(*) FROM mch_results" + " WHERE MchCod=%ld AND UsrCod=%ld", + Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod)) // Result exists + /* Update result */ + DB_QueryUPDATE ("can not update match result", + "UPDATE mch_results" + " SET EndTime=NOW()," + "NumQsts=%u," + "NumQstsNotBlank=%u," + "Score='%lf'" + " WHERE MchCod=%ld AND UsrCod=%ld", + NumQsts,NumQstsNotBlank,TotalScore, + Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod); + else // Result doesn't exist + /* Create result */ + DB_QueryINSERT ("can not create match result", + "INSERT mch_results " + "(MchCod,UsrCod,StartTime,EndTime,NumQsts,NumQstsNotBlank,Score)" + " VALUES " + "(%ld," // MchCod + "%ld," // UsrCod + "NOW()," // StartTime + "NOW()," // EndTime + "%u," // NumQsts + "%u," // NumQstsNotBlank + "'%lf')", // Score + Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod, + NumQsts,NumQstsNotBlank,TotalScore); Str_SetDecimalPointToLocal (); // Return to local system } @@ -2492,7 +2514,7 @@ unsigned Mch_GetNumUsrsWhoHaveAnswerQst (long MchCod,unsigned QstInd) /***** Get number of users who have answered a question in match from database *****/ return - (unsigned) DB_QueryCOUNT ("can not get number of users who hasve answered a question", + (unsigned) DB_QueryCOUNT ("can not get number of users who have answered a question", "SELECT COUNT(*) FROM mch_answers" " WHERE MchCod=%ld AND QstInd=%u", MchCod,QstInd); @@ -2522,7 +2544,7 @@ static unsigned Mch_GetNumUsrsWhoHaveAnswerMch (long MchCod) /***** Get number of users who have answered any question in match from database *****/ return - (unsigned) DB_QueryCOUNT ("can not get number of users who hasve answered a match", + (unsigned) DB_QueryCOUNT ("can not get number of users who have answered a match", "SELECT COUNT(DISTINCT UsrCod) FROM mch_answers" " WHERE MchCod=%ld", MchCod); @@ -2812,7 +2834,7 @@ void Mch_ShowUsrsMchResults (void) static void Mch_ShowHeaderMchResults (void) { extern const char *Txt_User[Usr_NUM_SEXS]; - extern const char *Txt_Date; + extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME]; extern const char *Txt_Questions; extern const char *Txt_Non_blank_BR_questions; extern const char *Txt_Total_BR_score; @@ -2824,7 +2846,10 @@ static void Mch_ShowHeaderMchResults (void) "" "%s" "" - "" + "" + "%s" + "" + "" "%s" "" "" @@ -2845,7 +2870,8 @@ static void Mch_ShowHeaderMchResults (void) "" "", Txt_User[Usr_SEX_UNKNOWN], - Txt_Date, + Txt_START_END_TIME[Dat_START_TIME], + Txt_START_END_TIME[Dat_END_TIME], Txt_Questions, Txt_Non_blank_BR_questions, Txt_Total_BR_score, @@ -2881,8 +2907,8 @@ static void Mch_ShowMchResults (struct UsrData *UsrDat) NumResults = (unsigned) DB_QuerySELECT (&mysql_res,"can not get matches results of a user", "SELECT mch_results.MchCod," // row[0] - "UNIX_TIMESTAMP(mch_matches.StartTime)," // row[1] - "UNIX_TIMESTAMP(mch_matches.EndTime)," // row[2] + "UNIX_TIMESTAMP(mch_results.StartTime)," // row[1] + "UNIX_TIMESTAMP(mch_results.EndTime)," // row[2] "mch_results.NumQsts," // row[3] "mch_results.NumQstsNotBlank," // row[4] "mch_results.Score" // row[5] @@ -2924,10 +2950,10 @@ static void Mch_ShowMchResults (struct UsrData *UsrDat) StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1); StartEndTime++) { - TimeUTC[0] = Dat_GetUNIXTimeFromStr (row[1 + StartEndTime]); + TimeUTC[StartEndTime] = Dat_GetUNIXTimeFromStr (row[1 + StartEndTime]); UniqueId++; fprintf (Gbl.F.Out,"" + " class=\"%s LEFT_TOP COLOR%u\">" "