From 40fcb365c3341470790c11bc2b2f45affe4b851b Mon Sep 17 00:00:00 2001 From: David Monllao Date: Tue, 23 May 2017 17:43:46 +0800 Subject: [PATCH] MDL-58859 analytics: Subsystem and API db/ requirements added Part of MDL-57791 epic. --- lib/classes/component.php | 2 ++ lib/classes/plugin_manager.php | 10 ++++-- lib/classes/plugininfo/mlbackend.php | 54 ++++++++++++++++++++++++++++ lib/db/access.php | 18 ++++++++++ lib/db/caches.php | 9 +++++ lib/db/messages.php | 5 +++ 6 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 lib/classes/plugininfo/mlbackend.php diff --git a/lib/classes/component.php b/lib/classes/component.php index 009e8a34b0840..b4eee454e696f 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -415,6 +415,7 @@ protected static function fetch_subsystems() { $info = array( 'access' => null, 'admin' => $CFG->dirroot.'/'.$CFG->admin, + 'analytics' => $CFG->dirroot . '/analytics', 'antivirus' => $CFG->dirroot . '/lib/antivirus', 'auth' => $CFG->dirroot.'/auth', 'availability' => $CFG->dirroot . '/availability', @@ -515,6 +516,7 @@ protected static function fetch_plugintypes() { 'gradeimport' => $CFG->dirroot.'/grade/import', 'gradereport' => $CFG->dirroot.'/grade/report', 'gradingform' => $CFG->dirroot.'/grade/grading/form', + 'mlbackend' => $CFG->dirroot.'/lib/mlbackend', 'mnetservice' => $CFG->dirroot.'/mnet/service', 'webservice' => $CFG->dirroot.'/webservice', 'repository' => $CFG->dirroot.'/repository', diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index dc8a6c8513ea0..38998fb095d61 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1807,6 +1807,10 @@ public static function standard_plugins_list($type) { 'memberships', 'profile', 'toolproxy', 'toolsettings' ), + 'mlbackend' => array( + 'php', 'python' + ), + 'media' => array( 'html5audio', 'html5video', 'swf', 'videojs', 'vimeo', 'youtube' ), @@ -1868,7 +1872,7 @@ public static function standard_plugins_list($type) { 'report' => array( 'backups', 'competency', 'completion', 'configlog', 'courseoverview', 'eventlist', - 'log', 'loglive', 'outline', 'participation', 'progress', 'questioninstances', + 'insights', 'log', 'loglive', 'outline', 'participation', 'progress', 'questioninstances', 'security', 'stats', 'performance', 'usersessions' ), @@ -1902,8 +1906,8 @@ public static function standard_plugins_list($type) { 'tool' => array( 'assignmentupgrade', 'availabilityconditions', 'behat', 'capability', 'cohortroles', 'customlang', 'dbtransfer', 'filetypes', 'generator', 'health', 'innodb', 'installaddon', - 'langimport', 'log', 'lp', 'lpimportcsv', 'lpmigrate', 'messageinbound', 'mobile', 'multilangupgrade', 'monitor', - 'oauth2', 'phpunit', 'profiling', 'recyclebin', 'replace', 'spamcleaner', 'task', 'templatelibrary', + 'langimport', 'log', 'lp', 'lpimportcsv', 'lpmigrate', 'messageinbound', 'mobile', 'models', 'multilangupgrade', + 'monitor', 'oauth2', 'phpunit', 'profiling', 'recyclebin', 'replace', 'spamcleaner', 'task', 'templatelibrary', 'unittest', 'uploadcourse', 'uploaduser', 'unsuproles', 'usertours', 'xmldb' ), diff --git a/lib/classes/plugininfo/mlbackend.php b/lib/classes/plugininfo/mlbackend.php new file mode 100644 index 0000000000000..1e1d0235fdc7d --- /dev/null +++ b/lib/classes/plugininfo/mlbackend.php @@ -0,0 +1,54 @@ +. + +/** + * Defines classes used for plugin info. + * + * @package core + * @copyright 2017 David Monllao + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace core\plugininfo; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Class for analytics machine learning backend plugins + * + * @package core + * @copyright 2017 David Monllao + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mlbackend extends base { + + /** + * Is uninstall allowed or not. + * + * @return bool + */ + public function is_uninstall_allowed() { + return true; + } + + /** + * Returns the node name used in admin settings menu for this plugin settings (if applicable). + * + * @return null|string node name or null if plugin does not create settings node (default) + */ + public function get_settings_section_name() { + return 'mlbackendsetting' . $this->name; + } +} diff --git a/lib/db/access.php b/lib/db/access.php index f8efdb9b819bc..808d0b9c1eaa6 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -2305,6 +2305,24 @@ 'manager' => CAP_ALLOW ), ), + 'moodle/analytics:listinsights' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ), + 'moodle/analytics:managemodels' => array( + 'riskbitmask' => RISK_CONFIG, + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'manager' => CAP_ALLOW + ), + ), 'moodle/competency:templateview' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_COURSECAT, diff --git a/lib/db/caches.php b/lib/db/caches.php index a63ff7e11d69f..93a1fa17cc95d 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -312,6 +312,15 @@ ), ), + // Caches analytic models that have already predicted stuff. + 'modelswithpredictions' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'staticacceleration' => true, + 'staticaccelerationsize' => 1 + ), + // Caches message processors. 'message_processors_enabled' => array( 'mode' => cache_store::MODE_APPLICATION, diff --git a/lib/db/messages.php b/lib/db/messages.php index d9aa3739ca14e..68ac95f77a016 100644 --- a/lib/db/messages.php +++ b/lib/db/messages.php @@ -101,4 +101,9 @@ // A comment was left on a user competency. 'competencyusercompcomment' => array(), + + // User insights. + 'insights' => array ( + 'capability' => 'moodle/analytics:listinsights' + ) );