diff --git a/admin/tool/analytics/classes/output/models_list.php b/admin/tool/analytics/classes/output/models_list.php index 63648a985d6..47cd54acd1a 100644 --- a/admin/tool/analytics/classes/output/models_list.php +++ b/admin/tool/analytics/classes/output/models_list.php @@ -198,7 +198,7 @@ class models_list implements \renderable, \templatable { // Get predictions. if (!$onlycli && $modeldata->enabled && !empty($modeldata->timesplitting)) { $urlparams['action'] = 'scheduledanalysis'; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $icon = new \action_menu_link_secondary($url, new \pix_icon('i/notifications', get_string('executescheduledanalysis', 'tool_analytics')), get_string('executescheduledanalysis', 'tool_analytics')); @@ -225,7 +225,7 @@ class models_list implements \renderable, \templatable { $evaluateparams = [$actionid, $trainedonlyexternally, $modeltimesplittingmethods]; $PAGE->requires->js_call_amd('tool_analytics/model', 'selectEvaluationOptions', $evaluateparams); $urlparams['action'] = 'evaluate'; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $icon = new \action_menu_link_secondary($url, new \pix_icon('i/calc', get_string('evaluate', 'tool_analytics')), get_string('evaluate', 'tool_analytics'), ['data-action-id' => $actionid]); $actionsmenu->add($icon); @@ -234,7 +234,7 @@ class models_list implements \renderable, \templatable { // Machine-learning-based models evaluation log. if (!$model->is_static() && $model->get_logs()) { $urlparams['action'] = 'log'; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $icon = new \action_menu_link_secondary($url, new \pix_icon('i/report', get_string('viewlog', 'tool_analytics')), get_string('viewlog', 'tool_analytics')); $actionsmenu->add($icon); @@ -242,7 +242,7 @@ class models_list implements \renderable, \templatable { // Edit model. $urlparams['action'] = 'edit'; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $icon = new \action_menu_link_secondary($url, new \pix_icon('t/edit', get_string('edit')), get_string('edit')); $actionsmenu->add($icon); @@ -259,7 +259,7 @@ class models_list implements \renderable, \templatable { $icontype = 'i/checked'; } $urlparams['action'] = $action; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $icon = new \action_menu_link_secondary($url, new \pix_icon($icontype, $text), $text); $actionsmenu->add($icon); } @@ -272,7 +272,7 @@ class models_list implements \renderable, \templatable { if ($fullysetup || $istrained) { - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); // Clear the previous action param from the URL, we will set it in JS. $url->remove_params('action'); @@ -300,7 +300,7 @@ class models_list implements \renderable, \templatable { $analyser = $model->get_analyser(['notimesplitting' => true]); if (!$analyser instanceof \core_analytics\local\analyser\sitewide) { $urlparams['action'] = 'invalidanalysables'; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $pix = new \pix_icon('i/report', get_string('invalidanalysables', 'tool_analytics')); $icon = new \action_menu_link_secondary($url, $pix, get_string('invalidanalysables', 'tool_analytics')); $actionsmenu->add($icon); @@ -311,7 +311,7 @@ class models_list implements \renderable, \templatable { $actionid = 'clear-' . $model->get_id(); $PAGE->requires->js_call_amd('tool_analytics/model', 'confirmAction', [$actionid, 'clear']); $urlparams['action'] = 'clear'; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $icon = new \action_menu_link_secondary($url, new \pix_icon('e/cleanup_messy_code', get_string('clearpredictions', 'tool_analytics')), get_string('clearpredictions', 'tool_analytics'), ['data-action-id' => $actionid]); @@ -322,7 +322,7 @@ class models_list implements \renderable, \templatable { $actionid = 'delete-' . $model->get_id(); $PAGE->requires->js_call_amd('tool_analytics/model', 'confirmAction', [$actionid, 'delete']); $urlparams['action'] = 'delete'; - $url = new \moodle_url('model.php', $urlparams); + $url = new \moodle_url('/admin/tool/analytics/model.php', $urlparams); $icon = new \action_menu_link_secondary($url, new \pix_icon('t/delete', get_string('delete', 'tool_analytics')), get_string('delete', 'tool_analytics'), ['data-action-id' => $actionid]); diff --git a/analytics/tests/behat/manage_models.feature b/analytics/tests/behat/manage_models.feature new file mode 100644 index 00000000000..8a668c924fd --- /dev/null +++ b/analytics/tests/behat/manage_models.feature @@ -0,0 +1,163 @@ +@core @core_analytics @javascript +Feature: Manage analytics models + In order to manage analytics models + As a manager + I need to create and use a model + + Background: + Given the following config values are set as admin: + | onlycli | 0 | analytics | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | manager1 | Manager | 1 | manager1@example.com | + | student0 | Student | 0 | student0@example.com | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | student3 | Student | 3 | student3@example.com | + | student4 | Student | 4 | student4@example.com | + | student5 | Student | 5 | student5@example.com | + | student6 | Student | 6 | student6@example.com | + And the following "system role assigns" exist: + | user | course | role | + | manager1 | Acceptance test site | manager | + And the following "courses" exist: + | fullname | shortname | category | enddate | startdate | enablecompletion | + | Course 1 | C1 | 0 | ## yesterday ## | ## 2 days ago ## | 1 | + | Course 2 | C2 | 0 | ## yesterday ## | ## 2 days ago ## | 1 | + | Course 3 | C3 | 0 | ## tomorrow ## | ## 2 days ago ## | 1 | + And the following "course enrolments" exist: + | user | course | role | timeend | timestart | + | teacher1 | C1 | editingteacher | ## 1 day ago ## | ## 2 days ago ## | + | student0 | C1 | student | ## 1 day ago ## | ## 2 days ago ## | + | student1 | C1 | student | ## 1 day ago ## | ## 2 days ago ## | + | student2 | C1 | student | ## 1 day ago ## | ## 2 days ago ## | + | teacher1 | C2 | editingteacher | ## 1 day ago ## | ## 2 days ago ## | + | student3 | C2 | student | ## 1 day ago ## | ## 2 days ago ## | + | student4 | C2 | student | ## 1 day ago ## | ## 2 days ago ## | + | teacher1 | C3 | editingteacher | 0 | ## 2 days ago ## | + | manager1 | C3 | manager | 0 | ## 2 days ago ## | + | student5 | C3 | student | 0 | ## 2 days ago ## | + | student6 | C3 | student | 0 | ## 2 days ago ## | + And the following "activities" exist: + | activity | name | intro | course | idnumber | section | completion | completionview | + | assign | assign1 | A1 desc | C1 | assign1 | 0 | 2 | 1 | + | assign | assign2 | A2 desc | C2 | assign2 | 0 | 2 | 1 | + | assign | assign3 | A3 desc | C3 | assign3 | 0 | 2 | 1 | + And the following "analytics model" exist: + | target | indicators | timesplitting | enabled | + | \core_course\analytics\target\course_completion | \core\analytics\indicator\any_write_action,\core\analytics\indicator\read_actions | \core\analytics\time_splitting\single_range | true | + And I log in as "manager1" + And I navigate to "Analytics > Analytics models" in site administration + + Scenario: Create a model + When I click on "New model" "link" + And I click on "Create model" "link" + And I set the field "Enabled" to "Enable" + And I select "__core_course__analytics__target__course_completion" from the "target" singleselect + And I open the autocomplete suggestions list + And I click on "Read actions amount" item in the autocomplete list + And I open the autocomplete suggestions list + And I click on "Any write action in the course" item in the autocomplete list + And I select "__core__analytics__time_splitting__single_range" from the "timesplitting" singleselect + And I press "Save changes" + Then I should see "No predictions available yet" in the "Students at risk of not meeting the course completion conditions" "table_row" + + Scenario: Evaluate a model + Given I am on "Course 1" course homepage + And I navigate to "Course completion" in current page administration + And I expand all fieldsets + And I set the following fields to these values: + | Assignment - assign1 | 1 | + And I click on "Save changes" "button" + And I am on "Course 2" course homepage + And I navigate to "Course completion" in current page administration + And I expand all fieldsets + And I set the following fields to these values: + | Assignment - assign2 | 1 | + And I click on "Save changes" "button" + And I am on "Course 3" course homepage + And I navigate to "Course completion" in current page administration + And I expand all fieldsets + And I set the following fields to these values: + | Assignment - assign3 | 1 | + And I click on "Save changes" "button" + And I am on site homepage + And I navigate to "Analytics > Analytics models" in site administration + And I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Evaluate" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I press "Evaluate" + And I should see "Evaluate model" + And I press "Continue" + # Evaluation log + And I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Evaluation log" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I should see "Configuration" + And I click on "View" "link" + And I should see "Log extra info" + And I click on "Close" "button" + And I click on "Analytics models" "link" + # Execute scheduled analysis + And I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Execute scheduled analysis" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I should see "Training results" + And I press "Continue" + # Check notifications + Then I should see "1" in the "#nav-notification-popover-container [data-region='count-container']" "css_element" + And I open the notification popover + And I click on "View full notification" "link" in the ".popover-region-notifications" "css_element" + And I should see "Students at risk in Course 3 course" + When I am on site homepage + And I navigate to "Analytics > Analytics models" in site administration + # View predictions + When I select "C3" from the "contextid" singleselect + #And I click on "#dropdown-3" "css_element" + And I click on "Actions" "link" in the "Student 6" "table_row" + And I click on "View prediction details" "link" + And I should see "Prediction details" + And I should see "Any write action" + And I should see "Read actions amount" + And I click on "Actions" "link" + And I click on "Acknowledged" "link" + And I click on "Actions" "link" + And I click on "View prediction details" "link" + And I click on "Actions" "link" + And I click on "Not useful" "link" + And I should see "No insights reported" + # Clear predictions + When I am on site homepage + And I navigate to "Analytics > Analytics models" in site administration + And I should see "No insights reported" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Clear predictions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I press "Clear predictions" + Then I should see "No predictions available yet" in the "Students at risk of not meeting the course completion conditions" "table_row" + + Scenario: Edit a model + When I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Edit" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Read actions amount" "text" in the ".form-autocomplete-selection" "css_element" + And I press "Save changes" + And I should not see "Read actions amount" + + Scenario: Disable a model + When I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Disable" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + Then I should see "Disabled model" in the "Students at risk of not meeting the course completion conditions" "table_row" + + Scenario: Export model + When I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Export" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And following "Export" should download between "100" and "500" bytes + + Scenario: Check invalid site elements + When I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Invalid site elements" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + Then I should see "Invalid analysable elements" + + Scenario: Delete model + When I click on "Actions" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Delete" "link" in the "Students at risk of not meeting the course completion conditions" "table_row" + And I click on "Delete" "button" in the "Confirm" "dialogue" + Then I should not see "Students at risk of not meeting the course completion conditions" diff --git a/lib/tests/behat/behat_data_generators.php b/lib/tests/behat/behat_data_generators.php index 699fcc615db..f4634d043f1 100644 --- a/lib/tests/behat/behat_data_generators.php +++ b/lib/tests/behat/behat_data_generators.php @@ -227,6 +227,10 @@ class behat_data_generators extends behat_base { 'datagenerator' => 'customlang', 'required' => array('component', 'stringid', 'value'), ), + 'analytics model' => array ( + 'datagenerator' => 'analytics_model', + 'required' => array('target', 'indicators', 'timesplitting', 'enabled'), + ), ); /** @@ -1085,4 +1089,25 @@ class behat_data_generators extends behat_base { } \core_message\api::mute_conversation($data['userid'], $conversationid); } + + /** + * Transform indicators string into array. + * + * @param array $data + * @return array + */ + protected function preprocess_analytics_model($data) { + $data['indicators'] = explode(',', $data['indicators']); + return $data; + } + + /** + * Creates an analytics model + * + * @param target $data + * @return void + */ + protected function process_analytics_model($data) { + \core_analytics\manager::create_declared_model($data); + } }