From 820dba7995933654b79a31306ca0be629d776fba Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 25 Sep 2023 21:14:05 +0200 Subject: [PATCH] Version 23.17.2: Sep 25, 2023 Fixed bug in hierarchy. --- swad_changelog.h | 3 ++- swad_country_database.c | 50 ++++++++++++++++++++++++++++------------- swad_country_database.h | 12 ++++------ swad_hierarchy.c | 47 ++++++++++++++++++++++++-------------- swad_hierarchy.h | 2 +- 5 files changed, 72 insertions(+), 42 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 394308cc9..9cc717e32 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -632,10 +632,11 @@ TODO: Francisco Javier Fern Me sale este error, no sé si por no recordar yo la sintaxis apropiada para mandar a varios destinatarios. ¿No era así? "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.17.1 (2023-09-25)" +#define Log_PLATFORM_VERSION "SWAD 23.17.2 (2023-09-25)" #define CSS_FILE "swad23.16.1.css" #define JS_FILE "swad22.49.js" /* + Version 23.17.2: Sep 25, 2023 Fixed bug in hierarchy. (336673 lines) Version 23.17.1: Sep 25, 2023 Fixed bug in hierarchy. (336654 lines) Version 23.17: Sep 25, 2023 Code refactoring in hierarchy. (336655 lines) Version 23.16.1: Sep 25, 2023 Fixed CSS issues. (336778 lines) diff --git a/swad_country_database.c b/swad_country_database.c index ddba8fb0c..a8173835a 100644 --- a/swad_country_database.c +++ b/swad_country_database.c @@ -295,41 +295,54 @@ unsigned Cty_DB_GetNumCtysInSys (__attribute__((unused)) long SysCod) /***************** Get number of countries with institutions *****************/ /*****************************************************************************/ -unsigned Cty_DB_GetNumCtysWithInss (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod) +unsigned Cty_DB_GetNumCtysWithInss (Hie_Level_t Level,long HieCod) { + char SubQuery[128]; + + Hie_DB_BuildSubquery (SubQuery,Level,HieCod); + return (unsigned) DB_QueryCOUNT ("can not get number of countries with institutions", "SELECT COUNT(DISTINCT cty_countrs.CtyCod)" " FROM cty_countrs," "ins_instits" - " WHERE cty_countrs.CtyCod=ins_instits.CtyCod"); + " WHERE %s" + "cty_countrs.CtyCod=ins_instits.CtyCod", + SubQuery); } /*****************************************************************************/ /******************* Get number of countries with centers ********************/ /*****************************************************************************/ -unsigned Cty_DB_GetNumCtysWithCtrs (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod) +unsigned Cty_DB_GetNumCtysWithCtrs (Hie_Level_t Level,long HieCod) { + char SubQuery[128]; + + Hie_DB_BuildSubquery (SubQuery,Level,HieCod); + return (unsigned) DB_QueryCOUNT ("can not get number of countries with centers", "SELECT COUNT(DISTINCT cty_countrs.CtyCod)" " FROM cty_countrs," "ins_instits," "ctr_centers" - " WHERE cty_countrs.CtyCod=ins_instits.CtyCod" - " AND ins_instits.InsCod=ctr_centers.InsCod"); + " WHERE %s" + "cty_countrs.CtyCod=ins_instits.CtyCod" + " AND ins_instits.InsCod=ctr_centers.InsCod", + SubQuery); } /*****************************************************************************/ /******************* Get number of countries with degrees ********************/ /*****************************************************************************/ -unsigned Cty_DB_GetNumCtysWithDegs (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod) +unsigned Cty_DB_GetNumCtysWithDegs (Hie_Level_t Level,long HieCod) { + char SubQuery[128]; + + Hie_DB_BuildSubquery (SubQuery,Level,HieCod); + return (unsigned) DB_QueryCOUNT ("can not get number of countries with degrees", "SELECT COUNT(DISTINCT cty_countrs.CtyCod)" @@ -337,18 +350,23 @@ unsigned Cty_DB_GetNumCtysWithDegs (__attribute__((unused)) Hie_Level_t Level, "ins_instits," "ctr_centers," "deg_degrees" - " WHERE cty_countrs.CtyCod=ins_instits.CtyCod" + " WHERE %s" + "cty_countrs.CtyCod=ins_instits.CtyCod" " AND ins_instits.InsCod=ctr_centers.InsCod" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod"); + " AND ctr_centers.CtrCod=deg_degrees.CtrCod", + SubQuery); } /*****************************************************************************/ /******************* Get number of countries with courses ********************/ /*****************************************************************************/ -unsigned Cty_DB_GetNumCtysWithCrss (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod) +unsigned Cty_DB_GetNumCtysWithCrss (Hie_Level_t Level,long HieCod) { + char SubQuery[128]; + + Hie_DB_BuildSubquery (SubQuery,Level,HieCod); + return (unsigned) DB_QueryCOUNT ("can not get number of countries with courses", "SELECT COUNT(DISTINCT cty_countrs.CtyCod)" @@ -357,10 +375,12 @@ unsigned Cty_DB_GetNumCtysWithCrss (__attribute__((unused)) Hie_Level_t Level, "ctr_centers," "deg_degrees," "crs_courses" - " WHERE cty_countrs.CtyCod=ins_instits.CtyCod" + " WHERE %s" + "cty_countrs.CtyCod=ins_instits.CtyCod" " AND ins_instits.InsCod=ctr_centers.InsCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod"); + " AND deg_degrees.DegCod=crs_courses.DegCod", + SubQuery); } /*****************************************************************************/ diff --git a/swad_country_database.h b/swad_country_database.h index 300afb062..e19cdd65a 100644 --- a/swad_country_database.h +++ b/swad_country_database.h @@ -52,14 +52,10 @@ void Cty_DB_GetCountryName (long CtyCod,Lan_Language_t Language, unsigned Cty_DB_GetNumCtysInSys (__attribute__((unused)) long SysCod); -unsigned Cty_DB_GetNumCtysWithInss (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod); -unsigned Cty_DB_GetNumCtysWithCtrs (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod); -unsigned Cty_DB_GetNumCtysWithDegs (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod); -unsigned Cty_DB_GetNumCtysWithCrss (__attribute__((unused)) Hie_Level_t Level, - __attribute__((unused)) long HieCod); +unsigned Cty_DB_GetNumCtysWithInss (Hie_Level_t Level,long HieCod); +unsigned Cty_DB_GetNumCtysWithCtrs (Hie_Level_t Level,long HieCod); +unsigned Cty_DB_GetNumCtysWithDegs (Hie_Level_t Level,long HieCod); +unsigned Cty_DB_GetNumCtysWithCrss (Hie_Level_t Level,long HieCod); unsigned Cty_DB_GetNumCtysWithUsrs (Rol_Role_t Role, Hie_Level_t Level,long Cod); diff --git a/swad_hierarchy.c b/swad_hierarchy.c index b40967553..c153d0bb2 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -80,7 +80,7 @@ static Hie_StatusTxt_t Hie_GetStatusTxtFromStatusBits (Hie_Status_t Status); static Hie_Status_t Hie_GetStatusBitsFromStatusTxt (Hie_StatusTxt_t StatusTxt); static void Hie_WriteHeadHierarchy (void); -static void Hie_GetAndShowHierarchyWith (Hie_Level_t LevelGrandChildren); +static void Hie_GetAndShowHierarchyWithNodes (Hie_Level_t HavingNodesOfLevel); static void Hie_GetAndShowHierarchyWithUsrs (Rol_Role_t Role); static void Hie_GetAndShowHierarchyTotal (void); static void Hie_ShowHierarchyRow (const char *Text1,const char *Text2, @@ -979,6 +979,7 @@ void Hie_GetAndShowHierarchyStats (void) { extern const char *Hlp_ANALYTICS_Figures_hierarchy; extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES]; + Hie_Level_t HavingNodesOfLevel; Rol_Role_t Role; /***** Begin box and table *****/ @@ -986,15 +987,22 @@ void Hie_GetAndShowHierarchyStats (void) NULL,NULL, Hlp_ANALYTICS_Figures_hierarchy,Box_NOT_CLOSABLE,2); + /* Head row */ Hie_WriteHeadHierarchy (); - Hie_GetAndShowHierarchyWith (Hie_INS); - Hie_GetAndShowHierarchyWith (Hie_CTR); - Hie_GetAndShowHierarchyWith (Hie_DEG); - Hie_GetAndShowHierarchyWith (Hie_CRS); + + /* Rows with number of nodes having nodes of each level */ + for (HavingNodesOfLevel = Hie_INS; + HavingNodesOfLevel <= Hie_CRS; + HavingNodesOfLevel++) + Hie_GetAndShowHierarchyWithNodes (HavingNodesOfLevel); + + /* Rows with number of nodes having users of each role */ for (Role = Rol_TCH; Role >= Rol_STD; Role--) Hie_GetAndShowHierarchyWithUsrs (Role); + + /* Row with total nodes */ Hie_GetAndShowHierarchyTotal (); /***** End table and box *****/ @@ -1059,7 +1067,7 @@ static void Hie_WriteHeadHierarchy (void) /********* Get and show number of elements in hierarchy with nodes ***********/ /*****************************************************************************/ -static void Hie_GetAndShowHierarchyWith (Hie_Level_t LevelGrandChildren) +static void Hie_GetAndShowHierarchyWithNodes (Hie_Level_t HavingNodesOfLevel) { extern const char *Txt_With_; extern const char *Txt_institutions; @@ -1081,17 +1089,18 @@ static void Hie_GetAndShowHierarchyWith (Hie_Level_t LevelGrandChildren) for (LevelChildren = Hie_CTY; LevelChildren <= Hie_CRS; LevelChildren++) - if (LevelChildren >= LevelGrandChildren) // Example: don't show number of centers with institutions + if (LevelChildren >= HavingNodesOfLevel) // Example: don't show number of centers with institutions NumNodes[LevelChildren] = -1; - else if (LevelChildren < Gbl.Scope.Current) // Example: if scope is center (4) => - NumNodes[LevelChildren] = 1; // number of countries/instit./centers in center is 1 + else if (LevelChildren < Gbl.Scope.Current && // Example: if scope is center (4) + HavingNodesOfLevel <= Gbl.Scope.Current) // number of nodes with instit./countries/centers + NumNodes[LevelChildren] = 1; // in current center is 1 else - NumNodes[LevelChildren] = (int) Hie_GetCachedNumNodesInHieLvlWith (LevelChildren, // Child + NumNodes[LevelChildren] = (int) Hie_GetCachedNumNodesInHieLvlWith (LevelChildren, // Child Gbl.Scope.Current, // Parent - LevelGrandChildren);// Grand child + HavingNodesOfLevel);// Grand child /***** Write number of elements with courses *****/ - Hie_ShowHierarchyRow (Txt_With_,*Txt[LevelGrandChildren],"DAT",NumNodes); + Hie_ShowHierarchyRow (Txt_With_,*Txt[HavingNodesOfLevel],"DAT",NumNodes); } /*****************************************************************************/ @@ -1207,13 +1216,17 @@ unsigned Hie_GetNumNodesInHieLvl (Hie_Level_t LevelChildren, } /*****************************************************************************/ -/***** Get number of children nodes in parent node with children nodes *********************/ +/**** Get number of children nodes in parent node having nodes of a level ****/ /*****************************************************************************/ unsigned Hie_GetCachedNumNodesInHieLvlWith (Hie_Level_t LevelChildren, Hie_Level_t LevelParent, - Hie_Level_t LevelGrandChildren) + Hie_Level_t HavingNodesOfLevel) { + // Example: number of centers with courses in current institution + // LevelChildren = center + // LevelParent = institution + // HavingNodesOfLevel = course static FigCch_FigureCached_t Figure[Hie_NUM_LEVELS][Hie_NUM_LEVELS] = { // Child / Grandchild @@ -1251,13 +1264,13 @@ unsigned Hie_GetCachedNumNodesInHieLvlWith (Hie_Level_t LevelChildren, unsigned NumNodes; /***** Get number of centers with degrees from cache *****/ - if (!FigCch_GetFigureFromCache (Figure[LevelChildren][LevelGrandChildren], + if (!FigCch_GetFigureFromCache (Figure[LevelChildren][HavingNodesOfLevel], LevelParent,Gbl.Hierarchy.Node[LevelParent].HieCod, FigCch_UNSIGNED,&NumNodes)) { /***** Get current number of nodes with degrees from database and update cache *****/ - NumNodes = FunctionGetFigure[LevelChildren][LevelGrandChildren] (LevelParent,Gbl.Hierarchy.Node[LevelParent].HieCod); - FigCch_UpdateFigureIntoCache (Figure[LevelChildren][LevelGrandChildren], + NumNodes = FunctionGetFigure[LevelChildren][HavingNodesOfLevel] (LevelParent,Gbl.Hierarchy.Node[LevelParent].HieCod); + FigCch_UpdateFigureIntoCache (Figure[LevelChildren][HavingNodesOfLevel], LevelParent,Gbl.Hierarchy.Node[LevelParent].HieCod, FigCch_UNSIGNED,&NumNodes); } diff --git a/swad_hierarchy.h b/swad_hierarchy.h index e88af4688..1bd656d96 100644 --- a/swad_hierarchy.h +++ b/swad_hierarchy.h @@ -80,7 +80,7 @@ unsigned Hie_GetNumNodesInHieLvl (Hie_Level_t LevelChildren, unsigned Hie_GetCachedNumNodesInHieLvlWith (Hie_Level_t LevelChildren, Hie_Level_t LevelParent, - Hie_Level_t LevelGrandChildren); + Hie_Level_t HavingNodesOfLevel); void Hie_FlushCacheNumUsrsWhoClaimToBelongTo (Hie_Level_t Level); unsigned Hie_GetCachedNumUsrsWhoClaimToBelongTo (Hie_Level_t Level,