From 130d4971e95ceb7942ef45d2f9b2e8692167bfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sat, 8 Oct 2016 21:19:47 +0200 Subject: [PATCH] Version 16.17.4 --- swad_changelog.h | 3 +- swad_report.c | 74 +++++++++++++++++++++++++++++++++++++----------- swad_statistic.c | 2 ++ 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 446109ff9..a9ea5b05e 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -148,13 +148,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.17.3 (2016-10-08)" +#define Log_PLATFORM_VERSION "SWAD 16.17.4 (2016-10-08)" #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 16.17.4: Oct 08, 2016 Code refactoring in user's usage report. (206292 lines) Version 16.17.3: Oct 08, 2016 Message translated in user's usage report. (206255 lines) Version 16.17.2: Oct 08, 2016 Message translated in user's usage report. (206233 lines) Version 16.17.1: Oct 08, 2016 Message translated in user's usage report. (206211 lines) diff --git a/swad_report.c b/swad_report.c index e08601867..ba14b235d 100644 --- a/swad_report.c +++ b/swad_report.c @@ -70,6 +70,12 @@ struct CurrentTimeUTC unsigned Time; // Example: 190349 }; +struct Rep_Hits + { + unsigned long Num; + unsigned long Max; + }; + /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ @@ -140,7 +146,10 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, time_t FirstClickTimeUTC, const struct tm *tm_FirstClickTime, unsigned long MaxHitsPerYear); -static void Rep_DrawBarNumHits (float HitsNum,float HitsMax, +static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits, + unsigned long NumRows, + MYSQL_RES *mysql_res,unsigned Field); +static void Rep_DrawBarNumHits (unsigned long HitsNum,unsigned long HitsMax, unsigned MaxBarWidth); static void Rep_RemoveUsrReportsFiles (long UsrCod); @@ -789,10 +798,10 @@ static void Rep_WriteSectionHitsPerAction (const struct UsrFigures *UsrFigures) MYSQL_ROW row; unsigned long NumRows; unsigned long NumRow; - struct Sta_Hits Hits; + struct Rep_Hits Hits; long ActCod; char ActTxt[Act_MAX_LENGTH_ACTION_TXT+1]; - long NumClicks; + unsigned long NumClicks; /***** Start of section *****/ fprintf (Gbl.F.Rep,"
" @@ -808,7 +817,7 @@ static void Rep_WriteSectionHitsPerAction (const struct UsrFigures *UsrFigures) NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get clicks"); /***** Compute maximum number of hits per action *****/ - Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); + Rep_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1); mysql_data_seek (mysql_res,0); /***** Write rows *****/ @@ -821,9 +830,10 @@ static void Rep_WriteSectionHitsPerAction (const struct UsrFigures *UsrFigures) /* Get the action (row[0]) */ ActCod = Str_ConvertStrCodToLongCod (row[0]); - /* Get number hits (in row[1]) */ - Hits.Num = Str_GetFloatNumFromStr (row[1]); - NumClicks += (long) Hits.Num; + /* Get number of hits (row[1]) */ + if (sscanf (row[1],"%lu",&Hits.Num) != 1) + Hits.Num = 0; + NumClicks += Hits.Num; /* Draw bar proportional to number of hits */ Rep_DrawBarNumHits (Hits.Num,Hits.Max,Rep_MAX_BAR_WIDTH); @@ -843,7 +853,7 @@ static void Rep_WriteSectionHitsPerAction (const struct UsrFigures *UsrFigures) } /***** Draw bar for the rest of the clicks *****/ - if (UsrFigures->NumClicks > NumClicks) + if ((unsigned long) UsrFigures->NumClicks > NumClicks) fprintf (Gbl.F.Rep,"%ld %s
", UsrFigures->NumClicks - NumClicks, Txt_Other_actions); @@ -1250,7 +1260,7 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, unsigned ReadYear; unsigned LastYear; unsigned Year; - struct Sta_Hits Hits; + struct Rep_Hits Hits; /***** Make the query *****/ if (AnyCourse) @@ -1284,11 +1294,11 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, /***** Set maximum number of hits per year *****/ if (MaxHitsPerYear) /* Set maximum number of hits per year from parameter */ - Hits.Max = (float) MaxHitsPerYear; + Hits.Max = MaxHitsPerYear; else { /* Compute maximum number of hits per year */ - Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); + Rep_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1); mysql_data_seek (mysql_res,0); } @@ -1304,7 +1314,8 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, Lay_ShowErrorAndExit ("Wrong date."); /* Get number hits (in row[1]) */ - Hits.Num = Str_GetFloatNumFromStr (row[1]); + if (sscanf (row[1],"%lu",&Hits.Num) != 1) + Hits.Num = 0; for (Year = LastYear; Year >= ReadYear; @@ -1315,7 +1326,7 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, /* Draw bar proportional to number of hits */ Rep_DrawBarNumHits (Year == LastYear ? Hits.Num : - 0.0, + 0, Hits.Max,Rep_MAX_BAR_WIDTH); fprintf (Gbl.F.Rep,"
"); } @@ -1334,25 +1345,54 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, fprintf (Gbl.F.Rep,"%04u ",Year); /* Draw bar proportional to number of hits */ - Rep_DrawBarNumHits (0.0,Hits.Max,Rep_MAX_BAR_WIDTH); + Rep_DrawBarNumHits (0,Hits.Max,Rep_MAX_BAR_WIDTH); fprintf (Gbl.F.Rep,"
"); } } +/*****************************************************************************/ +/*************** Compute maximum and total number of hits ********************/ +/*****************************************************************************/ + +static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits, + unsigned long NumRows, + MYSQL_RES *mysql_res,unsigned Field) + { + unsigned long NumRow; + MYSQL_ROW row; + + /***** For each row... *****/ + for (NumRow = 1, Hits->Max = 0; + NumRow <= NumRows; + NumRow++) + { + /* Get row */ + row = mysql_fetch_row (mysql_res); + + /* Get number of hits */ + if (sscanf (row[Field],"%lu",&Hits->Num) != 1) + Hits->Num = 0; + + /* Update maximum hits */ + if (Hits->Num > Hits->Max) + Hits->Max = Hits->Num; + } + } + /*****************************************************************************/ /********************* Draw a bar with the number of hits ********************/ /*****************************************************************************/ -static void Rep_DrawBarNumHits (float HitsNum,float HitsMax, +static void Rep_DrawBarNumHits (unsigned long HitsNum,unsigned long HitsMax, unsigned MaxBarWidth) { unsigned BarWidth; unsigned i; - if (HitsNum != 0.0) + if (HitsNum) { /***** Draw bar with a with proportional to the number of hits *****/ - BarWidth = (unsigned) (((HitsNum * (float) MaxBarWidth) / HitsMax) + 0.5); + BarWidth = (unsigned) ((((float) HitsNum * (float) MaxBarWidth) / (float) HitsMax) + 0.5); if (BarWidth) { fprintf (Gbl.F.Rep,""); diff --git a/swad_statistic.c b/swad_statistic.c index 7ec686dc9..8c0944435 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -3700,10 +3700,12 @@ void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, unsigned long NumRow; MYSQL_ROW row; + /***** For each row... *****/ for (NumRow = 1, Hits->Max = Hits->Total = 0.0; NumRow <= NumRows; NumRow++) { + /* Get row */ row = mysql_fetch_row (mysql_res); /* Get number of hits */