From c64d7c4e120ea72315a1c49a6162f15eef7961c0 Mon Sep 17 00:00:00 2001 From: acanas Date: Wed, 13 Oct 2021 14:38:51 +0200 Subject: [PATCH] Version 21.31.1: Oct 13, 2021 Queries moved to module swad_log_database. --- swad_changelog.h | 3 +- swad_log_database.c | 117 ++++++++++++++++++++++++++++++++++++++++++ swad_log_database.h | 8 +++ swad_report.c | 122 +++++++++----------------------------------- 4 files changed, 150 insertions(+), 100 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 6b754124..00d72900 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 21.31 (2021-10-13)" +#define Log_PLATFORM_VERSION "SWAD 21.31.1 (2021-10-13)" #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 21.31.1: Oct 13, 2021 Queries moved to module swad_log_database. (319520 lines) Version 21.31: Oct 13, 2021 New module swad_report_database for database queries related to user reports. (319475 lines) Version 21.30.1: Oct 13, 2021 Queries moved to module swad_record_database. (319411 lines) Version 21.30: Oct 12, 2021 New module swad_record_database for database queries related to records. (319400 lines) diff --git a/swad_log_database.c b/swad_log_database.c index a2fc2d1b..a4328552 100644 --- a/swad_log_database.c +++ b/swad_log_database.c @@ -225,6 +225,123 @@ unsigned Log_DB_GetUsrNumClicks (long UsrCod) UsrCod); } +/*****************************************************************************/ +/********************** Get my clicks grouped by action **********************/ +/*****************************************************************************/ + +unsigned Log_DB_GetMyClicksGroupedByAction (MYSQL_RES **mysql_res, + time_t FirstClickTimeUTC, + unsigned MaxActions) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get clicks", + "SELECT SQL_NO_CACHE ActCod," // row[0] + "COUNT(*) AS N" // row[1] + " FROM log" + " WHERE ClickTime>=FROM_UNIXTIME(%ld)" + " AND UsrCod=%ld" + " GROUP BY ActCod" + " ORDER BY N DESC" + " LIMIT %u", + (long) FirstClickTimeUTC, + Gbl.Usrs.Me.UsrDat.UsrCod, + MaxActions); + } + +/*****************************************************************************/ +/************ Get my maximum number of hits per course-year-role ************/ +/*****************************************************************************/ + +unsigned Log_DB_GetMyMaxHitsPerYear (MYSQL_RES **mysql_res, + time_t FirstClickTimeUTC) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get last question index", + "SELECT MAX(N) FROM (" + // Clicks without course selected -------------------------- + "SELECT -1 AS CrsCod," + "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," + "%u AS Role," + "COUNT(*) AS N" + " FROM log" + " WHERE ClickTime>=FROM_UNIXTIME(%ld)" + " AND UsrCod=%ld" + " AND CrsCod<=0" + " GROUP BY Year" + // --------------------------------------------------------- + " UNION " + // Clicks as student, non-editing teacher or teacher in courses + "SELECT CrsCod," + "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," + "Role," + "COUNT(*) AS N" + " FROM log" + " WHERE ClickTime>=FROM_UNIXTIME(%ld)" + " AND UsrCod=%ld" + " AND Role>=%u" // Student + " AND Role<=%u" // Teacher + " AND CrsCod>0" + " GROUP BY CrsCod," + "Year," + "Role" + // --------------------------------------------------------- + ") AS hits_per_crs_year", + (unsigned) Rol_UNK, + (long) FirstClickTimeUTC, + Gbl.Usrs.Me.UsrDat.UsrCod, + (long) FirstClickTimeUTC, + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Rol_STD, + (unsigned) Rol_TCH); + } + +/*****************************************************************************/ +/************ Get my courses with number of hits per course-role ************/ +/*****************************************************************************/ + +unsigned Log_DB_GetMyCrssAndHitsPerCrs (MYSQL_RES **mysql_res,Rol_Role_t Role) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get courses of a user", + "SELECT my_courses.CrsCod," // row[0] + "COUNT(*) AS N" // row[1] + " FROM (SELECT CrsCod" + " FROM crs_users" + " WHERE UsrCod=%ld" + " AND Role=%u) AS my_courses" // It's imperative to use a derived table to not block crs_usr! + " LEFT JOIN log" + " ON (my_courses.CrsCod=log.CrsCod)" + " WHERE log.UsrCod=%ld" + " AND log.Role=%u" + " GROUP BY my_courses.CrsCod" + " ORDER BY N DESC," + "my_courses.CrsCod DESC", + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role, + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role); + } +/*****************************************************************************/ +/************************** Get my historic courses **************************/ +/*****************************************************************************/ + +unsigned Log_DB_GetMyHistoricCrss (MYSQL_RES **mysql_res,Rol_Role_t Role, + unsigned MinClicksCrs) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get courses of a user", + "SELECT CrsCod," // row[0] + "COUNT(*) AS N" // row[1] + " FROM log" + " WHERE UsrCod=%ld" + " AND Role=%u" + " AND CrsCod>0" + " GROUP BY CrsCod" + " HAVING N>%u" + " ORDER BY N DESC", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Role, + MinClicksCrs); + } + /*****************************************************************************/ /************ Sometimes, we delete old entries in recent log table ***********/ /*****************************************************************************/ diff --git a/swad_log_database.h b/swad_log_database.h index 473730b6..219500ea 100644 --- a/swad_log_database.h +++ b/swad_log_database.h @@ -49,6 +49,14 @@ void Log_DB_LogBanner (long LogCod,long BanCodClicked); unsigned Log_DB_GetLastClicks (MYSQL_RES **mysql_res); unsigned Log_DB_GetUsrFirstClick (MYSQL_RES **mysql_res,long UsrCod); unsigned Log_DB_GetUsrNumClicks (long UsrCod); +unsigned Log_DB_GetMyClicksGroupedByAction (MYSQL_RES **mysql_res, + time_t FirstClickTimeUTC, + unsigned MaxActions); +unsigned Log_DB_GetMyMaxHitsPerYear (MYSQL_RES **mysql_res, + time_t FirstClickTimeUTC); +unsigned Log_DB_GetMyCrssAndHitsPerCrs (MYSQL_RES **mysql_res,Rol_Role_t Role); +unsigned Log_DB_GetMyHistoricCrss (MYSQL_RES **mysql_res,Rol_Role_t Role, + unsigned MinClicksCrs); void Log_DB_RemoveOldEntriesRecentLog (void); diff --git a/swad_report.c b/swad_report.c index fdfd717a..51a54bb3 100644 --- a/swad_report.c +++ b/swad_report.c @@ -38,6 +38,7 @@ #include "swad_hierarchy_level.h" #include "swad_HTML.h" #include "swad_ID.h" +#include "swad_log_database.h" #include "swad_profile.h" #include "swad_report_database.h" #include "swad_tab.h" @@ -402,11 +403,11 @@ static void Rep_WriteHeader (const struct Rep_Report *Report) extern const char *Txt_Permalink; /***** Begin header *****/ - fprintf (Gbl.F.Rep,"
"); - fprintf (Gbl.F.Rep,"

"); + fprintf (Gbl.F.Rep,"
" + "

"); fprintf (Gbl.F.Rep,Txt_Report_of_use_of_PLATFORM,Cfg_PLATFORM_SHORT_NAME); - fprintf (Gbl.F.Rep,"

"); - fprintf (Gbl.F.Rep,"
    "); + fprintf (Gbl.F.Rep,"

" + "