mirror of https://github.com/acanas/swad-core.git
Version 21.24.1: Oct 05, 2021 Queries moved to module swad_photo_database.
This commit is contained in:
parent
fd5f6f97a8
commit
c281e847aa
|
@ -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.
|
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 21.24 (2021-10-05)"
|
#define Log_PLATFORM_VERSION "SWAD 21.24.1 (2021-10-05)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.69.1.js"
|
#define JS_FILE "swad20.69.1.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
|
Version 21.24.1: Oct 05, 2021 Queries moved to module swad_photo_database. (318406 lines)
|
||||||
Version 21.24: Oct 05, 2021 New module swad_photo_database for database queries related to users' photos. (318352 lines)
|
Version 21.24: Oct 05, 2021 New module swad_photo_database for database queries related to users' photos. (318352 lines)
|
||||||
Version 21.23: Oct 04, 2021 New module swad_password_database for database queries related to passwords. (318197 lines)
|
Version 21.23: Oct 04, 2021 New module swad_password_database for database queries related to passwords. (318197 lines)
|
||||||
Version 21.22: Oct 04, 2021 Queries related to notifications moved to other modules. (318066 lines)
|
Version 21.22: Oct 04, 2021 Queries related to notifications moved to other modules. (318066 lines)
|
||||||
|
|
82
swad_photo.c
82
swad_photo.c
|
@ -129,7 +129,8 @@ static void Pho_PutLinkToCalculateDegreeStats (const struct Pho_DegPhotos *DegPh
|
||||||
static void Pho_GetMaxStdsPerDegree (struct Pho_DegPhotos *DegPhotos);
|
static void Pho_GetMaxStdsPerDegree (struct Pho_DegPhotos *DegPhotos);
|
||||||
static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
|
static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
|
||||||
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
|
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
|
||||||
static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *NumStdsWithPhoto);
|
static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,
|
||||||
|
int *NumStds,int *NumStdsWithPhoto);
|
||||||
static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
|
static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
|
||||||
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
|
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
|
||||||
|
|
||||||
|
@ -1387,38 +1388,12 @@ static long Pho_GetDegWithAvgPhotoLeastRecentlyUpdated (void)
|
||||||
|
|
||||||
/***** 1. If a degree is not in table of computed degrees,
|
/***** 1. If a degree is not in table of computed degrees,
|
||||||
choose it as least recently updated *****/
|
choose it as least recently updated *****/
|
||||||
DegCod = DB_QuerySELECTCode ("can not get degrees",
|
if ((DegCod = Pho_DB_GetADegWithStdsNotInTableOfComputedDegs ()) > 0)
|
||||||
"SELECT DISTINCT deg_degrees.DegCod"
|
return DegCod;
|
||||||
" FROM deg_degrees,"
|
|
||||||
"crs_courses,"
|
|
||||||
"crs_users"
|
|
||||||
" WHERE deg_degrees.DegCod=crs_courses.DegCod"
|
|
||||||
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
||||||
" AND crs_users.Role=%u"
|
|
||||||
" AND deg_degrees.DegCod NOT IN"
|
|
||||||
" (SELECT DISTINCT DegCod"
|
|
||||||
" FROM sta_degrees)"
|
|
||||||
" LIMIT 1",
|
|
||||||
(unsigned) Rol_STD);
|
|
||||||
|
|
||||||
if (DegCod <= 0)
|
/***** 2. If all the degrees are in table,
|
||||||
/***** 2. If all the degrees are in table,
|
choose the least recently updated that has students *****/
|
||||||
choose the least recently updated that has students *****/
|
return Pho_DB_GetDegWithAvgPhotoLeastRecentlyUpdated ();
|
||||||
DegCod = DB_QuerySELECTCode ("can not get degrees",
|
|
||||||
"SELECT sta_degrees.DegCod"
|
|
||||||
" FROM sta_degrees,"
|
|
||||||
"crs_courses,"
|
|
||||||
"crs_users"
|
|
||||||
" WHERE sta_degrees.TimeAvgPhoto<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
|
|
||||||
" AND sta_degrees.DegCod=crs_courses.DegCod"
|
|
||||||
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
||||||
" AND crs_users.Role=%u"
|
|
||||||
" ORDER BY sta_degrees.TimeAvgPhoto"
|
|
||||||
" LIMIT 1",
|
|
||||||
Cfg_MIN_TIME_TO_RECOMPUTE_AVG_PHOTO,
|
|
||||||
(unsigned) Rol_STD);
|
|
||||||
|
|
||||||
return DegCod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1432,12 +1407,7 @@ static long Pho_GetTimeAvgPhotoWasComputed (long DegCod)
|
||||||
long TimeAvgPhotoWasComputed = 0L;
|
long TimeAvgPhotoWasComputed = 0L;
|
||||||
|
|
||||||
/***** Get last time an average photo was computed from database *****/
|
/***** Get last time an average photo was computed from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get last time"
|
if (Pho_DB_GetTimeAvgPhotoWasComputed (&mysql_res,DegCod) == 1)
|
||||||
" an average photo was computed",
|
|
||||||
"SELECT COALESCE(MIN(UNIX_TIMESTAMP(TimeAvgPhoto)),0)" // row[0]
|
|
||||||
" FROM sta_degrees"
|
|
||||||
" WHERE DegCod=%ld",
|
|
||||||
DegCod) == 1)
|
|
||||||
{
|
{
|
||||||
/***** Get row *****/
|
/***** Get row *****/
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
@ -1466,11 +1436,7 @@ static long Pho_GetTimeToComputeAvgPhoto (long DegCod)
|
||||||
long TotalTimeToComputeAvgPhoto = -1L;
|
long TotalTimeToComputeAvgPhoto = -1L;
|
||||||
|
|
||||||
/***** Get time to compute average photo from database *****/
|
/***** Get time to compute average photo from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get time to compute average photo",
|
if (Pho_DB_GetTimeToComputeAvgPhoto (&mysql_res,DegCod) == Usr_NUM_SEXS)
|
||||||
"SELECT TimeToComputeAvgPhoto" // row[0]
|
|
||||||
" FROM sta_degrees"
|
|
||||||
" WHERE DegCod=%ld",
|
|
||||||
DegCod) == Usr_NUM_SEXS)
|
|
||||||
{
|
{
|
||||||
TotalTimeToComputeAvgPhoto = 0;
|
TotalTimeToComputeAvgPhoto = 0;
|
||||||
for (Sex = (Usr_Sex_t) 0;
|
for (Sex = (Usr_Sex_t) 0;
|
||||||
|
@ -2009,14 +1975,7 @@ static void Pho_GetMaxStdsPerDegree (struct Pho_DegPhotos *DegPhotos)
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
|
|
||||||
/***** Get maximum number of students in a degree from database *****/
|
/***** Get maximum number of students in a degree from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get maximum"
|
if (Pho_DB_GetMaxStdsPerDegree (&mysql_res) == 1)
|
||||||
" number of students in a degree",
|
|
||||||
"SELECT MAX(NumStds)," // row[0]
|
|
||||||
"MAX(NumStdsWithPhoto)," // row[1]
|
|
||||||
"MAX(NumStdsWithPhoto/NumStds)" // row[2]
|
|
||||||
" FROM sta_degrees"
|
|
||||||
" WHERE Sex='all'"
|
|
||||||
" AND NumStds>0") == 1)
|
|
||||||
{
|
{
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
|
||||||
|
@ -2230,26 +2189,19 @@ static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
|
||||||
/*** Get number of students and number of students with photo in a degree ****/
|
/*** Get number of students and number of students with photo in a degree ****/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *NumStdsWithPhoto)
|
static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,
|
||||||
|
int *NumStds,int *NumStdsWithPhoto)
|
||||||
{
|
{
|
||||||
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
|
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
|
|
||||||
/***** Get the number of students in a degree from database *****/
|
/***** Get the number of students in a degree from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get the number of students"
|
if (Pho_DB_GetNumStdsInDegree (&mysql_res,DegCod,Sex))
|
||||||
" in a degree",
|
|
||||||
"SELECT NumStds," // row[0]
|
|
||||||
"NumStdsWithPhoto" // row[1]
|
|
||||||
" FROM sta_degrees"
|
|
||||||
" WHERE DegCod=%ld"
|
|
||||||
" AND Sex='%s'",
|
|
||||||
DegCod,
|
|
||||||
Usr_StringsSexDB[Sex]) == 0)
|
|
||||||
*NumStds = *NumStdsWithPhoto = -1;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
|
||||||
|
/* Get number of students (row[0])
|
||||||
|
and number of students with photo (row[1]) */
|
||||||
if (sscanf (row[0],"%d",NumStds) != 1)
|
if (sscanf (row[0],"%d",NumStds) != 1)
|
||||||
*NumStds = -1;
|
*NumStds = -1;
|
||||||
if (sscanf (row[1],"%d",NumStdsWithPhoto) != 1)
|
if (sscanf (row[1],"%d",NumStdsWithPhoto) != 1)
|
||||||
|
@ -2258,6 +2210,8 @@ static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *
|
||||||
/***** Free structure that stores the query result *****/
|
/***** Free structure that stores the query result *****/
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
DB_FreeMySQLResult (&mysql_res);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
*NumStds = *NumStdsWithPhoto = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -249,6 +249,111 @@ unsigned Pho_DB_QueryDegrees (MYSQL_RES **mysql_res,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******** Get degree with students not in table of computed degrees **********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
long Pho_DB_GetADegWithStdsNotInTableOfComputedDegs (void)
|
||||||
|
{
|
||||||
|
return DB_QuerySELECTCode ("can not get degree",
|
||||||
|
"SELECT DISTINCT deg_degrees.DegCod"
|
||||||
|
" FROM deg_degrees,"
|
||||||
|
"crs_courses,"
|
||||||
|
"crs_users"
|
||||||
|
" WHERE deg_degrees.DegCod=crs_courses.DegCod"
|
||||||
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
||||||
|
" AND crs_users.Role=%u"
|
||||||
|
" AND deg_degrees.DegCod NOT IN"
|
||||||
|
" (SELECT DISTINCT DegCod"
|
||||||
|
" FROM sta_degrees)"
|
||||||
|
" LIMIT 1",
|
||||||
|
(unsigned) Rol_STD);
|
||||||
|
}
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********* Get the least recently updated degree that has students ***********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
long Pho_DB_GetDegWithAvgPhotoLeastRecentlyUpdated (void)
|
||||||
|
{
|
||||||
|
return DB_QuerySELECTCode ("can not get degree",
|
||||||
|
"SELECT sta_degrees.DegCod"
|
||||||
|
" FROM sta_degrees,"
|
||||||
|
"crs_courses,"
|
||||||
|
"crs_users"
|
||||||
|
" WHERE sta_degrees.TimeAvgPhoto<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
|
||||||
|
" AND sta_degrees.DegCod=crs_courses.DegCod"
|
||||||
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
||||||
|
" AND crs_users.Role=%u"
|
||||||
|
" ORDER BY sta_degrees.TimeAvgPhoto"
|
||||||
|
" LIMIT 1",
|
||||||
|
Cfg_MIN_TIME_TO_RECOMPUTE_AVG_PHOTO,
|
||||||
|
(unsigned) Rol_STD);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********* Get maximum number of students in a degree from database **********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Pho_DB_GetMaxStdsPerDegree (MYSQL_RES **mysql_res)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get maximum number of students in a degree",
|
||||||
|
"SELECT MAX(NumStds)," // row[0]
|
||||||
|
"MAX(NumStdsWithPhoto)," // row[1]
|
||||||
|
"MAX(NumStdsWithPhoto/NumStds)" // row[2]
|
||||||
|
" FROM sta_degrees"
|
||||||
|
" WHERE Sex='all'"
|
||||||
|
" AND NumStds>0");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*** Get number of students and number of students with photo in a degree ****/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Pho_DB_GetNumStdsInDegree (MYSQL_RES **mysql_res,long DegCod,Usr_Sex_t Sex)
|
||||||
|
{
|
||||||
|
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
|
||||||
|
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get the number of students in a degree",
|
||||||
|
"SELECT NumStds," // row[0]
|
||||||
|
"NumStdsWithPhoto" // row[1]
|
||||||
|
" FROM sta_degrees"
|
||||||
|
" WHERE DegCod=%ld"
|
||||||
|
" AND Sex='%s'",
|
||||||
|
DegCod,
|
||||||
|
Usr_StringsSexDB[Sex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********* Get last time an average photo was computed from database *********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Pho_DB_GetTimeAvgPhotoWasComputed (MYSQL_RES **mysql_res,long DegCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get last time"
|
||||||
|
" an average photo was computed",
|
||||||
|
"SELECT COALESCE(MIN(UNIX_TIMESTAMP(TimeAvgPhoto)),0)" // row[0]
|
||||||
|
" FROM sta_degrees"
|
||||||
|
" WHERE DegCod=%ld",
|
||||||
|
DegCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********************* Get time to compute average photo *********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Pho_DB_GetTimeToComputeAvgPhoto (MYSQL_RES **mysql_res,long DegCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get time to compute average photo",
|
||||||
|
"SELECT TimeToComputeAvgPhoto" // row[0]
|
||||||
|
" FROM sta_degrees"
|
||||||
|
" WHERE DegCod=%ld",
|
||||||
|
DegCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Delete all the degrees in sta_degrees table not present in degrees table **/
|
/* Delete all the degrees in sta_degrees table not present in degrees table **/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -57,8 +57,16 @@ void Pho_DB_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod);
|
||||||
void Pho_DB_UpdateDegStats (long DegCod,Usr_Sex_t Sex,
|
void Pho_DB_UpdateDegStats (long DegCod,Usr_Sex_t Sex,
|
||||||
unsigned NumStds,unsigned NumStdsWithPhoto,
|
unsigned NumStds,unsigned NumStdsWithPhoto,
|
||||||
long TimeToComputeAvgPhotoInMicroseconds);
|
long TimeToComputeAvgPhotoInMicroseconds);
|
||||||
|
|
||||||
unsigned Pho_DB_QueryDegrees (MYSQL_RES **mysql_res,
|
unsigned Pho_DB_QueryDegrees (MYSQL_RES **mysql_res,
|
||||||
Pho_HowOrderDegrees_t HowOrderDegrees);
|
Pho_HowOrderDegrees_t HowOrderDegrees);
|
||||||
|
long Pho_DB_GetADegWithStdsNotInTableOfComputedDegs (void);
|
||||||
|
long Pho_DB_GetDegWithAvgPhotoLeastRecentlyUpdated (void);
|
||||||
|
unsigned Pho_DB_GetMaxStdsPerDegree (MYSQL_RES **mysql_res);
|
||||||
|
unsigned Pho_DB_GetNumStdsInDegree (MYSQL_RES **mysql_res,long DegCod,Usr_Sex_t Sex);
|
||||||
|
unsigned Pho_DB_GetTimeAvgPhotoWasComputed (MYSQL_RES **mysql_res,long DegCod);
|
||||||
|
unsigned Pho_DB_GetTimeToComputeAvgPhoto (MYSQL_RES **mysql_res,long DegCod);
|
||||||
|
|
||||||
void Pho_DB_RemoveObsoleteStatDegrees (void);
|
void Pho_DB_RemoveObsoleteStatDegrees (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue