From 13b1cfd5447a8f8c2d1cec2c8289ef767de12b3d Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 11:35:59 +0200 Subject: [PATCH 01/17] Move tests.php to devtools --- tests.php => devtools/tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests.php => devtools/tests.php (97%) diff --git a/tests.php b/devtools/tests.php similarity index 97% rename from tests.php rename to devtools/tests.php index 8539319..c63845a 100644 --- a/tests.php +++ b/devtools/tests.php @@ -21,7 +21,7 @@ * @package report_hybridmeter */ -require(dirname(__FILE__) . '/../../config.php'); +require(dirname(__FILE__) . '/../../../config.php'); use report_hybridmeter\tests\ND\inconsistent_nd as inconsistent_nd; use report_hybridmeter\tests\NU\inconsistent_nu as inconsistent_nu; -- GitLab From a0705feab802f1c122ad1f46205560984de58939 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 11:25:50 +0200 Subject: [PATCH 02/17] Remove unnecessary code --- debug.php | 54 ----------------------------------------------- planned_tasks.php | 36 ------------------------------- vuetest.php | 29 ------------------------- 3 files changed, 119 deletions(-) delete mode 100644 debug.php delete mode 100644 planned_tasks.php delete mode 100644 vuetest.php diff --git a/debug.php b/debug.php deleted file mode 100644 index d20e3fd..0000000 --- a/debug.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -// This file is part of Moodle - http://moodle.org -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see <http://www.gnu.org/licenses/>. - -/** - * @author Nassim Bennouar - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) - * @package report_hybridmeter - */ - -require(dirname(__FILE__).'/../../config.php'); -require_once('classes/configurator.php'); - -use report_hybridmeter\configurator as configurator; - -require_login(); -$context = context_system::instance(); -$PAGE->set_context($context); -has_capability('report/hybridmeter:all', $context) || die(); - -$configurator = configurator::get_instance(); - -$task = optional_param('task', 'nothing', PARAM_ALPHAEXT); - -if ($task == "disable") { - $configurator->unset_debug(); -} else if ($task == 'enable') { - $configurator->set_debug(); -} - -if ($configurator->get_debug()) { - echo '<form action="" method="get"> - <p>Debug feature is ON</p> - <input type="submit" name="task" value="disable"/> - </form>'; -} else { - echo '<form action="" method="get"> - <p>Debug feature is OFF</p> - <input type="submit" name="task" value="enable"/> - </form>'; -} diff --git a/planned_tasks.php b/planned_tasks.php deleted file mode 100644 index 9b7c8d5..0000000 --- a/planned_tasks.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php -// This file is part of Moodle - http://moodle.org -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see <http://www.gnu.org/licenses/>. - -/** - * @author Nassim Bennouar - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) - * @package report_hybridmeter - */ - -require(dirname(__FILE__).'/../../config.php'); -require_once('classes/data_provider.php'); - -use report_hybridmeter\data_provider as data_provider; - -require_login(); -$context = context_system::instance(); -$PAGE->set_context($context); -has_capability('report/hybridmeter:all', $context) || die(); - -$plannedtasks = data_provider::get_instance()->get_adhoc_tasks_list(); - -echo json_encode($plannedtasks); diff --git a/vuetest.php b/vuetest.php deleted file mode 100644 index 7ce6b28..0000000 --- a/vuetest.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -// This file is part of Moodle - http://moodle.org -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see <http://www.gnu.org/licenses/>. - -/** - * @author Nassim Bennouar - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) - * @package report_hybridmeter - */ - -require(dirname(__FILE__).'/../../config.php'); - -require_login(); -$context = context_system::instance(); -$PAGE->set_context($context); -has_capability('report/hybridmeter:all', $context) || die(); -- GitLab From fad4c0b5da9fb464b22241a6f9ac419b0fe1a4fe Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 11:26:43 +0200 Subject: [PATCH 03/17] Add inline documentation --- ajax/result_viewer.php | 2 ++ constants.php | 8 ++++++++ index.php | 3 +++ indicators.php | 10 +++++----- management.php | 2 ++ processing.php | 2 ++ settings.php | 2 ++ version.php | 2 ++ 8 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ajax/result_viewer.php b/ajax/result_viewer.php index 7883719..e0b5184 100644 --- a/ajax/result_viewer.php +++ b/ajax/result_viewer.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Render the data collected for a course on the last processing. + * * @author Bruno Ilponse, Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) diff --git a/constants.php b/constants.php index ee42dc7..f8fea72 100644 --- a/constants.php +++ b/constants.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Plugin constants. + * * @author Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) @@ -131,6 +133,9 @@ const ALIAS = [ REPORT_HYBRIDMETER_FIELD_END_DATE => 'Fin de la période de capture', ]; +/** + * Coefficient to be applied to each type of module to calculate the "digitalization" indicator + */ const REPORT_HYBRIDMETER_DIGITALISATION_COEFFS = [ REPORT_HYBRIDMETER_MODULE_ASSIGN => 4, REPORT_HYBRIDMETER_MODULE_ASSIGNMENT => 4, @@ -159,6 +164,9 @@ const REPORT_HYBRIDMETER_DIGITALISATION_COEFFS = [ REPORT_HYBRIDMETER_MODULE_NUGGET => 5, ]; +/** + * Coefficient to be applied to each type of module to calculate the "usage" indicator + */ const REPORT_HYBRIDMETER_USAGE_COEFFS = [ REPORT_HYBRIDMETER_MODULE_ASSIGN => 4, REPORT_HYBRIDMETER_MODULE_ASSIGNMENT => 4, diff --git a/index.php b/index.php index eeeb6e6..b30b1e5 100644 --- a/index.php +++ b/index.php @@ -15,6 +15,9 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Homepage of the plugin. + * Presents the results of the last processing, allow to schedule the next run and to download the report. + * * @author Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) diff --git a/indicators.php b/indicators.php index 2286439..2758ecb 100644 --- a/indicators.php +++ b/indicators.php @@ -15,10 +15,11 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Define the lambdas computing the various indicators * @author Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) - * @package + * @package report_hybridmeter */ defined('MOODLE_INTERNAL') || die(); @@ -31,13 +32,12 @@ use report_hybridmeter\cache_manager as cache_manager; function hybridation_calculus(string $type, array $activitydata): float { $h = 0; // Hybridation value. $c = 0; // Number of activity types. - $n = 0; // Nombre total d'activités. + $n = 0; // Total number of activities. $sigmapk = 0; // Sum of activity weights. - $sigmapkvk = 0; // Sum of activity weight multiplicated by their hybridation value. + $sigmapkvk = 0; // Sum of activity weight multiplied by their hybridisation value. $m = 1; // Malus. foreach ($activitydata as $k => $nk) { - // Possibilité d'accéder à des valeurs hardcodées pour le diagnostic. - $vk = configurator::get_instance()->get_coeff($type, $k); // Activity hybridation value. + $vk = configurator::get_instance()->get_coeff($type, $k); // Activity hybridisation value. if ($nk > 0 && $vk > 0) { $c ++; diff --git a/management.php b/management.php index 77b5b4a..fa128e4 100644 --- a/management.php +++ b/management.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Page allowing an administrator to configure the next computation of HybridMeter report. + * * @author Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) diff --git a/processing.php b/processing.php index 0d59d76..ab21b1d 100644 --- a/processing.php +++ b/processing.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Launch manually the computation of indicators. + * * @author Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) diff --git a/settings.php b/settings.php index 5ec2ac1..6df7a40 100644 --- a/settings.php +++ b/settings.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Plugin settings. + * * @author Bruno Ilponse, Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) diff --git a/version.php b/version.php index 8600bc5..cb15d39 100644 --- a/version.php +++ b/version.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Plugin version information. + * * @author Nassim Bennouar, Bruno Ilponse, John Tranier * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) -- GitLab From 0f03277e91d81361f0d1f30cb4aa4aaaf4100c93 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 15:50:34 +0200 Subject: [PATCH 04/17] Reduce ajax/moodle_data to ajax/moodle_role --- ajax/{moodle_data.php => moodle_roles.php} | 12 ++---------- .../components/subcomponents/OtherDataManager.vue | 5 ++--- .../components/subcomponents/OtherDataManager.vue | 5 ++--- 3 files changed, 6 insertions(+), 16 deletions(-) rename ajax/{moodle_data.php => moodle_roles.php} (84%) diff --git a/ajax/moodle_data.php b/ajax/moodle_roles.php similarity index 84% rename from ajax/moodle_data.php rename to ajax/moodle_roles.php index 80c2763..784438d 100644 --- a/ajax/moodle_data.php +++ b/ajax/moodle_roles.php @@ -32,13 +32,5 @@ $context = \context_system::instance(); $PAGE->set_context($context); has_capability('report/hybridmeter:all', $context) || die(); -$task = required_param('task', PARAM_ALPHAEXT); - -if ($task == "roles") { - $roles = $DB->get_records("role"); - $output = json_encode(array_values($roles)); -} else { - $output = json_encode([]); -} - -echo $output; +$roles = $DB->get_records("role"); +echo json_encode($roles); diff --git a/amd/src/components/subcomponents/OtherDataManager.vue b/amd/src/components/subcomponents/OtherDataManager.vue index e5d7a50..89ee870 100644 --- a/amd/src/components/subcomponents/OtherDataManager.vue +++ b/amd/src/components/subcomponents/OtherDataManager.vue @@ -76,10 +76,9 @@ export default { message.messages.success.message = strings.value.student_archetype_updated; }); - let data = [{ task : "roles" }]; - dispatchCurrentDebug(store.state.debug) + dispatchCurrentDebug(store.state.debug) - get("moodle_data", data).then(data => roles.value = data).then(() => { + get("moodle_roles").then(data => roles.value = data).then(() => { dispatchCurrentArchetype(store.state.student_archetype) }); } diff --git a/vue/src/components/subcomponents/OtherDataManager.vue b/vue/src/components/subcomponents/OtherDataManager.vue index e5d7a50..89ee870 100644 --- a/vue/src/components/subcomponents/OtherDataManager.vue +++ b/vue/src/components/subcomponents/OtherDataManager.vue @@ -76,10 +76,9 @@ export default { message.messages.success.message = strings.value.student_archetype_updated; }); - let data = [{ task : "roles" }]; - dispatchCurrentDebug(store.state.debug) + dispatchCurrentDebug(store.state.debug) - get("moodle_data", data).then(data => roles.value = data).then(() => { + get("moodle_roles").then(data => roles.value = data).then(() => { dispatchCurrentArchetype(store.state.student_archetype) }); } -- GitLab From 9aeb2f3957fb5ab1a9540b1b593bd86b6b5bc50d Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 15:53:04 +0200 Subject: [PATCH 05/17] Add inline documentation --- ajax/configuration_handler.php | 2 ++ ajax/moodle_roles.php | 2 ++ classes/data/general_data.php | 38 ++++++++++++++++++++++++++- classes/utils.php | 47 ++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/ajax/configuration_handler.php b/ajax/configuration_handler.php index b9d3a3b..f17bbe2 100644 --- a/ajax/configuration_handler.php +++ b/ajax/configuration_handler.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Endpoint to update or retrieve HybridMeter config. + * * @author Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) diff --git a/ajax/moodle_roles.php b/ajax/moodle_roles.php index 784438d..04546a6 100644 --- a/ajax/moodle_roles.php +++ b/ajax/moodle_roles.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Render moodle roles as JSON. + * * @author Nassim Bennouar * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) diff --git a/classes/data/general_data.php b/classes/data/general_data.php index 5b69782..71244b7 100644 --- a/classes/data/general_data.php +++ b/classes/data/general_data.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * General (or aggregated) data produced by HybridMeter processing. + * * @author Nassim Bennouar, John Tranier * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) @@ -25,19 +27,53 @@ namespace report_hybridmeter\data; use report_hybridmeter\configurator as configurator; use report_hybridmeter\data_provider as data_provider; +/** + * General (or aggregated) data produced by HybridMeter processing. + */ class general_data { + /** + * @var $begintimestamp : Beginning of the analyzed period. + */ protected $begintimestamp; + + /** + * @var $endtimestamp : End of the analyzed period. + */ protected $endtimestamp; + /** + * @var array $courses : List of analyzed courses. + */ protected $courses; + + /** + * @var array $usedcourses : List of analysed courses that pass the "used" threshold. + */ protected $usedcourses; - protected $digitalisedcourses; + /** + * @var array $digitalisedcourses : List of analysed courses that pass the "digitalized" threshold. + */ protected $digitalisedcourses; + + /** + * @var int Number of students registered on digitalized courses. + */ protected $nbstudentsconcerneddigitalised; + + /** + * @var int Number of students registered on used courses. + */ protected $nbstudentsconcernedused; + /** + * @var int Number of active students on digitalized courses. + */ protected $nbstudentsconcerneddigitalisedactive; + + /** + * @var int Number of active students on used coursed. + */ protected $nbstudentsconcernedusedactive; public function __construct($courses, $configurator) { diff --git a/classes/utils.php b/classes/utils.php index c638906..bac7b57 100644 --- a/classes/utils.php +++ b/classes/utils.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Facilities functions. + * * @author Nassim Bennouar, Bruno Ilponse * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) @@ -41,6 +43,13 @@ class utils { }, $array)); } + /** + * Checks that an array contains only int values. + * + * @param array $idscourses + * @return void + * @throws Exception + */ public static function precondition_ids(array $idscourses) { $accumulatedprecondition = array_reduce( @@ -55,6 +64,11 @@ class utils { } } + /** + * Returns the timestamp for tomorrow at midnight. + * + * @return false|int + */ public static function tomorrow_midnight() { $tomorrowmidnight = strtotime("tomorrow 00:00"); return $tomorrowmidnight; @@ -87,6 +101,12 @@ class utils { return $output; } + /** + * Display an associative array as an HTML table. + * + * @param array $array + * @return string + */ public static function data_grouped_by_to_html(array $array): string { $output = "<table>"; $output .= "<tbody>"; @@ -106,6 +126,12 @@ class utils { return $output; } + /** + * Display an array as an HTML table with headers. + * + * @param array $array + * @return string + */ public static function columns_rows_array_to_html(array $array): string { $output = "<table>"; $output .= "<thead><tr>"; @@ -127,6 +153,13 @@ class utils { return $output; } + /** + * Render an array in HTML using n_uplets style. + * + * @param array $array + * @param int $n + * @return string + */ public static function array_to_n_uplets_table_html(array $array, int $n = 10): string { $output = "<table>"; $output .= "<tbody>"; @@ -147,6 +180,13 @@ class utils { return $output; } + /** + * Convert a timestamp to a datetime. + * + * @param int $timestamp + * @param string $format + * @return string + */ public static function timestamp_to_datetime(int $timestamp, string $format = 'd/m/Y H:i:s e'): string { $datetime = new DateTime(); $datetime->setTimestamp($timestamp); @@ -154,6 +194,13 @@ class utils { return $datetime->format($format); } + /** + * Modulo operation ensuring a positive result. + * + * @param $x + * @param int $n + * @return int + */ public static function modulo_fixed($x, int $n): int { $r = $x % $n; if ($r < 0) { -- GitLab From 2e457ceaf91c78af917402fead5877c54443ca36 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 16:58:09 +0200 Subject: [PATCH 06/17] Remove dead code --- classes/utils.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/classes/utils.php b/classes/utils.php index bac7b57..48dda0f 100644 --- a/classes/utils.php +++ b/classes/utils.php @@ -28,20 +28,10 @@ use report_hybridmeter\formatter as formatter; use Exception; use DateTime; +/** + * Facilities functions. + */ class utils { - public static function object_to_array(object $object) { - $array = []; - foreach ($object as $key => $value) { - $array[$key] = $value; - } - return $array; - } - - public static function id_objects_array_to_array(array $array) { - return array_values(array_map(function($obj) { - return $obj->id; - }, $array)); - } /** * Checks that an array contains only int values. -- GitLab From 9b4726a6ebce30942fa26bc48001ad4da213cc59 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 17:00:17 +0200 Subject: [PATCH 07/17] Add inline documentation --- classes/logger.php | 31 ++++++++++--------------------- classes/utils.php | 6 ++++++ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/classes/logger.php b/classes/logger.php index 9cb4ab5..0f5e34d 100644 --- a/classes/logger.php +++ b/classes/logger.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Plugin logger. + * * @author Nassim Bennouar, Bruno Ilponse * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) @@ -24,32 +26,19 @@ namespace report_hybridmeter; use report_hybridmeter\configurator as configurator; -// Hybridmeter's logger. +/** + * Plugin logger. + */ class logger { - private static function var_dump_ret($object) { - ob_start(); - var_dump($object); - $content = ob_get_contents(); - ob_end_clean(); - return $content; - } - - public static function log_var_dump($object) { - if (configurator::get_instance()->get_debug()) { - debugging("[Hybridmeter] ".self::var_dump_ret($object)); - } - } + /** + * Print an object if debug mode is enabled. + * @param $object + * @return void + */ public static function log($object) { if (configurator::get_instance()->get_debug()) { debugging("[Hybridmeter] ".print_r($object, 1)); } } - - public static function file_log($object, $filename) { - if (configurator::get_instance()->get_debug()) { - $file = fopen(dirname(__FILE__).'/../'.$filename, 'a'); - fwrite($file, print_r($object, 1)); - } - } } diff --git a/classes/utils.php b/classes/utils.php index 48dda0f..0749df3 100644 --- a/classes/utils.php +++ b/classes/utils.php @@ -64,6 +64,12 @@ class utils { return $tomorrowmidnight; } + /** + * Render an array of objects as HTML. + * + * @param array $array + * @return string + */ public static function objects_array_to_html(array $array): string { if (empty($array)) { return "No data"; -- GitLab From 04729f716cb9d495b3eb4226906015a90b0feafc Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 19:48:15 +0200 Subject: [PATCH 08/17] Minor code cleaning --- classes/processing.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/classes/processing.php b/classes/processing.php index 682ca13..571021d 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -55,8 +55,12 @@ class processing { $configurator->get_begin_timestamp(), $configurator->get_end_timestamp() ); - $filteredids = array_map(function ($a) { return $a->id; - }, $filtered); + $filteredids = array_map( + function ($course) { + return $course->id; + }, + $filtered + ); logger::log("Active course ids: ".implode(", ", $filteredids)); $this->formatter = new formatter($filtered); @@ -72,13 +76,10 @@ class processing { logger::log("# Processing: blacklist computation"); $configurator = configurator::get_instance(); - $configurator->set_as_running($this->begin_date); - $configurator->update_blacklisted_data(); // Calculation of detailed indicators. - logger::log("# Processing: course indicators computation"); $this->formatter->calculate_new_indicator( -- GitLab From 51275423f81afdfeb29146f78282c210cbf8f596 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Tue, 16 Apr 2024 19:52:58 +0200 Subject: [PATCH 09/17] Code cleaning : Use configurator as singleton --- classes/data/general_data.php | 3 ++- classes/processing.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/classes/data/general_data.php b/classes/data/general_data.php index 71244b7..5ade88e 100644 --- a/classes/data/general_data.php +++ b/classes/data/general_data.php @@ -76,7 +76,8 @@ class general_data { */ protected $nbstudentsconcernedusedactive; - public function __construct($courses, $configurator) { + public function __construct($courses) { + $configurator = configurator::get_instance(); $dataprovider = data_provider::get_instance(); $this->begintimestamp = $configurator->get_begin_timestamp(); diff --git a/classes/processing.php b/classes/processing.php index 571021d..428f621 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -180,7 +180,7 @@ class processing { // Calculation of general indicators. logger::log("# Processing: global indicators computation"); - $generaldata = new general_data($dataout, $configurator); + $generaldata = new general_data($dataout); // Data exportation. logger::log("# Processing: serializing results"); -- GitLab From ffd218a22c93342224ab09a86b6ad888d24ba022 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 09:27:16 +0200 Subject: [PATCH 10/17] class processing.php : Merge construct & launch() --- classes/processing.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/classes/processing.php b/classes/processing.php index 428f621..6cd15aa 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -40,7 +40,9 @@ class processing { protected $begin_date; protected $end_date; - public function __construct() { + public function launch() { + global $CFG; + logger::log("# Processing: initializing"); $timestamp = REPORT_HYBRIDMETER_NOW; @@ -69,10 +71,7 @@ class processing { $this->begin_date->setTimestamp($timestamp); $this->end_date = new DateTime(); - } - public function launch() { - global $CFG; logger::log("# Processing: blacklist computation"); $configurator = configurator::get_instance(); -- GitLab From 1400a3abe8737c687682d7f407847891ca092311 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 09:57:09 +0200 Subject: [PATCH 11/17] class processing.php : Set launch() as static --- classes/processing.php | 58 +++++++++++++++----------------- classes/task/cron_processing.php | 3 +- classes/task/processing.php | 3 +- processing.php | 3 +- 4 files changed, 30 insertions(+), 37 deletions(-) diff --git a/classes/processing.php b/classes/processing.php index 6cd15aa..fc6d5d6 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -36,11 +36,7 @@ use DateTime; class processing { - protected $formatter; - protected $begin_date; - protected $end_date; - - public function launch() { + public static function launch() { global $CFG; logger::log("# Processing: initializing"); @@ -65,42 +61,42 @@ class processing { ); logger::log("Active course ids: ".implode(", ", $filteredids)); - $this->formatter = new formatter($filtered); + $formatter = new formatter($filtered); - $this->begin_date = new DateTime(); - $this->begin_date->setTimestamp($timestamp); + $begin_date = new DateTime(); + $begin_date->setTimestamp($timestamp); - $this->end_date = new DateTime(); + $end_date = new DateTime(); logger::log("# Processing: blacklist computation"); $configurator = configurator::get_instance(); - $configurator->set_as_running($this->begin_date); + $configurator->set_as_running($begin_date); $configurator->update_blacklisted_data(); // Calculation of detailed indicators. logger::log("# Processing: course indicators computation"); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( function($object) { return $object['id']; }, REPORT_HYBRIDMETER_FIELD_ID_MOODLE ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( "get_category_path", REPORT_HYBRIDMETER_FIELD_CATEGORY_PATH ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( function($object) { return $object['idnumber']; }, REPORT_HYBRIDMETER_FIELD_ID_NUMBER ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( function($object, $parameters) { return $parameters["www_root"]."/course/view.php?id=".$object['id']; }, @@ -110,33 +106,33 @@ class processing { ] ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( "digitalisation_level", REPORT_HYBRIDMETER_FIELD_DIGITALISATION_LEVEL, [ - "nb_cours" => $this->formatter->get_length_array(), + "nb_cours" => $formatter->get_length_array(), ] ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( "usage_level", REPORT_HYBRIDMETER_FIELD_USAGE_LEVEL, [ - "nb_cours" => $this->formatter->get_length_array(), + "nb_cours" => $formatter->get_length_array(), ] ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( "is_course_active_last_month", REPORT_HYBRIDMETER_FIELD_ACTIVE_COURSE ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( "active_students", REPORT_HYBRIDMETER_FIELD_NB_ACTIVE_USERS ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( "nb_registered_students", REPORT_HYBRIDMETER_FIELD_NB_REGISTERED_STUDENTS ); @@ -145,7 +141,7 @@ class processing { $begindate->setTimestamp($configurator->get_begin_timestamp()); $begindate = $begindate->format('d/m/Y'); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( function ($object, $parameters) { return $parameters['begin_date']; }, @@ -159,7 +155,7 @@ class processing { $enddate->setTimestamp($configurator->get_end_timestamp()); $enddate = $enddate->format('d/m/Y'); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( function ($object, $parameters) { return $parameters['end_date']; }, @@ -169,12 +165,12 @@ class processing { ] ); - $this->formatter->calculate_new_indicator( + $formatter->calculate_new_indicator( 'raw_data', 'raw_data' ); - $dataout = $this->formatter->get_array(); + $dataout = $formatter->get_array(); // Calculation of general indicators. logger::log("# Processing: global indicators computation"); @@ -184,13 +180,13 @@ class processing { // Data exportation. logger::log("# Processing: serializing results"); - $this->end_date->setTimestamp(strtotime("now")); + $end_date->setTimestamp(strtotime("now")); - $interval = $this->end_date->getTimestamp() - $this->begin_date->getTimestamp(); + $interval = $end_date->getTimestamp() - $begin_date->getTimestamp(); $time = [ - "begin_timestamp" => $this->begin_date->getTimestamp(), - "end_timestamp" => $this->end_date->getTimestamp(), + "begin_timestamp" => $begin_date->getTimestamp(), + "end_timestamp" => $end_date->getTimestamp(), "diff" => $interval, ]; @@ -209,10 +205,10 @@ class processing { fclose($fileexporter); /* We have deactivated CSV logging for RGPD reasons (we need to renegotiate the conditions with the DPO to include them) - * $formatted_date = $this->begin_date->format('Y-m-d H:i:s'); + * $formatted_date = $begin_date->format('Y-m-d H:i:s'); * $filename = $CFG->dataroot."/hybridmeter/records/backup/record_".$formatted_date.".csv"; * $backup=fopen($filename,"w"); - * fwrite($backup, $this->exporter->print_csv_data(true)); + * fwrite($backup, $exporter->print_csv_data(true)); */ // Log and task management. diff --git a/classes/task/cron_processing.php b/classes/task/cron_processing.php index 229cda2..7c17cf5 100644 --- a/classes/task/cron_processing.php +++ b/classes/task/cron_processing.php @@ -33,7 +33,6 @@ class cron_processing extends scheduled_task { } public function execute() { - $processing = new processing(); - $processing->launch(); + processing::launch(); } } diff --git a/classes/task/processing.php b/classes/task/processing.php index 4d06551..2eaaddc 100644 --- a/classes/task/processing.php +++ b/classes/task/processing.php @@ -33,7 +33,6 @@ class processing extends adhoc_task { public function execute() { \report_hybridmeter\configurator::get_instance()->unschedule_calculation(); - $processing = new class_processing(); - $processing->launch(); + class_processing::launch(); } } diff --git a/processing.php b/processing.php index ab21b1d..a5c7fb8 100644 --- a/processing.php +++ b/processing.php @@ -31,7 +31,6 @@ $context = context_system::instance(); $PAGE->set_context($context); has_capability('report/hybridmeter:all', $context) || die(); -$processing = new report_hybridmeter\processing(); -$data = $processing->launch(); +$data = report_hybridmeter\processing::launch(); echo json_encode($data); -- GitLab From 446754165c74aa40c0c0e7f923208408ff897f38 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 09:59:15 +0200 Subject: [PATCH 12/17] Add inline documentation --- classes/processing.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/classes/processing.php b/classes/processing.php index fc6d5d6..5fcef1a 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** + * Produce HybridMeter report. + * * @author Nassim Bennouar, Bruno Ilponse * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) @@ -34,8 +36,16 @@ use report_hybridmeter\formatter as formatter; use report_hybridmeter\logger as logger; use DateTime; +/** + * Produce HybridMeter report. + */ class processing { + /** + * Launch the computations to produce HybridMeter report. + * + * @return array + */ public static function launch() { global $CFG; -- GitLab From d172057d1d051c018105066fb7508b6fdb91be95 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 10:02:25 +0200 Subject: [PATCH 13/17] Move class general_data.php in default plugin namespace --- classes/{data => }/general_data.php | 4 ++-- classes/processing.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename classes/{data => }/general_data.php (98%) diff --git a/classes/data/general_data.php b/classes/general_data.php similarity index 98% rename from classes/data/general_data.php rename to classes/general_data.php index 5ade88e..fbb06bc 100644 --- a/classes/data/general_data.php +++ b/classes/general_data.php @@ -15,14 +15,14 @@ // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** - * General (or aggregated) data produced by HybridMeter processing. + * General data produced by HybridMeter processing. * * @author Nassim Bennouar, John Tranier * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) * @package report_hybridmeter */ -namespace report_hybridmeter\data; +namespace report_hybridmeter; use report_hybridmeter\configurator as configurator; use report_hybridmeter\data_provider as data_provider; diff --git a/classes/processing.php b/classes/processing.php index 5fcef1a..b4b0532 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -29,12 +29,12 @@ defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/../indicators.php'); require_once(__DIR__.'/../constants.php'); -use report_hybridmeter\data\general_data as general_data; -use report_hybridmeter\data_provider as data_provider; +use DateTime; use report_hybridmeter\configurator as configurator; +use report_hybridmeter\data_provider as data_provider; use report_hybridmeter\formatter as formatter; +use report_hybridmeter\general_data as general_data; use report_hybridmeter\logger as logger; -use DateTime; /** * Produce HybridMeter report. -- GitLab From bfb36c1d26a560fa28562c4f5a5458f890e64f85 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 11:51:28 +0200 Subject: [PATCH 14/17] Code cleaning : rewrite indicators computation --- classes/course_data.php | 69 +++++++++++++++++++++++++ classes/general_data.php | 4 +- classes/indicators.php | 101 +++++++++++++++++++++++++++++++++++++ classes/processing.php | 106 +++++++-------------------------------- 4 files changed, 191 insertions(+), 89 deletions(-) create mode 100644 classes/course_data.php create mode 100644 classes/indicators.php diff --git a/classes/course_data.php b/classes/course_data.php new file mode 100644 index 0000000..ba24161 --- /dev/null +++ b/classes/course_data.php @@ -0,0 +1,69 @@ +<?php + +namespace report_hybridmeter; + +use Cassandra\Date; + +class course_data { + + protected $id; + protected $fullname; + protected $category_id; + protected $category_name; + protected $categorypath; + protected $idnumber; + protected $url; + protected $digitalisationlevel; + protected $usagelevel; + protected $activelastmonth; + protected $activestudents; + protected $nbregisteredstudents; + protected $begindate; + protected $enddate; + protected $rawdata; + + public function __construct($course, $wwwroot) { + $this->id = $course->id; + $this->fullname = $course->fullname; + $this->category_id = $course->category_id; + $this->category_name = $course->category_name; + $this->categorypath = indicators::get_category_path($course); + $this->idnumber = $course->idnumber; + $this->url = $wwwroot."/course/view.php?id=".$this->id; + $this->digitalisationlevel = indicators::digitalisation_level($this->id); + $this->usagelevel = indicators::usage_level($this->id); + $this->activelastmonth = indicators::is_course_active_last_month($this->id); + $this->activestudents = indicators::active_students($this->id); + $this->nbregisteredstudents = indicators::nb_registered_students($this->id); + $this->rawdata = indicators::raw_data($this->id); + } + + public function set_begindate($begindate) { + $this->begindate = $begindate; + } + + public function set_enddate($enddate) { + $this->enddate = $enddate; + } + + public function to_map() { + return [ + 'id' => $this->id, + 'fullname' => $this->fullname, + 'category_id' => $this->category_id, + 'category_name' => $this->category_name, + REPORT_HYBRIDMETER_FIELD_ID_MOODLE => $this->id, + REPORT_HYBRIDMETER_FIELD_CATEGORY_PATH => $this->categorypath, + REPORT_HYBRIDMETER_FIELD_ID_NUMBER => $this->idnumber, + REPORT_HYBRIDMETER_FIELD_URL => $this->url, + REPORT_HYBRIDMETER_FIELD_DIGITALISATION_LEVEL => $this->digitalisationlevel, + REPORT_HYBRIDMETER_FIELD_USAGE_LEVEL => $this->usagelevel, + REPORT_HYBRIDMETER_FIELD_ACTIVE_COURSE => $this->activelastmonth, + REPORT_HYBRIDMETER_FIELD_NB_ACTIVE_USERS =>$this->activestudents, + REPORT_HYBRIDMETER_FIELD_NB_REGISTERED_STUDENTS => $this->nbregisteredstudents, + REPORT_HYBRIDMETER_FIELD_BEGIN_DATE => $this->begindate, + REPORT_HYBRIDMETER_FIELD_END_DATE => $this->enddate, + 'raw_data' => $this->rawdata, + ]; + } +} \ No newline at end of file diff --git a/classes/general_data.php b/classes/general_data.php index fbb06bc..667e945 100644 --- a/classes/general_data.php +++ b/classes/general_data.php @@ -159,8 +159,8 @@ class general_data { protected function getids($courses) { return array_map( - function ($cours) { - return intval($cours["id"]); + function ($course) { + return intval($course["id"]); }, $courses); } } diff --git a/classes/indicators.php b/classes/indicators.php new file mode 100644 index 0000000..5b13664 --- /dev/null +++ b/classes/indicators.php @@ -0,0 +1,101 @@ +<?php + +namespace report_hybridmeter; + +class indicators { + + public static function get_category_path($course): string { + $cachemanager = cache_manager::get_instance(); + + if ($cachemanager->is_category_path_calculated($course->category_id)) { + return $cachemanager->get_category_path($course->category_id); + } + + $categorypath = data_provider::get_instance()->get_category_path($course->category_id); + + $cachemanager->update_category_path($course->category_id, $categorypath); + + return $categorypath; + } + + public static function digitalisation_level($courseid): float { + $activitydata = data_provider::get_instance()->count_activities_per_type_of_course($courseid); + return hybridation_calculus("digitalisation_coeffs", $activitydata); + } + + public static function usage_level($courseid): float { + $dataprovider = data_provider::get_instance(); + $configurator = configurator::get_instance(); + $indicator = 0; + $total = 0; + $activitydata = $dataprovider->count_hits_on_activities_per_type( + $courseid, + $configurator->get_begin_timestamp(), + $configurator->get_end_timestamp() + ); + return hybridation_calculus("usage_coeffs", $activitydata); + } + + public static function is_course_active_last_month($courseid): int { + $configurator = configurator::get_instance(); + $dataprovider = data_provider::get_instance(); + + $count = $dataprovider->count_student_single_visitors_on_courses( + [$courseid], + $configurator->get_begin_timestamp(), + $configurator->get_end_timestamp() + ); + + if ($count >= $configurator->get_data()["active_treshold"]) { + return 1; + } else { + return 0; + } + } + + public static function active_students ($courseid): int { + $configurator = configurator::get_instance(); + return data_provider::get_instance()->count_student_single_visitors_on_courses( + [$courseid], + $configurator->get_begin_timestamp(), + $configurator->get_end_timestamp() + ); + } + + public static function nb_registered_students ($courseid): int { + return data_provider::get_instance()->count_registered_students_of_course($courseid); + } + + public static function raw_data($courseid): array { + return data_provider::get_instance()->count_activities_per_type_of_course($courseid); + } + + public static function hybridation_calculus(string $type, array $activitydata): float { + $h = 0; // Hybridation value. + $c = 0; // Number of activity types. + $n = 0; // Total number of activities. + $sigmapk = 0; // Sum of activity weights. + $sigmapkvk = 0; // Sum of activity weight multiplied by their hybridisation value. + $m = 1; // Malus. + foreach ($activitydata as $k => $nk) { + $vk = configurator::get_instance()->get_coeff($type, $k); // Activity hybridisation value. + + if ($nk > 0 && $vk > 0) { + $c ++; + $n += $nk; + $pk = $nk / ($nk + REPORT_HYBRIDMETER_ACTIVITY_INSTANCES_DEVIATOR_CONSTANT); // Activity weight. + $sigmapk += $pk; + $sigmapkvk += $pk * $vk; + } + } + if ($n <= 2) { + $m = 0.25; + } + if ($sigmapk != 0) { + $p = $c / ($c + REPORT_HYBRIDMETER_ACTIVITY_VARIETY_DEVIATOR_CONSTANT); // Course weight. + $h = $m * $p * $sigmapkvk / $sigmapk; + } + return round($h, 2); + } + +} \ No newline at end of file diff --git a/classes/processing.php b/classes/processing.php index b4b0532..e9c8d4f 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -32,7 +32,6 @@ require_once(__DIR__.'/../constants.php'); use DateTime; use report_hybridmeter\configurator as configurator; use report_hybridmeter\data_provider as data_provider; -use report_hybridmeter\formatter as formatter; use report_hybridmeter\general_data as general_data; use report_hybridmeter\logger as logger; @@ -58,20 +57,18 @@ class processing { $whitelistids = $dataprovider->get_whitelisted_courses_ids(); logger::log("Whitelisted course ids: ".implode(", ", $whitelistids)); - $filtered = $dataprovider->filter_living_courses_on_period( + $courses = $dataprovider->filter_living_courses_on_period( $whitelistids, $configurator->get_begin_timestamp(), $configurator->get_end_timestamp() ); - $filteredids = array_map( + $courseids = array_map( function ($course) { return $course->id; }, - $filtered + $courses ); - logger::log("Active course ids: ".implode(", ", $filteredids)); - - $formatter = new formatter($filtered); + logger::log("Active course ids: ".implode(", ", $courseids)); $begin_date = new DateTime(); $begin_date->setTimestamp($timestamp); @@ -87,100 +84,35 @@ class processing { // Calculation of detailed indicators. logger::log("# Processing: course indicators computation"); - $formatter->calculate_new_indicator( - function($object) { - return $object['id']; - }, - REPORT_HYBRIDMETER_FIELD_ID_MOODLE - ); - - $formatter->calculate_new_indicator( - "get_category_path", - REPORT_HYBRIDMETER_FIELD_CATEGORY_PATH - ); - - $formatter->calculate_new_indicator( - function($object) { - return $object['idnumber']; - }, - REPORT_HYBRIDMETER_FIELD_ID_NUMBER - ); - - $formatter->calculate_new_indicator( - function($object, $parameters) { - return $parameters["www_root"]."/course/view.php?id=".$object['id']; + $processeddata = array_map( + function ($course) { + global $CFG; + return new course_data($course, $CFG->wwwroot); }, - REPORT_HYBRIDMETER_FIELD_URL, - [ - "www_root" => $CFG->wwwroot, - ] - ); - - $formatter->calculate_new_indicator( - "digitalisation_level", - REPORT_HYBRIDMETER_FIELD_DIGITALISATION_LEVEL, - [ - "nb_cours" => $formatter->get_length_array(), - ] - ); - - $formatter->calculate_new_indicator( - "usage_level", - REPORT_HYBRIDMETER_FIELD_USAGE_LEVEL, - [ - "nb_cours" => $formatter->get_length_array(), - ] - ); - - $formatter->calculate_new_indicator( - "is_course_active_last_month", - REPORT_HYBRIDMETER_FIELD_ACTIVE_COURSE - ); - - $formatter->calculate_new_indicator( - "active_students", - REPORT_HYBRIDMETER_FIELD_NB_ACTIVE_USERS - ); - - $formatter->calculate_new_indicator( - "nb_registered_students", - REPORT_HYBRIDMETER_FIELD_NB_REGISTERED_STUDENTS + $courses ); $begindate = new DateTime(); $begindate->setTimestamp($configurator->get_begin_timestamp()); $begindate = $begindate->format('d/m/Y'); - $formatter->calculate_new_indicator( - function ($object, $parameters) { - return $parameters['begin_date']; - }, - REPORT_HYBRIDMETER_FIELD_BEGIN_DATE, - [ - "begin_date" => $begindate, - ] - ); $enddate = new DateTime(); $enddate->setTimestamp($configurator->get_end_timestamp()); $enddate = $enddate->format('d/m/Y'); - $formatter->calculate_new_indicator( - function ($object, $parameters) { - return $parameters['end_date']; - }, - REPORT_HYBRIDMETER_FIELD_END_DATE, - [ - "end_date" => $enddate, - ] - ); + foreach ($processeddata as $coursedata) { + $coursedata->set_begindate($begindate); + $coursedata->set_enddate($enddate); - $formatter->calculate_new_indicator( - 'raw_data', - 'raw_data' - ); + } - $dataout = $formatter->get_array(); + $dataout = array_map( + function ($coursedata) { + return $coursedata->to_map(); + }, + $processeddata + ); // Calculation of general indicators. logger::log("# Processing: global indicators computation"); -- GitLab From 573babd3fedbf6b6aaf4e15584d41362b19577ec Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 12:39:25 +0200 Subject: [PATCH 15/17] Code cleaning : Remove formatter class --- classes/formatter.php | 75 ------------------------------------------- classes/utils.php | 9 ++++-- 2 files changed, 7 insertions(+), 77 deletions(-) delete mode 100644 classes/formatter.php diff --git a/classes/formatter.php b/classes/formatter.php deleted file mode 100644 index 88e667a..0000000 --- a/classes/formatter.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php -// This file is part of Moodle - http://moodle.org -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see <http://www.gnu.org/licenses/>. - -/** - * @author Nassim Bennouar - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) - * @package report_hybridmeter - */ -namespace report_hybridmeter; - -use Exception; - -class formatter { - - protected $data; - - public function __construct(array $data) { - $this->precondition_record($data); - $this->data = $this->objects_array_to_2D_array($data); - } - - protected function objects_array_to_2d_array(array $data): array { - return (array) array_map( - function($element) { - return (array) $element; - }, - $data - ); - } - - protected function precondition_record(array $data) { - $accumulatedprecondition = array_reduce( - $data, - function($acc, $record) { - return ($acc && (is_object($record) || is_array($record))); - }, - true - ); - - if (!$accumulatedprecondition) { - throw new Exception("The data is not formatted correctly, a record is an array of objects or a two dimensional array"); - } - } - - public function calculate_new_indicator($lambda, string $indicatorname, array $parameters = []) { - $i = 1; - foreach ($this->data as $key => $value) { - logger::log("Computing indicator ".$indicatorname." for course id=". $key." (".$i."/".count($this->data).")"); - $this->data[$key][$indicatorname] = $lambda($value, $parameters); - $i++; - } - } - - public function get_array(): array { - return $this->data; - } - - public function get_length_array(): int { - return count($this->data); - } -} diff --git a/classes/utils.php b/classes/utils.php index 0749df3..4dd5c6b 100644 --- a/classes/utils.php +++ b/classes/utils.php @@ -24,7 +24,6 @@ */ namespace report_hybridmeter; -use report_hybridmeter\formatter as formatter; use Exception; use DateTime; @@ -74,7 +73,13 @@ class utils { if (empty($array)) { return "No data"; } - $array = (new formatter($array))->get_array(); + + $array = array_map( + function($element) { + return (array) $element; + }, + $array + ); $output = "<table>"; $output .= "<thead><tr>"; -- GitLab From 2104efa4239b09c7519d46d008b4a79dc14b5889 Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 12:44:43 +0200 Subject: [PATCH 16/17] Code cleaning : Remove indicators.php --- classes/indicators.php | 4 +- classes/processing.php | 1 - indicators.php | 125 ----------------------------------------- 3 files changed, 2 insertions(+), 128 deletions(-) delete mode 100644 indicators.php diff --git a/classes/indicators.php b/classes/indicators.php index 5b13664..f7e5e66 100644 --- a/classes/indicators.php +++ b/classes/indicators.php @@ -20,7 +20,7 @@ class indicators { public static function digitalisation_level($courseid): float { $activitydata = data_provider::get_instance()->count_activities_per_type_of_course($courseid); - return hybridation_calculus("digitalisation_coeffs", $activitydata); + return self::hybridation_calculus("digitalisation_coeffs", $activitydata); } public static function usage_level($courseid): float { @@ -33,7 +33,7 @@ class indicators { $configurator->get_begin_timestamp(), $configurator->get_end_timestamp() ); - return hybridation_calculus("usage_coeffs", $activitydata); + return self::hybridation_calculus("usage_coeffs", $activitydata); } public static function is_course_active_last_month($courseid): int { diff --git a/classes/processing.php b/classes/processing.php index e9c8d4f..b27a4fe 100644 --- a/classes/processing.php +++ b/classes/processing.php @@ -26,7 +26,6 @@ namespace report_hybridmeter; defined('MOODLE_INTERNAL') || die(); -require_once(__DIR__.'/../indicators.php'); require_once(__DIR__.'/../constants.php'); use DateTime; diff --git a/indicators.php b/indicators.php deleted file mode 100644 index 2758ecb..0000000 --- a/indicators.php +++ /dev/null @@ -1,125 +0,0 @@ -<?php -// This file is part of Moodle - http://moodle.org -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see <http://www.gnu.org/licenses/>. - -/** - * Define the lambdas computing the various indicators - * @author Nassim Bennouar - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @copyright (C) 2020 ISAE-SUPAERO (https://www.isae-supaero.fr/) - * @package report_hybridmeter - */ -defined('MOODLE_INTERNAL') || die(); - -require_once(__DIR__.'/constants.php'); - -use report_hybridmeter\configurator as configurator; -use report_hybridmeter\data_provider as data_provider; -use report_hybridmeter\cache_manager as cache_manager; - -function hybridation_calculus(string $type, array $activitydata): float { - $h = 0; // Hybridation value. - $c = 0; // Number of activity types. - $n = 0; // Total number of activities. - $sigmapk = 0; // Sum of activity weights. - $sigmapkvk = 0; // Sum of activity weight multiplied by their hybridisation value. - $m = 1; // Malus. - foreach ($activitydata as $k => $nk) { - $vk = configurator::get_instance()->get_coeff($type, $k); // Activity hybridisation value. - - if ($nk > 0 && $vk > 0) { - $c ++; - $n += $nk; - $pk = $nk / ($nk + REPORT_HYBRIDMETER_ACTIVITY_INSTANCES_DEVIATOR_CONSTANT); // Activity weight. - $sigmapk += $pk; - $sigmapkvk += $pk * $vk; - } - } - if ($n <= 2) { - $m = 0.25; - } - if ($sigmapk != 0) { - $p = $c / ($c + REPORT_HYBRIDMETER_ACTIVITY_VARIETY_DEVIATOR_CONSTANT); // Course weight. - $h = $m * $p * $sigmapkvk / $sigmapk; - } - return round($h, 2); -} - -function digitalisation_level(array $object, array $parameters): float { - $activitydata = data_provider::get_instance()->count_activities_per_type_of_course($object['id']); - return hybridation_calculus("digitalisation_coeffs", $activitydata); -} - -function raw_data(array $object, array $parameters) { - return data_provider::get_instance()->count_activities_per_type_of_course($object['id']); -} - - -function usage_level(array $object, array $parameters): float { - $dataprovider = data_provider::get_instance(); - $configurator = configurator::get_instance(); - $indicator = 0; - $total = 0; - $activitydata = $dataprovider->count_hits_on_activities_per_type( - $object['id'], - $configurator->get_begin_timestamp(), - $configurator->get_end_timestamp() - ); - return hybridation_calculus("usage_coeffs", $activitydata); -} - -function get_category_path(array $object, array $parameters): string { - $cachemanager = cache_manager::get_instance(); - - if ($cachemanager->is_category_path_calculated($object['category_id'])) { - return $cachemanager->get_category_path($object['category_id']); - } - - $categorypath = data_provider::get_instance()->get_category_path($object['category_id']); - - $cachemanager->update_category_path($object['category_id'], $categorypath); - - return $categorypath; -} - -function is_course_active_last_month(array $object, array $parameters): int { - $configurator = configurator::get_instance(); - $dataprovider = data_provider::get_instance(); - - $count = $dataprovider->count_student_single_visitors_on_courses( - [$object['id']], - $configurator->get_begin_timestamp(), - $configurator->get_end_timestamp() - ); - - if ($count >= $configurator->get_data()["active_treshold"]) { - return 1; - } else { - return 0; - } -} - -function active_students (array $object, array $parameters): int { - $configurator = configurator::get_instance(); - return data_provider::get_instance()->count_student_single_visitors_on_courses( - [$object['id']], - $configurator->get_begin_timestamp(), - $configurator->get_end_timestamp() - ); -} - -function nb_registered_students (array $object, array $parameters): int { - return data_provider::get_instance()->count_registered_students_of_course($object['id']); -} -- GitLab From 72f00ec609e9d5862585f274cc3cabdea8da5fcd Mon Sep 17 00:00:00 2001 From: John Tranier <john.tranier@isae-supaero.fr> Date: Wed, 17 Apr 2024 13:07:50 +0200 Subject: [PATCH 17/17] Release 1.2.0 --- CHANGES.md | 6 ++++++ version.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9255fe6..4429275 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,12 @@ _Ce document décrit les modifications du plugin HybridMeter pour chaque version [Site HybridMeter](https://online.isae-supaero.fr/hybridmeter) +## Hybridmeter version 1.2.0 (2024-04-17) +### Chore +- Add inline documentation +- Rewrite indicators computation (introducing explicit types) +- Remove unnecessary code + ## Hybridmeter version 1.1.14 (2024-04-16) ### Chore - Publish source code on GitHub and update the README accordingly diff --git a/version.php b/version.php index cb15d39..eb3760d 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = "report_hybridmeter"; -$plugin->version = 2024041600; +$plugin->version = 2024041700; $plugin->requires = 2018051700; // Moodle 3.5.7 minimum. -$plugin->release = "1.1.14"; +$plugin->release = "1.2.0"; $plugin->maturity = MATURITY_STABLE; -- GitLab