Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Adds settings links to admin tree.
19
 *
20
 * @package   core_analytics
21
 * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
if ($hassiteconfig && \core_analytics\manager::is_analytics_enabled()) {
28
 
29
    $settings = new admin_settingpage('analyticssite', new lang_string('analyticssiteinfo', 'analytics'));
30
    $ADMIN->add('analytics', $settings);
31
 
32
    if ($ADMIN->fulltree) {
33
        $modeinstructions = [
34
            'facetoface' => get_string('modeinstructionfacetoface', 'analytics'),
35
            'blendedhybrid' => get_string('modeinstructionblendedhybrid', 'analytics'),
36
            'fullyonline' => get_string('modeinstructionfullyonline', 'analytics'),
37
        ];
38
        $settings->add(new admin_setting_configmultiselect('analytics/modeinstruction', get_string('modeinstruction', 'analytics'),
39
            '', [], $modeinstructions));
40
 
41
        $settings->add(new admin_setting_configtext_with_maxlength('analytics/percentonline',
42
            get_string('percentonline', 'analytics'),
43
            get_string('percentonline_help', 'analytics'), '', PARAM_INT, 3, 3));
44
 
45
        $typeinstitutions = [
46
            'typeinstitutionacademic' => get_string('typeinstitutionacademic', 'analytics'),
47
            'typeinstitutiontraining' => get_string('typeinstitutiontraining', 'analytics'),
48
            'typeinstitutionngo' => get_string('typeinstitutionngo', 'analytics'),
49
        ];
50
        $settings->add(new admin_setting_configmultiselect('analytics/typeinstitution', get_string('typeinstitution', 'analytics'),
51
            '', [], $typeinstitutions));
52
 
53
        $levelinstitutions = [
54
            'levelinstitutionisced0' => get_string('levelinstitutionisced0', 'analytics'),
55
            'levelinstitutionisced1' => get_string('levelinstitutionisced1', 'analytics'),
56
            'levelinstitutionisced2' => get_string('levelinstitutionisced2', 'analytics'),
57
            'levelinstitutionisced3' => get_string('levelinstitutionisced3', 'analytics'),
58
            'levelinstitutionisced4' => get_string('levelinstitutionisced4', 'analytics'),
59
            'levelinstitutionisced5' => get_string('levelinstitutionisced5', 'analytics'),
60
            'levelinstitutionisced6' => get_string('levelinstitutionisced6', 'analytics'),
61
            'levelinstitutionisced7' => get_string('levelinstitutionisced7', 'analytics'),
62
            'levelinstitutionisced8' => get_string('levelinstitutionisced8', 'analytics'),
63
        ];
64
        $settings->add(new admin_setting_configmultiselect('analytics/levelinstitution',
65
            get_string('levelinstitution', 'analytics'), '', [], $levelinstitutions));
66
    }
67
 
68
    $settings = new admin_settingpage('analyticssettings', new lang_string('analyticssettings', 'analytics'));
69
    $ADMIN->add('analytics', $settings);
70
 
71
    if ($ADMIN->fulltree) {
72
        // Select the site prediction's processor.
73
        $predictionprocessors = \core_analytics\manager::get_all_prediction_processors();
1441 ariadna 74
        $predictors = [];
1 efrain 75
        foreach ($predictionprocessors as $fullclassname => $predictor) {
76
            $pluginname = substr($fullclassname, 1, strpos($fullclassname, '\\', 1) - 1);
77
            $predictors[$fullclassname] = new lang_string('pluginname', $pluginname);
78
        }
1441 ariadna 79
        $settings->add(
80
            new \core_analytics\admin_setting_predictor(
81
                'analytics/predictionsprocessor',
82
                new lang_string('defaultpredictionsprocessor', 'analytics'),
83
                new lang_string('predictionsprocessor_help', 'analytics'),
84
                \core_analytics\manager::default_mlbackend(),
85
                $predictors,
86
            )
1 efrain 87
        );
1441 ariadna 88
        // Warn if current processor is not configured.
89
        // We are avoiding doing this check in write_config because it is likely the default
90
        // mlbackend_python plugin is not configured and will output warnings during install.
91
        $currentprocessor = get_config('analytics', 'predictionsprocessor');
92
        if (!empty($currentprocessor)) {
93
            $currentprocessor = new $currentprocessor;
94
            $currentprocessorisready = $currentprocessor->is_ready();
95
            if ($currentprocessorisready !== true) {
96
                $settings->add(new admin_setting_description(
97
                    'processornotready',
98
                    '',
99
                    html_writer::tag('div', $currentprocessorisready, ['class' => 'alert alert-danger'])
100
                ));
101
            }
102
        }
1 efrain 103
 
104
        // Log store.
105
        $logmanager = get_log_manager();
106
        $readers = $logmanager->get_readers('core\log\sql_reader');
107
        $options = array();
108
        $defaultreader = null;
109
        foreach ($readers as $plugin => $reader) {
110
            if (!$reader->is_logging()) {
111
                continue;
112
            }
113
            if (!isset($defaultreader)) {
114
                // The top one as default reader.
115
                $defaultreader = $plugin;
116
            }
117
            $options[$plugin] = $reader->get_name();
118
        }
119
 
120
        if (empty($defaultreader)) {
121
            // We fall here during initial site installation because log stores are not
122
            // enabled until admin/tool/log/db/install.php is executed and get_readers
123
            // return nothing.
124
 
125
            if ($enabledlogstores = get_config('tool_log', 'enabled_stores')) {
126
                $enabledlogstores = explode(',', $enabledlogstores);
127
                $defaultreader = reset($enabledlogstores);
128
 
129
                // No need to set the correct name, just the value, this will not be displayed.
130
                $options[$defaultreader] = $defaultreader;
131
            }
132
        }
133
        $settings->add(new admin_setting_configselect('analytics/logstore',
134
            new lang_string('analyticslogstore', 'analytics'), new lang_string('analyticslogstore_help', 'analytics'),
135
            $defaultreader, $options));
136
 
137
        // Enable/disable time splitting methods.
138
        $alltimesplittings = \core_analytics\manager::get_time_splitting_methods_for_evaluation(true);
139
 
140
        $timesplittingoptions = array();
141
        $timesplittingdefaults = array('\core\analytics\time_splitting\quarters_accum',
142
            '\core\analytics\time_splitting\quarters', '\core\analytics\time_splitting\single_range');
143
        foreach ($alltimesplittings as $key => $timesplitting) {
144
            $timesplittingoptions[$key] = $timesplitting->get_name();
145
        }
146
        $settings->add(new admin_setting_configmultiselect('analytics/defaulttimesplittingsevaluation',
147
            new lang_string('defaulttimesplittingmethods', 'analytics'),
148
            new lang_string('defaulttimesplittingmethods_help', 'analytics'),
149
            $timesplittingdefaults, $timesplittingoptions)
150
        );
151
 
152
        // Predictions processor output dir - specify default in setting description (used if left blank).
153
        $defaultmodeloutputdir = \core_analytics\model::default_output_dir();
154
        $settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
155
            new lang_string('modeloutputdirwithdefaultinfo', 'analytics', $defaultmodeloutputdir), ''));
