Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 39 and 400]

Abstract base target.

Copyright: 2016 David Monllao {@link http://www.davidmonllao.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 459 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: base  - X-Ref

Abstract base target.

uses_insights()   X-Ref
Is this target generating insights?

Defaults to true.

return: bool

link_insights_report()   X-Ref
Should the insights of this model be linked from reports?

return: bool

based_on_assumptions()   X-Ref
Based on facts (processed by machine learning backends) by default.

return: bool

always_update_analysis_time()   X-Ref
Update the last analysis time on analysable processed or always.

If you overwrite this method to return false the last analysis time
will only be recorded in DB when the element successfully analysed. You can
safely return false for lightweight targets.

return: bool

prediction_actions(\core_analytics\prediction $prediction, $includedetailsaction = false,$isinsightuser = false)   X-Ref
Suggested actions for a user.

return: \core_analytics\prediction_action[]
param: \core_analytics\prediction $prediction
param: bool $includedetailsaction
param: bool $isinsightuser                       Force all the available actions to be returned as it the user who

bulk_actions(array $predictions)   X-Ref
Suggested bulk actions for a user.

return: \core_analytics\bulk_action[]                 The list of bulk actions.
param: \core_analytics\prediction[]     $predictions List of predictions suitable for the bulk actions to use.

add_bulk_actions_js()   X-Ref
Adds the JS required to run the bulk actions.


get_view_details_text()   X-Ref
Returns the view details link text.

return: string

prediction_callback($modelid, $sampleid, $rangeindex, \context $samplecontext, $prediction, $predictionscore)   X-Ref
Callback to execute once a prediction has been returned from the predictions processor.

Note that the analytics_predictions db record is not yet inserted.

return: void
param: int $modelid
param: int $sampleid
param: int $rangeindex
param: \context $samplecontext
param: float|int $prediction
param: float $predictionscore

generate_insight_notifications($modelid, $samplecontexts, array $predictions = [])   X-Ref
Generates insights notifications

return: void
param: int $modelid
param: \context[] $samplecontexts
param: \core_analytics\prediction[] $predictions

get_insights_users(\context $context)   X-Ref
Returns the list of users that will receive insights notifications.

Feel free to overwrite if you need to but keep in mind that moodle/analytics:listinsights
or moodle/analytics:listowninsights capability is required to access the list of insights.

return: array
param: \context $context

get_insight_context_url($modelid, $context)   X-Ref
URL to the insight.

return: \moodle_url
param: int $modelid
param: \context $context

get_insight_subject(int $modelid, \context $context)   X-Ref
The insight notification subject.

This is just a default message, you should overwrite it for a custom insight message.

return: string
param: int $modelid
param: \context $context

get_insight_body(\context $context, string $contextname, \stdClass $user, \moodle_url $insighturl)   X-Ref
Returns the body message for an insight with multiple predictions.

This default method is executed when the analysable used by the model generates multiple insight
for each analysable (one_sample_per_analysable === false)

return: string[]                     The plain text message and the HTML message
param: \context     $context
param: string       $contextname
param: \stdClass    $user
param: \moodle_url  $insighturl

get_insight_body_for_prediction(\context $context, \stdClass $user, \core_analytics\prediction $prediction,array &$actions)   X-Ref
Returns the body message for an insight for a single prediction.

This default method is executed when the analysable used by the model generates one insight
for each analysable (one_sample_per_analysable === true)

return: array                                                Plain text msg, HTML message and the main URL for this
param: \context                             $context
param: \stdClass                            $user
param: \core_analytics\prediction           $prediction
param: \core_analytics\action[]             $actions        Passed by reference to remove duplicate links to actions.

instance()   X-Ref
Returns an instance of the child class.

Useful to reset cached data.

return: \core_analytics\base\target

min_prediction_score()   X-Ref
Defines a boundary to ignore predictions below the specified prediction score.

Value should go from 0 to 1.

return: float

triggers_callback($predictedvalue, $predictionscore)   X-Ref
This method determines if a prediction is interesing for the model or not.

return: bool
param: mixed $predictedvalue
param: float $predictionscore

calculate($sampleids, \core_analytics\analysable $analysable, $starttime = false, $endtime = false)   X-Ref
Calculates the target.

Returns an array of values which size matches $sampleids size.

Rows with null values will be skipped as invalid by time splitting methods.

return: array The format to follow is [userid] = scalar|null
param: array $sampleids
param: \core_analytics\analysable $analysable
param: int $starttime
param: int $endtime

filter_out_invalid_samples(&$sampleids, \core_analytics\analysable $analysable, $fortraining = true)   X-Ref
Filters out invalid samples for training.

return: void
param: int[] $sampleids
param: \core_analytics\analysable $analysable
param: bool $fortraining