diff --git a/swad_changelog.h b/swad_changelog.h index 8fb6541c4..611885d0a 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -135,13 +135,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.251.2 (2016-09-11)" +#define Log_PLATFORM_VERSION "SWAD 15.252 (2016-09-12)" #define CSS_FILE "swad15.229.css" #define JS_FILE "swad15.238.1.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 /* + Version 15.252: Sep 12, 2016 Hits in user's usage report. Not finished. (204589 lines) Version 15.251.2: Sep 11, 2016 Changes in layout of user's usage report. (204465 lines) Version 15.251.1: Sep 11, 2016 Changes in user's usage report. (204406 lines) Version 15.251: Sep 11, 2016 List of courses in user's usage report. (204416 lines) diff --git a/swad_report.c b/swad_report.c index 378c62502..a27cd871e 100644 --- a/swad_report.c +++ b/swad_report.c @@ -72,6 +72,8 @@ static void Rep_PutIconToPrintMyUsageReport (void); static void Rep_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role); static void Rep_WriteRowCrsData (MYSQL_ROW row); +static void Rep_ShowMyHits (time_t FirstClickTimeUTC,struct tm *tm_FirstClickTime); + /*****************************************************************************/ /********* Show my usage report (report on my use of the platform) ***********/ /*****************************************************************************/ @@ -120,11 +122,12 @@ static void Rep_ShowOrPrintMyUsageReport (Rep_SeeOrPrint_t SeeOrPrint) extern const char *Txt_courses; extern const char *Txt_teachers_ABBREVIATION; extern const char *Txt_students_ABBREVIATION; + extern const char *Txt_Hits; unsigned NumID; char CtyName[Cty_MAX_BYTES_COUNTRY_NAME+1]; struct Institution Ins; struct UsrFigures UsrFigures; - struct tm FirstClickTime; + struct tm tm_FirstClickTime; unsigned NumFiles; unsigned NumPublicFiles; Rol_Role_t Role; @@ -194,15 +197,15 @@ static void Rep_ShowOrPrintMyUsageReport (Rep_SeeOrPrint_t SeeOrPrint) fprintf (Gbl.F.Out,"
  • %s: ",Txt_From_TIME); if (UsrFigures.FirstClickTimeUTC) { - if ((gmtime_r (&UsrFigures.FirstClickTimeUTC,&FirstClickTime)) != NULL) + if ((gmtime_r (&UsrFigures.FirstClickTimeUTC,&tm_FirstClickTime)) != NULL) { fprintf (Gbl.F.Out,"%04d-%02d-%02d %02d:%02d:%02d UTC", - 1900 + FirstClickTime.tm_year, // year - 1 + FirstClickTime.tm_mon, // month - FirstClickTime.tm_mday, // day of the month - FirstClickTime.tm_hour, // hours - FirstClickTime.tm_min, // minutes - FirstClickTime.tm_sec); // seconds + 1900 + tm_FirstClickTime.tm_year, // year + 1 + tm_FirstClickTime.tm_mon, // month + tm_FirstClickTime.tm_mday, // day of the month + tm_FirstClickTime.tm_hour, // hours + tm_FirstClickTime.tm_min, // minutes + tm_FirstClickTime.tm_sec); // seconds if (UsrFigures.NumDays > 0) fprintf (Gbl.F.Out," (%d %s)", UsrFigures.NumDays, @@ -340,6 +343,17 @@ static void Rep_ShowOrPrintMyUsageReport (Rep_SeeOrPrint_t SeeOrPrint) fprintf (Gbl.F.Out,""); + /***** Hits *****/ + fprintf (Gbl.F.Out,"

    %s

    ",Txt_Hits); + fprintf (Gbl.F.Out,"2016-04: ███ 300
    "); + fprintf (Gbl.F.Out,"2016-05: █ 100
    "); + fprintf (Gbl.F.Out,"2016-06: 0
    "); + fprintf (Gbl.F.Out,"2016-07: █████ 500
    "); + fprintf (Gbl.F.Out,"2016-08: █████████ 900
    "); + fprintf (Gbl.F.Out,"2016-09: ██████ 600
    "); + + Rep_ShowMyHits (UsrFigures.FirstClickTimeUTC,&tm_FirstClickTime); + /***** End frame *****/ fprintf (Gbl.F.Out,""); if (SeeOrPrint == Rep_SEE) @@ -456,7 +470,7 @@ static void Rep_WriteRowCrsData (MYSQL_ROW row) fprintf (Gbl.F.Out,"
  • "); /***** Write course full name (row[2]) *****/ - fprintf (Gbl.F.Out,"%s -",row[2]); + fprintf (Gbl.F.Out,"%s -",row[2]); /***** Write year (row[3]) *****/ if ((Year = Deg_ConvStrToYear (row[3]))) @@ -471,3 +485,113 @@ static void Rep_WriteRowCrsData (MYSQL_ROW row) NumTchs,Txt_teachers_ABBREVIATION, NumStds,Txt_students_ABBREVIATION); } + +/*****************************************************************************/ +/********************* Write my hits grouped by months ***********************/ +/*****************************************************************************/ + +static void Rep_ShowMyHits (time_t FirstClickTimeUTC,struct tm *tm_FirstClickTime) + { + char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE+1]; + char Query[1024]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned long NumRows; + unsigned long NumRow; + struct Date ReadDate; + struct Date LastDate; + struct Date Date; + unsigned M; + unsigned NumMonthsBetweenLastDateAndCurrentDate; + struct Sta_Hits Hits; + + /***** Get client time zone *****/ + Dat_GetBrowserTimeZone (BrowserTimeZone); + + /***** Make the query *****/ + sprintf (Query,"SELECT SQL_NO_CACHE " + "DATE_FORMAT(CONVERT_TZ(ClickTime,@@session.time_zone,'%s'),'%%Y%%m') AS Month," + "COUNT(*) FROM log_full" + " WHERE ClickTime>=FROM_UNIXTIME('%ld')" + " AND UsrCod='%ld'" + " GROUP BY Month DESC", + BrowserTimeZone, + (long) FirstClickTimeUTC, + Gbl.Usrs.Me.UsrDat.UsrCod); + NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get clicks"); + + /***** Initialize first date *****/ + Gbl.DateRange.DateIni.Date.Year = 1900 + tm_FirstClickTime->tm_year; + Gbl.DateRange.DateIni.Date.Month = 1 + tm_FirstClickTime->tm_mon; + Gbl.DateRange.DateIni.Date.Day = tm_FirstClickTime->tm_mday; + + /***** Initialize LastDate *****/ + Dat_AssignDate (&LastDate,&Gbl.Now.Date); + + /***** Compute maximum number of pages generated per month *****/ + Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); + + fprintf (Gbl.F.Out,""); + + /***** Write rows *****/ + mysql_data_seek (mysql_res,0); + for (NumRow = 1; + NumRow <= NumRows; + NumRow++) + { + row = mysql_fetch_row (mysql_res); + + /* Get the year and the month (in row[0] is the date in YYYYMM format) */ + if (sscanf (row[0],"%04u%02u",&ReadDate.Year,&ReadDate.Month) != 2) + Lay_ShowErrorAndExit ("Wrong date."); + + /* Get number of pages generated (in row[1]) */ + Hits.Num = Str_GetFloatNumFromStr (row[1]); + + Dat_AssignDate (&Date,&LastDate); + NumMonthsBetweenLastDateAndCurrentDate = Dat_GetNumMonthsBetweenDates (&ReadDate,&LastDate); + for (M = 1; + M <= NumMonthsBetweenLastDateAndCurrentDate; + M++) + { + /* Write the month */ + fprintf (Gbl.F.Out,"" + "", + Date.Year,Date.Month); + + /* Draw bar proportional to number of pages generated */ + Sta_DrawBarNumHits ('c', + M == NumMonthsBetweenLastDateAndCurrentDate ? Hits.Num : + 0.0, + Hits.Max,Hits.Total,500); + + /* Decrease month */ + Dat_GetMonthBefore (&Date,&Date); + } + Dat_AssignDate (&LastDate,&Date); + } + + /***** Finally, show the oldest months without clicks *****/ + NumMonthsBetweenLastDateAndCurrentDate = Dat_GetNumMonthsBetweenDates (&Gbl.DateRange.DateIni.Date,&LastDate); + for (M = 1; + M <= NumMonthsBetweenLastDateAndCurrentDate; + M++) + { + /* Write the month */ + fprintf (Gbl.F.Out,"" + "", + Date.Year,Date.Month); + + /* Draw bar proportional to number of pages generated */ + Sta_DrawBarNumHits ('c',0.0,Hits.Max,Hits.Total,500); + + /* Decrease month */ + Dat_GetMonthBefore (&Date,&Date); + } + + fprintf (Gbl.F.Out,"
    " + "%04u-%02u " + "
    " + "%04u-%02u " + "
    "); + } diff --git a/swad_statistic.c b/swad_statistic.c index 4bce9e358..511994d2e 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -124,13 +124,6 @@ typedef enum Sta_SHOW_COURSE_ACCESSES, } Sta_GlobalOrCourseAccesses_t; -struct Sta_Hits - { - float Num; - float Max; - float Total; - }; - /*****************************************************************************/ /***************************** Internal prototypes ***************************/ /*****************************************************************************/ @@ -182,11 +175,6 @@ static void Sta_ShowNumHitsPerDegree (unsigned long NumRows, static void Sta_WriteDegree (long DegCod); static void Sta_ShowNumHitsPerCourse (unsigned long NumRows, MYSQL_RES *mysql_res); -static void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, - unsigned long NumRows, - MYSQL_RES *mysql_res,unsigned Field, - unsigned Divisor); -static void Sta_DrawBarNumHits (char Color,float HitsNum,float HitsMax,float HitsTotal,unsigned MaxBarWidth); static void Sta_GetAndShowHierarchyStats (void); static void Sta_WriteHeadDegsCrssInSWAD (void); @@ -1897,7 +1885,7 @@ static void Sta_ShowNumHitsPerDays (unsigned long NumRows, MYSQL_ROW row; /***** Initialize LastDate *****/ - Dat_AssignDate (&LastDate,&(Gbl.DateRange.DateEnd.Date)); + Dat_AssignDate (&LastDate,&Gbl.DateRange.DateEnd.Date); /***** Write heading *****/ fprintf (Gbl.F.Out,"" @@ -2084,7 +2072,7 @@ static void Sta_ShowDistrAccessesPerDaysAndHour (unsigned long NumRows,MYSQL_RES Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,2,1); /***** Initialize LastDate *****/ - Dat_AssignDate (&LastDate,&(Gbl.DateRange.DateEnd.Date)); + Dat_AssignDate (&LastDate,&Gbl.DateRange.DateEnd.Date); /***** Reset number of pages generated per hour *****/ for (Hour = 0; @@ -2479,7 +2467,7 @@ static void Sta_ShowNumHitsPerWeeks (unsigned long NumRows, /***** Initialize LastDate to avoid warning *****/ Dat_CalculateWeekOfYear (&Gbl.DateRange.DateEnd.Date); // Changes Week and Year - Dat_AssignDate (&LastDate,&(Gbl.DateRange.DateEnd.Date)); + Dat_AssignDate (&LastDate,&Gbl.DateRange.DateEnd.Date); /***** Write heading *****/ fprintf (Gbl.F.Out,"" @@ -2577,7 +2565,7 @@ static void Sta_ShowNumHitsPerMonths (unsigned long NumRows, MYSQL_ROW row; /***** Initialize LastDate *****/ - Dat_AssignDate (&LastDate,&(Gbl.DateRange.DateEnd.Date)); + Dat_AssignDate (&LastDate,&Gbl.DateRange.DateEnd.Date); /***** Write heading *****/ fprintf (Gbl.F.Out,"" @@ -2625,7 +2613,7 @@ static void Sta_ShowNumHitsPerMonths (unsigned long NumRows, /* Draw bar proportional to number of pages generated */ Sta_DrawBarNumHits ('c', M == NumMonthsBetweenLastDateAndCurrentDate ? Hits.Num : - 0.0, + 0.0, Hits.Max,Hits.Total,500); /* Decrease month */ @@ -3698,10 +3686,10 @@ static void Sta_ShowNumHitsPerCourse (unsigned long NumRows, /*************** Compute maximum and total number of hits ********************/ /*****************************************************************************/ -static void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, - unsigned long NumRows, - MYSQL_RES *mysql_res,unsigned Field, - unsigned Divisor) +void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, + unsigned long NumRows, + MYSQL_RES *mysql_res,unsigned Field, + unsigned Divisor) { unsigned long NumRow; MYSQL_ROW row; @@ -3730,7 +3718,7 @@ static void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, /********************* Draw a bar with the number of hits ********************/ /*****************************************************************************/ -static void Sta_DrawBarNumHits (char Color,float HitsNum,float HitsMax,float HitsTotal,unsigned MaxBarWidth) +void Sta_DrawBarNumHits (char Color,float HitsNum,float HitsMax,float HitsTotal,unsigned MaxBarWidth) { unsigned BarWidth; diff --git a/swad_statistic.h b/swad_statistic.h index 2f689139c..e297ceed9 100644 --- a/swad_statistic.h +++ b/swad_statistic.h @@ -135,6 +135,13 @@ typedef enum #define Sta_NUM_STAT_CRS_FILE_ZONES 11 +struct Sta_Hits + { + float Num; + float Max; + float Total; + }; + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ @@ -147,10 +154,19 @@ void Sta_AskShowGblHits (void); void Sta_SetIniEndDates (void); void Sta_SeeGblAccesses (void); void Sta_SeeCrsAccesses (void); + +void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, + unsigned long NumRows, + MYSQL_RES *mysql_res,unsigned Field, + unsigned Divisor); + void Sta_ReqUseOfPlatform (void); void Pho_PutHiddenParamFigureType (void); void Sta_ShowUseOfPlatform (void); unsigned Sta_GetTotalNumberOfUsersInCourses (Sco_Scope_t Scope,Rol_Role_t Role); + +void Sta_DrawBarNumHits (char Color,float HitsNum,float HitsMax,float HitsTotal,unsigned MaxBarWidth); + void Sta_WriteParamsDatesSeeAccesses (void); void Sta_ComputeTimeToGeneratePage (void); diff --git a/swad_text.c b/swad_text.c index a2d5495c8..8ac6cc819 100644 --- a/swad_text.c +++ b/swad_text.c @@ -13858,6 +13858,27 @@ const char *Txt_Hide_right_column = "Ocultar coluna da direita"; #endif +const char *Txt_Hits = // hits = visits, clicks, page views... +#if L==1 + "Accessos"; +#elif L==2 + "Anmeldungen"; +#elif L==3 + "Hits"; +#elif L==4 + "Accesos"; +#elif L==5 + "Visites"; +#elif L==6 + "Accesos"; // Okoteve traducción +#elif L==7 + "Visite"; +#elif L==8 + "Odsłon"; +#elif L==9 + "Visitas"; +#endif + const char *Txt_Holiday = #if L==1 "Festivitat";