Prepares a structure of assessments and given grades

@param array $assessments batch of recordset items as returned by the grading strategy
@return array
336891
protected function prepare_data_from_recordset($assessments) {
        $data = array();    // to be returned
        foreach ($assessments as $a) {
            $id = $a->assessmentid; // just an abbreviation
            if (!isset($data[$id])) {
                $data[$id] = new stdclass();
                $data[$id]->assessmentid = $a->assessmentid;
                $data[$id]->weight       = $a->assessmentweight;
                $data[$id]->reviewerid   = $a->reviewerid;
                $data[$id]->gradinggrade = $a->gradinggrade;
                $data[$id]->submissionid = $a->submissionid;
                $data[$id]->dimgrades    = array();
            }
            $data[$id]->dimgrades[$a->dimensionid] = $a->grade;
        }
        return $data;
    }
689291
public function getAnswer(array $queries): array
    {
        $answers = [];
        foreach ($queries as $query) {
            $answer = $this->resourceRecords[$query->getName()][$query->getType()][$query->getClass()] ?? [];
            if (empty($answer)) {
                $answer = $this->findWildcardEntry($query);
            }

            $answers = array_merge($answers, $answer);
        }

        return $answers;
    }
825317
def get_assessments(self):
        
        assessments = []
        response = self.http.get('/Assessment')
        for assessment in response:
            assessments.append(Schemas.Assessment(assessment=assessment))
        return assessments
507471
public static function fetch_all($params) {
        if ($records = self::retrieve_record_set($params)) {
            return $records;
        }

        $records = grade_object::fetch_all_helper('grade_categories', 'grade_category', $params);
        self::set_record_set($params, $records);

        return $records;
    }
646861
def convert_assessments(quizzes, choices, feedbacks, questionnaires)
      assessment_converter = Moodle2CC::Moodle2Converter::AssessmentConverter.new
      assessments = []
      assessments += quizzes.map { |quiz| assessment_converter.convert_quiz(quiz) }
      assessments += choices.map { |choice| assessment_converter.convert_choice(choice) }
      assessments += feedbacks.map { |feedback| assessment_converter.convert_feedback(feedback) }
      assessments += questionnaires.map { |questionnaire| assessment_converter.convert_questionnaire(questionnaire) }
      assessments
    end
970427
public function files_for_gradebook(stdClass $grade) : array {
        return [
            'contextid' => $this->assignment->get_context()->id,
            'component' => ASSIGNFEEDBACK_COMMENTS_COMPONENT,
            'filearea' => ASSIGNFEEDBACK_COMMENTS_FILEAREA,
            'itemid' => $grade->id
        ];
    }
501030
protected function createData(array $entries): array
    {
        $rows = [];

        foreach ($entries as $entry) {
            $rows[] = $this->createEntryData($entry);
        }

        return [
            'version' => self::VERSION,
            'columns' => [self::COLUMN_LOG, self::COLUMN_TYPE, self::COLUMN_BACKTRACE],
            'rows' => $rows,
        ];
    }
273948
public function prepareExportFileVariables() : array {
		$result = [
			'success' => false,
			'error' => [],
			'data' => []
		];
		// details
		$details = [];
		if (!empty($this->collection['details'])) {
			$this->disassembleCollectionObject($this->collection['details'], $details);
		}
		// step 1: fields
		$result['data'][$this->collection['name']] = [];
		foreach ($this->fields as $k => $v) {
			if (!$this->skipExportField($k, $v)) continue;
			// if we have detail
			if (!empty($details[$k])) {
				$result['data'][$details[$k]['name']] = [];
				foreach ($details[$k]['pk'] as $k2 => $v2) {
					if ($k2 == 0 && strpos($v2, 'tenant_id') !== false) continue;
					$result['data'][$details[$k]['name']][0][$v2] = $v2;
				}
				continue;
			}
			// regular field
			$result['data'][$this->collection['name']][0][$k] = $k;
		}
		// step 2: detail fields
		foreach ($this->detail_fields as $k => $v) {
			$result['data'][$details[$k]['name']] = [];
			// add pk
			foreach ($details[$k]['pk'] as $k2 => $v2) {
				if ($k2 == 0 && strpos($v2, 'tenant_id') !== false) continue;
				$result['data'][$details[$k]['name']][0][$v2] = $v2;
			}
			// add fields
			foreach ($v['elements'] as $k2 => $v2) {
				if (!$this->skipExportField($k2, $v2)) continue;
				$result['data'][$details[$k]['name']][0][$k2] = $k2;
			}
		}
		$result['success'] = true;
		return $result;
	}
