Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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   * Test target.
  19   *
  20   * @package   core_analytics
  21   * @copyright 2017 David MonllaĆ³ {@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  /**
  28   * Test target.
  29   *
  30   * @package   core_analytics
  31   * @copyright 2017 David MonllaĆ³ {@link http://www.davidmonllao.com}
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class test_target_shortname extends \core_analytics\local\target\binary {
  35  
  36      /**
  37       * Returns a lang_string object representing the name for the indicator.
  38       *
  39       * Used as column identificator.
  40       *
  41       * If there is a corresponding '_help' string this will be shown as well.
  42       *
  43       * @return \lang_string
  44       */
  45      public static function get_name() : \lang_string {
  46          // Using a string that exists and contains a corresponding '_help' string.
  47          return new \lang_string('allowstealthmodules');
  48      }
  49  
  50      /**
  51       * predictions
  52       *
  53       * @var array
  54       */
  55      protected $predictions = array();
  56  
  57      /**
  58       * get_analyser_class
  59       *
  60       * @return string
  61       */
  62      public function get_analyser_class() {
  63          return '\core\analytics\analyser\site_courses';
  64      }
  65  
  66      /**
  67       * classes_description
  68       *
  69       * @return string[]
  70       */
  71      public static function classes_description() {
  72          return array(
  73              'Course fullname first char is A',
  74              'Course fullname first char is not A'
  75          );
  76      }
  77  
  78      /**
  79       * We don't want to discard results.
  80       * @return float
  81       */
  82      protected function min_prediction_score() {
  83          return null;
  84      }
  85  
  86      /**
  87       * We don't want to discard results.
  88       * @return array
  89       */
  90      public function ignored_predicted_classes() {
  91          return array();
  92      }
  93  
  94      /**
  95       * Only past stuff.
  96       *
  97       * @param  \core_analytics\local\time_splitting\base $timesplitting
  98       * @return bool
  99       */
 100      public function can_use_timesplitting(\core_analytics\local\time_splitting\base $timesplitting): bool {
 101          return ($timesplitting instanceof \core_analytics\local\time_splitting\before_now);
 102      }
 103  
 104      /**
 105       * is_valid_analysable
 106       *
 107       * @param \core_analytics\analysable $analysable
 108       * @param bool $fortraining
 109       * @return bool
 110       */
 111      public function is_valid_analysable(\core_analytics\analysable $analysable, $fortraining = true) {
 112          // This is testing, let's make things easy.
 113          return true;
 114      }
 115  
 116      /**
 117       * is_valid_sample
 118       *
 119       * @param int $sampleid
 120       * @param \core_analytics\analysable $analysable
 121       * @param bool $fortraining
 122       * @return bool
 123       */
 124      public function is_valid_sample($sampleid, \core_analytics\analysable $analysable, $fortraining = true) {
 125          // We skip not-visible courses during training as a way to emulate the training data / prediction data difference.
 126          // In normal circumstances is_valid_sample will return false when they receive a sample that can not be
 127          // processed.
 128          if (!$fortraining) {
 129              return true;
 130          }
 131  
 132          $sample = $this->retrieve('course', $sampleid);
 133          if ($sample->visible == 0) {
 134              return false;
 135          }
 136          return true;
 137      }
 138  
 139      /**
 140       * calculate_sample
 141       *
 142       * @param int $sampleid
 143       * @param \core_analytics\analysable $analysable
 144       * @param int $starttime
 145       * @param int $endtime
 146       * @return float
 147       */
 148      protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {
 149  
 150          $sample = $this->retrieve('course', $sampleid);
 151  
 152          $firstchar = substr($sample->shortname, 0, 1);
 153          if ($firstchar === 'a') {
 154              return 1;
 155          } else {
 156              return 0;
 157          }
 158      }
 159  }