156
 
157
        // Disable web interface evaluation and get predictions.
158
        $settings->add(new admin_setting_configcheckbox('analytics/onlycli', new lang_string('onlycli', 'analytics'),
159
            new lang_string('onlycliinfo', 'analytics'), 1));
160
 
161
        // Training and prediction time limit per model.
162
        $settings->add(new admin_setting_configduration('analytics/modeltimelimit', new lang_string('modeltimelimit', 'analytics'),
163
            new lang_string('modeltimelimitinfo', 'analytics'), 20 * MINSECS));
164
 
165
        $options = array(
166
 
167
            1000 => new lang_string('numdays', '', 1000),
168
            365  => new lang_string('numdays', '', 365),
169
            180  => new lang_string('numdays', '', 180),
170
            150  => new lang_string('numdays', '', 150),
171
            120  => new lang_string('numdays', '', 120),
172
            90   => new lang_string('numdays', '', 90),
173
            60   => new lang_string('numdays', '', 60),
174
            35   => new lang_string('numdays', '', 35));
175
        $settings->add(new admin_setting_configselect('analytics/calclifetime',
176
            new lang_string('calclifetime', 'analytics'),
177
            new lang_string('configlcalclifetime', 'analytics'), 35, $options));
178
 
179
 
180
    }
181
}