forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'analytics-34' of git://github.com/dmonllao/moodle
- Loading branch information
Showing
323 changed files
with
31,317 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Adds settings links to admin tree. | ||
* | ||
* @package core_analytics | ||
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
if ($hassiteconfig) { | ||
$settings = new admin_settingpage('analyticssettings', new lang_string('analyticssettings', 'analytics')); | ||
$ADMIN->add('appearance', $settings); | ||
|
||
if ($ADMIN->fulltree) { | ||
// Select the site prediction's processor. | ||
$predictionprocessors = \core_analytics\manager::get_all_prediction_processors(); | ||
$predictors = array(); | ||
foreach ($predictionprocessors as $fullclassname => $predictor) { | ||
$pluginname = substr($fullclassname, 1, strpos($fullclassname, '\\', 1) - 1); | ||
$predictors[$fullclassname] = new lang_string('pluginname', $pluginname); | ||
} | ||
$settings->add(new \core_analytics\admin_setting_predictor('analytics/predictionsprocessor', | ||
new lang_string('predictionsprocessor', 'analytics'), new lang_string('predictionsprocessor_help', 'analytics'), | ||
'\mlbackend_php\processor', $predictors) | ||
); | ||
|
||
// Log store. | ||
$logmanager = get_log_manager(); | ||
$readers = $logmanager->get_readers('core\log\sql_reader'); | ||
$options = array(); | ||
$defaultreader = null; | ||
foreach ($readers as $plugin => $reader) { | ||
if (!$reader->is_logging()) { | ||
continue; | ||
} | ||
if (!isset($defaultreader)) { | ||
// The top one as default reader. | ||
$defaultreader = $plugin; | ||
} | ||
$options[$plugin] = $reader->get_name(); | ||
} | ||
$settings->add(new admin_setting_configselect('analytics/logstore', | ||
new lang_string('analyticslogstore', 'analytics'), new lang_string('analyticslogstore_help', 'analytics'), | ||
$defaultreader, $options)); | ||
|
||
// Enable/disable time splitting methods. | ||
$alltimesplittings = \core_analytics\manager::get_all_time_splittings(); | ||
|
||
$timesplittingoptions = array(); | ||
$timesplittingdefaults = array('\core\analytics\time_splitting\quarters_accum', | ||
'\core\analytics\time_splitting\quarters', '\core\analytics\time_splitting\no_splitting'); | ||
foreach ($alltimesplittings as $key => $timesplitting) { | ||
$timesplittingoptions[$key] = $timesplitting->get_name(); | ||
} | ||
$settings->add(new admin_setting_configmultiselect('analytics/timesplittings', | ||
new lang_string('enabledtimesplittings', 'analytics'), new lang_string('enabledtimesplittings_help', 'analytics'), | ||
$timesplittingdefaults, $timesplittingoptions) | ||
); | ||
|
||
// Predictions processor output dir. | ||
$defaultmodeloutputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models'; | ||
if (empty(get_config('analytics', 'modeloutputdir')) && !file_exists($defaultmodeloutputdir) && | ||
is_writable($defaultmodeloutputdir)) { | ||
// Automatically create the dir for them so users don't see the invalid value red cross. | ||
mkdir($defaultmodeloutputdir, $CFG->directorypermissions, true); | ||
} | ||
$settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'), | ||
new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir)); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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/>. | ||
|
||
/** | ||
* Shows a dialogue with info about this logs. | ||
* | ||
* @module tool_analytics/log_info | ||
* @class log_info | ||
* @package tool_analytics | ||
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
define(['jquery', 'core/str', 'core/modal_factory', 'core/notification'], function($, str, ModalFactory, Notification) { | ||
|
||
return /** @alias module:tool_analytics/log_info */ { | ||
|
||
/** | ||
* Prepares a modal info for a log's results. | ||
* | ||
* @method loadInfo | ||
* @param {int} id | ||
* @param {string[]} info | ||
*/ | ||
loadInfo: function(id, info) { | ||
|
||
var link = $('[data-model-log-id="' + id + '"]'); | ||
str.get_string('loginfo', 'tool_analytics').then(function(langString) { | ||
|
||
var bodyInfo = $("<ul>"); | ||
info.forEach(function(item) { | ||
bodyInfo.append('<li>' + item + '</li>'); | ||
}); | ||
bodyInfo.append("</ul>"); | ||
|
||
return ModalFactory.create({ | ||
title: langString, | ||
body: bodyInfo.html(), | ||
large: true, | ||
}, link); | ||
|
||
}).catch(Notification.exception); | ||
} | ||
}; | ||
}); |
119 changes: 119 additions & 0 deletions
119
admin/tool/analytics/classes/output/form/edit_model.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Model edit form. | ||
* | ||
* @package tool_analytics | ||
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_analytics\output\form; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot.'/lib/formslib.php'); | ||
|
||
/** | ||
* Model edit form. | ||
* | ||
* @package tool_analytics | ||
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class edit_model extends \moodleform { | ||
|
||
/** | ||
* Form definition | ||
*/ | ||
public function definition() { | ||
global $OUTPUT; | ||
|
||
$mform = $this->_form; | ||
|
||
if ($this->_customdata['model']->get_model_obj()->trained == 1) { | ||
$message = get_string('edittrainedwarning', 'tool_analytics'); | ||
$mform->addElement('html', $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING)); | ||
} | ||
|
||
$mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'tool_analytics')); | ||
|
||
$indicators = array(); | ||
foreach ($this->_customdata['indicators'] as $classname => $indicator) { | ||
$optionname = \tool_analytics\output\helper::class_to_option($classname); | ||
$indicators[$optionname] = $indicator->get_name(); | ||
} | ||
$options = array( | ||
'multiple' => true | ||
); | ||
$mform->addElement('autocomplete', 'indicators', get_string('indicators', 'tool_analytics'), $indicators, $options); | ||
$mform->setType('indicators', PARAM_ALPHANUMEXT); | ||
|
||
$timesplittings = array('' => ''); | ||
foreach ($this->_customdata['timesplittings'] as $classname => $timesplitting) { | ||
$optionname = \tool_analytics\output\helper::class_to_option($classname); | ||
$timesplittings[$optionname] = $timesplitting->get_name(); | ||
} | ||
|
||
$mform->addElement('select', 'timesplitting', get_string('timesplittingmethod', 'analytics'), $timesplittings); | ||
$mform->addHelpButton('timesplitting', 'timesplittingmethod', 'analytics'); | ||
|
||
$mform->addElement('hidden', 'id', $this->_customdata['id']); | ||
$mform->setType('id', PARAM_INT); | ||
|
||
$mform->addElement('hidden', 'action', 'edit'); | ||
$mform->setType('action', PARAM_ALPHANUMEXT); | ||
|
||
$this->add_action_buttons(); | ||
} | ||
|
||
/** | ||
* Form validation | ||
* | ||
* @param array $data data from the form. | ||
* @param array $files files uploaded. | ||
* | ||
* @return array of errors. | ||
*/ | ||
public function validation($data, $files) { | ||
$errors = parent::validation($data, $files); | ||
|
||
if (!empty($data['timesplitting'])) { | ||
$realtimesplitting = \tool_analytics\output\helper::option_to_class($data['timesplitting']); | ||
if (\core_analytics\manager::is_valid($realtimesplitting, '\core_analytics\local\time_splitting\base') === false) { | ||
$errors['timesplitting'] = get_string('errorinvalidtimesplitting', 'analytics'); | ||
} | ||
} | ||
|
||
if (empty($data['indicators'])) { | ||
$errors['indicators'] = get_string('errornoindicators', 'analytics'); | ||
} else { | ||
foreach ($data['indicators'] as $indicator) { | ||
$realindicatorname = \tool_analytics\output\helper::option_to_class($indicator); | ||
if (\core_analytics\manager::is_valid($realindicatorname, '\core_analytics\local\indicator\base') === false) { | ||
$errors['indicators'] = get_string('errorinvalidindicator', 'analytics', $realindicatorname); | ||
} | ||
} | ||
} | ||
|
||
if (!empty($data['enabled']) && empty($data['timesplitting'])) { | ||
$errors['enabled'] = get_string('errorcantenablenotimesplitting', 'tool_analytics'); | ||
} | ||
|
||
return $errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Typical crappy helper class with tiny functions. | ||
* | ||
* @package tool_analytics | ||
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_analytics\output; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Helper class with general purpose tiny functions. | ||
* | ||
* @package tool_analytics | ||
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class helper { | ||
|
||
/** | ||
* Converts a class full name to a select option key | ||
* | ||
* @param string $class | ||
* @return string | ||
*/ | ||
public static function class_to_option($class) { | ||
// Form field is PARAM_ALPHANUMEXT and we are sending fully qualified class names | ||
// as option names, but replacing the backslash for a string that is really unlikely | ||
// to ever be part of a class name. | ||
return str_replace('\\', '2015102400ouuu', $class); | ||
} | ||
|
||
/** | ||
* option_to_class | ||
* | ||
* @param string $option | ||
* @return string | ||
*/ | ||
public static function option_to_class($option) { | ||
// Really unlikely but yeah, I'm a bad booyyy. | ||
return str_replace('2015102400ouuu', '\\', $option); | ||
} | ||
} |
Oops, something went wrong.