502186
protected function buildRequirements(array $matches)
    {
        $result = [];
        foreach ($matches as $match) {
            list($key, $regexp) = $this->splitSegment($match[3]);
            $result[$key] = $regexp . ($match[1] == '(' ? '*' : '+');
        }

        return $result;
    }
1333452
protected function define_assessment_subplugin_structure() {

        $paths = array();

        $elename = $this->get_namefor('grade');
        $elepath = $this->get_pathfor('/workshopform_accumulative_grade'); // we used get_recommended_name() so this works
        $paths[] = new restore_path_element($elename, $elepath);

        return $paths; // And we return the interesting paths
    }
131699
public function prepareSortOrProjection(array $fields)
    {
        $preparedFields = array();

        foreach ($fields as $key => $value) {
            $preparedFields[$this->prepareFieldName($key)] = $value;
        }

        return $preparedFields;
    }
186074
public function prep_paths(array $paths)
	{
		foreach ($paths as &$path)
		{
			$path = $this->prep_path($path);
		}
		return $paths;
	}
992789
protected function format_average_grade_for_questions($gradeaverages) {
        $row = array();

        if (!$gradeaverages) {
            $gradeaverages = array();
        }

        foreach ($this->questions as $question) {
            if (isset($gradeaverages[$question->slot]) && $question->maxmark > 0) {
                $record = $gradeaverages[$question->slot];
                $record->grade = quiz_rescale_grade(
                        $record->averagefraction * $question->maxmark, $this->quiz, false);

            } else {
                $record = new stdClass();
                $record->grade = null;
                $record->numaveraged = 0;
            }

            $row['qsgrade' . $question->slot] = $this->format_average($record, true);
        }

        return $row;
    }
1179335
protected function prepareFiles($files) {
    $values = [];

    foreach ($files as $file_uuid) {
      $file = $this->fileStorage->loadByProperties([
        'uuid' => $file_uuid,
      ]);

      if ($file) {
        $values[] = [
          'target_id' => current($file)->id(),
        ];
      }
    }

    return $values;
  }
1162385
public function toRecords(string $recordClass): array
    {
        $array = [];
        foreach ($this->rows as $row) {
            /**
             * @var $row Row
             */
            $record = Record::instanceRecord($recordClass, $row->toArray());
            $record->setLoaded();
            $array[] = $record;
        }
        return $array;
    }
1136736
protected function prepareFromYaml(array $categories = []) : array
    {
        $data = array();

        foreach ($this->paths as $path) {
            $files = Finder::create()->files()->in($path)->name('*.yml');

            foreach ($files as $file) {
                $fileData = Yaml::parse($file->getContents());
                $category = $fileData['category'];

                if (count($categories) > 0 && !in_array($category, $categories)) {
                    continue;
                }

                array_walk($fileData['questions'], function (&$item) use ($category) {
                    $item['category'] = $category;
                });

                $data = array_merge($data, $fileData['questions']);
            }
        }

        return $data;
    }
609692
protected function transform_db_records_to_entities(array $records) {
        $preprocessors = $this->get_preprocessors();
        $result = array_map(function($record) {
            return ['record' => $record];
        }, $records);

        $result = array_reduce(array_keys($preprocessors), function($carry, $preprocessor) use ($records, $preprocessors) {
            $step = $preprocessors[$preprocessor];
            $dependencies = $step->execute($records);

            foreach ($dependencies as $index => $dependency) {
                // Add the new dependency to the list.
                $carry[$index] = array_merge($carry[$index], [$preprocessor => $dependency]);
            }

            return $carry;
        }, $result);

        return $this->from_db_records($result);
    }