Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

Analytics basic actions manager.

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

Defines 1 class


Class: manager  - X-Ref

Analytics basic actions manager.

check_can_manage_models()   X-Ref
Checks that the user can manage models

return: void

check_can_list_insights(\context $context, bool $return = false)   X-Ref
Checks that the user can list that context insights

param: \context $context
param: bool $return The method returns a bool if true.
return: void

is_analytics_enabled()   X-Ref
Is analytics enabled globally?

return bool

get_all_models($enabled = false, $trained = false, $predictioncontext = false)   X-Ref
Returns all system models that match the provided filters.

param: bool $enabled
param: bool $trained
param: \context|false $predictioncontext
return: \core_analytics\model[]

get_predictions_processor($predictionclass = false, $checkisready = true)   X-Ref
Returns the provided predictions processor class.

param: false|string $predictionclass Returns the system default processor if false
param: bool $checkisready
return: \core_analytics\predictor

get_all_prediction_processors()   X-Ref
Return all system predictions processors.

return: \core_analytics\predictor[]

reset_prediction_processors()   X-Ref
Resets the cached prediction processors.

return: null

get_predictions_processor_name(\core_analytics\predictor $predictionsprocessor)   X-Ref
Returns the name of the provided predictions processor.

param: \core_analytics\predictor $predictionsprocessor
return: string

is_mlbackend_used($plugin)   X-Ref
Whether the provided plugin is used by any model.

param: string $plugin
return: bool

get_all_time_splittings()   X-Ref
Get all available time splitting methods.

return: \core_analytics\local\time_splitting\base[]

get_enabled_time_splitting_methods()   X-Ref
Returns the enabled time splitting methods.

return: \core_analytics\local\time_splitting\base[]

get_time_splitting_methods_for_evaluation(bool $all = false)   X-Ref
Returns the time-splitting methods for model evaluation.

param: bool $all Return all the time-splitting methods that can potentially be used for evaluation or the default ones.
return: \core_analytics\local\time_splitting\base[]

get_time_splitting($fullclassname)   X-Ref
Returns a time splitting method by its classname.

param: string $fullclassname
return: \core_analytics\local\time_splitting\base|false False if it is not valid.

get_all_targets()   X-Ref
Return all targets in the system.

return: \core_analytics\local\target\base[]

get_all_indicators()   X-Ref
Return all system indicators.

return: \core_analytics\local\indicator\base[]

get_target($fullclassname)   X-Ref
Returns the specified target

param: mixed $fullclassname
return: \core_analytics\local\target\base|false False if it is not valid

get_indicator($fullclassname)   X-Ref
Returns an instance of the provided indicator.

param: string $fullclassname
return: \core_analytics\local\indicator\base|false False if it is not valid.

is_valid($fullclassname, $baseclass)   X-Ref
Returns whether a time splitting method is valid or not.

param: string $fullclassname
param: string $baseclass
return: bool

get_analytics_logstore()   X-Ref
Returns the logstore used for analytics.

return: \core\log\sql_reader|false False if no log stores are enabled.

get_indicator_calculations($analysable, $starttime, $endtime, $samplesorigin)   X-Ref
Returns this analysable calculations during the provided period.

param: \core_analytics\analysable $analysable
param: int $starttime
param: int $endtime
param: string $samplesorigin The samples origin as sampleid is not unique across models.
return: array

get_models_with_insights(\context $context)   X-Ref
Returns the models with insights at the provided context.

Note that this method is used for display purposes. It filters out models whose insights
are not linked from the reports page.

param: \context $context
return: \core_analytics\model[]

cached_models_with_insights(\context $context, int $newmodelid = null)   X-Ref
Returns the models that generated insights in the provided context. It can also be used to add new models to the context.

Note that if you use this function with $newmodelid is the caller responsibility to ensure that the
provided model id generated insights for the provided context.

param: \context $context
param: int|null $newmodelid A new model to add to the list of models with insights in the provided context.
return: int[]

get_prediction($predictionid, $requirelogin = false)   X-Ref
Returns a prediction

param: int $predictionid
param: bool $requirelogin
return: array array($model, $prediction, $context)

add_builtin_models()   X-Ref
Used to be used to add models included with the Moodle core.

return: void

cleanup()   X-Ref
Cleans up analytics db tables that do not directly depend on analysables that may have been deleted.


default_mlbackend()   X-Ref
Default system backend.

return: string

get_analytics_classes($element)   X-Ref
Returns the provided element classes in the site.

param: string $element
return: string[] Array keys are the FQCN and the values the class path.

update_default_models_for_component(string $componentname)   X-Ref
Check that all the models declared by the component are up to date.

This is intended to be called during the installation / upgrade to automatically create missing models.

param: string $componentname The name of the component to load models for.
return: array \core_analytics\model[] List of actually created models.

load_default_models_for_component(string $componentname)   X-Ref
Return the list of models declared by the given component.

param: string $componentname The name of the component to load models for.
return: array The $models description array.

load_default_models_for_all_components()   X-Ref
Return the list of all the models declared anywhere in this Moodle installation.

Models defined by the core and core subsystems come first, followed by those provided by plugins.

return: array indexed by the frankenstyle component

validate_models_declaration(array $models)   X-Ref
Validate the declaration of prediction models according the syntax expected in the component's db folder.

The expected structure looks like this:

[
[
'target' => '\fully\qualified\name\of\the\target\class',
'indicators' => [
'\fully\qualified\name\of\the\first\indicator',
'\fully\qualified\name\of\the\second\indicator',
],
'timesplitting' => '\optional\name\of\the\time_splitting\class',
'enabled' => true,
],
];

param: array $models List of declared models.

create_declared_model(array $definition)   X-Ref
Create the defined model.

param: array $definition See {@link self::validate_models_declaration()} for the syntax.
return: \core_analytics\model

model_declaration_identifier(array $model)   X-Ref
Returns a string uniquely representing the given model declaration.

param: array $model Model declaration
return: string complying with PARAM_ALPHANUM rules and starting with an 'id' prefix

get_declared_target_and_indicators_instances(array $definition)   X-Ref
Given a model definition, return actual target and indicators instances.

param: array $definition See {@link self::validate_models_declaration()} for the syntax.
return: array [0] => target instance, [1] => array of indicators instances

get_potential_context_restrictions(?array $contextlevels = null, string $query = null)   X-Ref
Return the context restrictions that can be applied to the provided context levels.

param: array|null $contextlevels The list of context levels provided by the analyser. Null if all of them.
param: string|null $query
return: array Associative array with contextid as key and the short version of the context name as value.