mirror of https://github.com/acanas/swad-core.git
Version 21.18: Sep 29, 2021 New module swad_MFU_database for database queries related to most frequently used actions.
This commit is contained in:
parent
0ea1d5774d
commit
94948db72f
2
Makefile
2
Makefile
|
@ -65,7 +65,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
|
|||
swad_maintenance.o swad_map.o swad_mark.o swad_mark_database.o \
|
||||
swad_match.o swad_match_database.o swad_match_print.o \
|
||||
swad_match_result.o swad_media.o swad_media_database.o swad_menu.o \
|
||||
swad_message.o swad_message_database.o swad_MFU.o \
|
||||
swad_message.o swad_message_database.o swad_MFU.o swad_MFU_database.o \
|
||||
swad_network.o swad_nickname.o swad_notice.o swad_notification.o \
|
||||
swad_notification_database.o swad_pagination.o swad_parameter.o \
|
||||
swad_password.o swad_photo.o swad_place.o swad_plugin.o swad_privacy.o \
|
||||
|
|
53
swad_MFU.c
53
swad_MFU.c
|
@ -1,4 +1,4 @@
|
|||
// swad_role.c: user's roles
|
||||
// swad_MFU.c: Most Frequently Used actions
|
||||
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance),
|
||||
|
@ -38,6 +38,7 @@
|
|||
#include "swad_global.h"
|
||||
#include "swad_HTML.h"
|
||||
#include "swad_MFU.h"
|
||||
#include "swad_MFU_database.h"
|
||||
#include "swad_tab.h"
|
||||
#include "swad_theme.h"
|
||||
|
||||
|
@ -109,14 +110,7 @@ void MFU_GetMFUActions (struct MFU_ListMFUActions *ListMFUActions,unsigned MaxAc
|
|||
Act_Action_t Action;
|
||||
|
||||
/***** Get most frequently used actions *****/
|
||||
NumActions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get most frequently used actions",
|
||||
"SELECT ActCod"
|
||||
" FROM act_frequent"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Score DESC,"
|
||||
"LastClick DESC",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
NumActions = MFU_DB_GetMFUActionsOrderByScore (&mysql_res);
|
||||
|
||||
/***** Write list of frequently used actions *****/
|
||||
for (NumAction = 0, ListMFUActions->NumActions = 0;
|
||||
|
@ -153,14 +147,7 @@ Act_Action_t MFU_GetMyLastActionInCurrentTab (void)
|
|||
if (Gbl.Usrs.Me.UsrDat.UsrCod > 0)
|
||||
{
|
||||
/***** Get my most frequently used actions *****/
|
||||
NumActions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get the most frequently used actions",
|
||||
"SELECT ActCod"
|
||||
" FROM act_frequent"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY LastClick DESC,"
|
||||
"Score DESC",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
NumActions = MFU_DB_GetMFUActionsOrderByLastClick (&mysql_res);
|
||||
|
||||
/***** Loop over list of frequently used actions *****/
|
||||
for (NumAct = 0;
|
||||
|
@ -333,11 +320,6 @@ void MFU_WriteSmallMFUActions (struct MFU_ListMFUActions *ListMFUActions)
|
|||
/******************** Update most frequently used actions ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define MFU_MIN_SCORE 0.5
|
||||
#define MFU_MAX_SCORE 100.0
|
||||
#define MFU_INCREASE_FACTOR 1.2
|
||||
#define MFU_DECREASE_FACTOR 0.99
|
||||
|
||||
void MFU_UpdateMFUActions (void)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
|
@ -360,13 +342,7 @@ void MFU_UpdateMFUActions (void)
|
|||
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
|
||||
|
||||
/***** Get current score *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get score for current action",
|
||||
"SELECT Score" // row[0]
|
||||
" FROM act_frequent"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND ActCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ActCod))
|
||||
if (MFU_DB_GetScoreForCurrentAction (&mysql_res,ActCod))
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if (sscanf (row[0],"%lf",&Score) != 1)
|
||||
|
@ -382,25 +358,10 @@ void MFU_UpdateMFUActions (void)
|
|||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
/***** Update score for the current action *****/
|
||||
DB_QueryREPLACE ("can not update most frequently used actions",
|
||||
"REPLACE INTO act_frequent"
|
||||
" (UsrCod,ActCod,Score,LastClick)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,'%15lg',NOW())",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ActCod,
|
||||
Score);
|
||||
MFU_DB_UpdateScoreForCurrentAction (ActCod,Score);
|
||||
|
||||
/***** Update score for other actions *****/
|
||||
DB_QueryUPDATE ("can not update most frequently used actions",
|
||||
"UPDATE act_frequent"
|
||||
" SET Score=GREATEST(Score*'%.15lg','%.15lg')"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND ActCod<>%ld",
|
||||
MFU_DECREASE_FACTOR,
|
||||
MFU_MIN_SCORE,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ActCod);
|
||||
MFU_DB_UpdateScoreForOtherActions (ActCod);
|
||||
|
||||
Str_SetDecimalPointToLocal (); // Return to local system
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@
|
|||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define MFU_MIN_SCORE 0.5
|
||||
#define MFU_MAX_SCORE 100.0
|
||||
#define MFU_INCREASE_FACTOR 1.2
|
||||
#define MFU_DECREASE_FACTOR 0.99
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************** Public types *******************************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
// swad_MFU_database.c: Most Frequently Used actions, operations with database
|
||||
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General 3 License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/*********************************** Headers *********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "swad_database.h"
|
||||
#include "swad_global.h"
|
||||
#include "swad_MFU.h"
|
||||
#include "swad_MFU_database.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Private types *******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** External global variables from others modules ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
extern struct Globals Gbl;
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Private global variables *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Update score for the current action ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void MFU_DB_UpdateScoreForCurrentAction (long ActCod,double Score)
|
||||
{
|
||||
DB_QueryREPLACE ("can not update most frequently used actions",
|
||||
"REPLACE INTO act_frequent"
|
||||
" (UsrCod,ActCod,Score,LastClick)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,'%15lg',NOW())",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ActCod,
|
||||
Score);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Update score for other actions ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void MFU_DB_UpdateScoreForOtherActions (long ActCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update most frequently used actions",
|
||||
"UPDATE act_frequent"
|
||||
" SET Score=GREATEST(Score*'%.15lg','%.15lg')"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND ActCod<>%ld",
|
||||
MFU_DECREASE_FACTOR,
|
||||
MFU_MIN_SCORE,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ActCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Get most frequently used actions ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned MFU_DB_GetMFUActionsOrderByScore (MYSQL_RES **mysql_res)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get most frequently used actions",
|
||||
"SELECT ActCod"
|
||||
" FROM act_frequent"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Score DESC,"
|
||||
"LastClick DESC",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Get most frequently used actions ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned MFU_DB_GetMFUActionsOrderByLastClick (MYSQL_RES **mysql_res)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get the most frequently used actions",
|
||||
"SELECT ActCod"
|
||||
" FROM act_frequent"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY LastClick DESC,"
|
||||
"Score DESC",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************ Get score of current action ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned MFU_DB_GetScoreForCurrentAction (MYSQL_RES **mysql_res,long ActCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get score for current action",
|
||||
"SELECT Score" // row[0]
|
||||
" FROM act_frequent"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND ActCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ActCod);
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// swad_MFU_database.h: Most Frequently Used actions, operations with database
|
||||
|
||||
#ifndef _SWAD_MFU_DB
|
||||
#define _SWAD_MFU_DB
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance in Spanish),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/********************************** Headers **********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <mysql/mysql.h> // To access MySQL databases
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************** Public types *******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void MFU_DB_UpdateScoreForCurrentAction (long ActCod,double Score);
|
||||
void MFU_DB_UpdateScoreForOtherActions (long ActCod);
|
||||
|
||||
unsigned MFU_DB_GetMFUActionsOrderByScore (MYSQL_RES **mysql_res);
|
||||
unsigned MFU_DB_GetMFUActionsOrderByLastClick (MYSQL_RES **mysql_res);
|
||||
unsigned MFU_DB_GetScoreForCurrentAction (MYSQL_RES **mysql_res,long ActCod);
|
||||
|
||||
#endif
|
|
@ -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.17.4 (2021-09-29)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.18 (2021-09-29)"
|
||||
#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.18: Sep 29, 2021 New module swad_MFU_database for database queries related to most frequently used actions. (317529 lines)
|
||||
Version 21.17.4: Sep 29, 2021 Queries moved to module swad_message_database. (317408 lines)
|
||||
Version 21.17.3: Sep 29, 2021 Queries moved to module swad_message_database. (317431 lines)
|
||||
Version 21.17.2: Sep 27, 2021 Queries moved to module swad_message_database. (317358 lines)
|
||||
|
|
Loading…
Reference in New Issue