Skip to content

Commit

Permalink
merge code style and docu fixes from main and up version
Browse files Browse the repository at this point in the history
  • Loading branch information
LiFaytheGoblin committed Feb 5, 2024
2 parents c0f91cb + 61bd563 commit 0769ee1
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ Fernsel, L. (2024) Let's audit Learning Analytics [Moodle Plugin]. Available at:
author = {Linda Fernsel},
title={Let’s audit Learning Analytics [Moodle Plugin]},
url={https://github.com/LiFaytheGoblin/moodle-tool_lala/},
version = {4.0.0},
date = {2024-01-22},
version = {4.0.1},
date = {2024-02-05},
}
```

Expand Down
6 changes: 5 additions & 1 deletion classes/dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function get_file_type(): string {
}

/**
* Restore the data for a model version to the cache from the stored CSV files.
*
* @param array $options
* @return void
*/
Expand All @@ -128,7 +130,9 @@ public function restore_raw_data(array $options): void {
$this->data = dataset_helper::build_from_csv($filehandle, $options['analysisintervalkey']);
}

/** Validate the evidence's options.
/**
* Validate the evidence's options.
*
* @param array $options
*/
public function validate_restore_options(array $options) : void {
Expand Down
23 changes: 19 additions & 4 deletions classes/dataset_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ public static function replace_rows_in_dataset(array $dataset, array $newrows) :
* @return array[]
*/
public static function merge(array $dataseta, array $datasetb) : array {
if (count($dataseta) < 1) return $datasetb;
if (count($datasetb) < 1) return $dataseta;
if (count($dataseta) < 1) {
return $datasetb;
}
if (count($datasetb) < 1) {
return $dataseta;
}

$analysisintervalkeya = self::get_analysisintervalkey($dataseta);
$analysisintervalkeyb = self::get_analysisintervalkey($datasetb);
Expand All @@ -211,8 +215,12 @@ public static function merge(array $dataseta, array $datasetb) : array {
* @return array
*/
public static function diff(array $dataseta, array $datasetb) : array {
if (count($dataseta) < 1) return $datasetb;
if (count($datasetb) < 1) return $dataseta;
if (count($dataseta) < 1) {
return $datasetb;
}
if (count($datasetb) < 1) {
return $dataseta;
}

$sampleidsb = self::get_sampleids_used_in_dataset($datasetb);
$rowsa = self::get_rows($dataseta);
Expand Down Expand Up @@ -362,6 +370,13 @@ public static function validate(array $dataset) : void {
}
}

/**
* Transform a dataset (a two dimensional array) into a string which can be
* stored as a CSV. Elements at id '0' are treated as the header.
*
* @param array $dataset
* @return string
*/
public static function serialize(array $dataset) : string {
$str = '';
$columns = null;
Expand Down
10 changes: 7 additions & 3 deletions classes/evidence.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,20 @@ public function set_raw_data(mixed $data): void {
*
* @param array $options
*/
public abstract function restore_raw_data(array $options): void;
abstract public function restore_raw_data(array $options): void;

/**
* Validates the $options array passed to restore_raw_data.
*
* @param array $options
*/
public abstract function validate_restore_options(array $options): void;

abstract public function validate_restore_options(array $options): void;

/**
* Return the file that contains the evidence data.
*
* @return mixed
*/
public function get_file() {
if (!$this->serializedfilelocation) {
throw new LogicException('No serialized file available to restore data from.');
Expand Down
14 changes: 12 additions & 2 deletions classes/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ protected function get_file_type(): string {
}

/**
* @param array $options
* Restore the model from the stored .ser file.
*
* @param array $options (can be empty - not used)
* @return void
*/
public function restore_raw_data(array $options): void {
$file = $this->get_file();
$this->data = unserialize($file->get_content());
}

public function validate_restore_options(array $options): void {}
/**
* No validation is needed for the restore options of the model class,
* since that parameter is not used.
*
* @param array $options
* @return void
*/
public function validate_restore_options(array $options): void {
}
}
7 changes: 5 additions & 2 deletions classes/model_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ public static function create_scaffold_and_get_for_config(int $configid): int {
* @return model_version
* @throws Exception
*/
public static function create(int $versionid, ?array $contexts = null, ?string $dataset = null, ?bool $anonymous = true): model_version {
public static function create(int $versionid, ?array $contexts = null, ?string $dataset = null,
?bool $anonymous = true): model_version {
$version = new model_version($versionid);

try {
Expand Down Expand Up @@ -597,7 +598,9 @@ public function get_shuffled_data(mixed $existingtrainingdataset, mixed $existin
// So the second part needs to be the remaining data, but shuffled.
if ($existingtrainingdataset !== false && !$existingtestdataset) {
$trainingdata = $this->get_single_evidence('training_dataset'); // First part of reconstructed data.
if (!isset($trainingdata)) $trainingdata = [];
if (!isset($trainingdata)) {
$trainingdata = [];
}
$remainingdata = dataset_helper::diff($data, $trainingdata); // Second part of reconstructed data.
$remainingdatashuffled = dataset_helper::get_shuffled($remainingdata);
return dataset_helper::merge($trainingdata, $remainingdatashuffled);
Expand Down
4 changes: 3 additions & 1 deletion classes/task/version_create.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public function execute() {
mtrace('Finished version ' . $data->versionid . '.');
}

/*
/**
* Check whether the version creation task is active for a specific version.
*
* @param int $versionid
*/
public static function is_active($versionid) {
global $DB;
Expand Down
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="admin/tool/lala/db" VERSION="2024012213" COMMENT="XMLDB file for Moodle admin/tool/lala"
<XMLDB PATH="admin/tool/lala/db" VERSION="2024020508" COMMENT="XMLDB file for Moodle admin/tool/lala"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'tool_lala';
$plugin->release = '4.0.0';
$plugin->version = 2024012213;
$plugin->release = '4.0.1';
$plugin->version = 2024020508;
$plugin->requires = 2022041900;
$plugin->maturity = MATURITY_BETA;

0 comments on commit 0769ee1

Please sign in to comment.