@param $records

@return mixed
777342
public function transformRecordsToObjects($records)
    {
        if ($this->recordClass) {
            $recordClass = $this->recordClass;
            foreach ($records as &$record) {
                $record = (new $recordClass($record));
            }
        }

        return $records;
    }
167249
protected function getBestSplit(array $records) : DecisionTreeLeaf
    {
        $targets = array_intersect_key($this->targets, array_flip($records));
        $samples = array_intersect_key($this->samples, array_flip($records));
        $samples = array_combine($records, $this->preprocess($samples));
        $bestGiniVal = 1;
        $bestSplit = null;
        $features = $this->getSelectedFeatures();
        foreach ($features as $i) {
            $colValues = [];
            foreach ($samples as $index => $row) {
                $colValues[$index] = $row[$i];
            }
            $counts = array_count_values($colValues);
            arsort($counts);
            $baseValue = key($counts);
            $gini = $this->getGiniIndex($baseValue, $colValues, $targets);
            if ($bestSplit === null || $bestGiniVal > $gini) {
                $split = new DecisionTreeLeaf();
                $split->value = $baseValue;
                $split->giniIndex = $gini;
                $split->columnIndex = $i;
                $split->isContinuous = $this->columnTypes[$i] == self::CONTINUOUS;
                $split->records = $records;

                // If a numeric column is to be selected, then
                // the original numeric value and the selected operator
                // will also be saved into the leaf for future access
                if ($this->columnTypes[$i] == self::CONTINUOUS) {
                    $matches = [];
                    preg_match("/^([<>=]{1,2})\s*(.*)/", strval($split->value), $matches);
                    $split->operator = $matches[1];
                    $split->numericValue = floatval($matches[2]);
                }

                $bestSplit = $split;
                $bestGiniVal = $gini;
            }
        }

        return $bestSplit;
    }
323851
private function formatRecord(array $records, $currentRecordIndex)
    {
        $record = $records[$currentRecordIndex];
        $recordAsString = '';

        if ($this->isLogInfoDisplayed($record)) {
            $logInfo = $this->formatLogInfo($record);
            $recordAsString .= $this->formatAsSection($logInfo);
        }

        if (isset($record['message']) && !empty($record['message'])) {
            $recordAsString .= $this->formatMessage($record).PHP_EOL;
        }

        if (isset($record['context']) && !empty($record['context'])) {
            // if the context contains an error stack trace, remove it to display it separately
            $stack = null;
            if (isset($record['context']['stack'])) {
                $stack = $record['context']['stack'];
                unset($record['context']['stack']);
            }

            $recordAsString .= $this->formatContext($record).PHP_EOL;

            if (null !== $stack) {
                $recordAsString .= '--> Stack Trace:'.PHP_EOL;
                $recordAsString .= $this->formatStackTrace($stack, '    | ');
            }
        }

        if (isset($record['extra']) && !empty($record['extra'])) {
            // don't display the extra information when it's identical to the previous log record
            $previousRecordExtra = isset($records[$currentRecordIndex - 1]) ? $records[$currentRecordIndex - 1]['extra'] : null;
            if ($record['extra'] !== $previousRecordExtra) {
                $recordAsString .= $this->formatExtra($record).PHP_EOL;
            }
        }

        return $recordAsString;
    }
462713
public function findSubdefsByRecordReferenceFromCollection($records, array $names = null)
    {
        $subdefs = $this->reduceRecordReferenceCollection(
            $records,
            function (array &$carry, array $subdefs, array $references) {
                $subdefsByRecordId = [];

                /** @var \media_subdef $subdef */
                foreach ($subdefs as $subdef) {
                    $recordId = $subdef->get_record_id();

                    if (!isset($subdefsByRecordId[$recordId])) {
                        $subdefsByRecordId[$recordId] = [];
                    }

                    $subdefsByRecordId[$recordId][$subdef->get_name()] = $subdef;
                }

                /** @var RecordReferenceInterface $reference */
                foreach ($references as $index => $reference) {
                    if (isset($subdefsByRecordId[$reference->getRecordId()])) {
                        $carry[$index] = $subdefsByRecordId[$reference->getRecordId()];
                    };
                }

                return $carry;
            },
            array_fill_keys(array_keys($records instanceof \Traversable ? iterator_to_array($records) : $records), []),
            $names
        );

        $reordered = [];

        foreach ($records as $index => $record) {
            $reordered[$index] = $subdefs[$index];
        }

        return $reordered;
    }
1260303
protected static function sort_records(&$records, $sortfields) {
        if (empty($records)) {
            return;
        }
        // If sorting by course display name, calculate it (it may be fullname or shortname+fullname).
        if (array_key_exists('displayname', $sortfields)) {
            foreach ($records as $key => $record) {
                if (!isset($record->displayname)) {
                    $records[$key]->displayname = get_course_display_name_for_list($record);
                }
            }
        }
        // Sorting by one field - use core_collator.
        if (count($sortfields) == 1) {
            $property = key($sortfields);
            if (in_array($property, array('sortorder', 'id', 'visible', 'parent', 'depth'))) {
                $sortflag = core_collator::SORT_NUMERIC;
            } else if (in_array($property, array('idnumber', 'displayname', 'name', 'shortname', 'fullname'))) {
                $sortflag = core_collator::SORT_STRING;
            } else {
                $sortflag = core_collator::SORT_REGULAR;
            }
            core_collator::asort_objects_by_property($records, $property, $sortflag);
            if ($sortfields[$property] < 0) {
                $records = array_reverse($records, true);
            }
            return;
        }

        // Sort by multiple fields - use custom sorting.
        uasort($records, function($a, $b) use ($sortfields) {
            foreach ($sortfields as $field => $mult) {
                // Nulls first.
                if (is_null($a->$field) && !is_null($b->$field)) {
                    return -$mult;
                }
                if (is_null($b->$field) && !is_null($a->$field)) {
                    return $mult;
                }

                if (is_string($a->$field) || is_string($b->$field)) {
                    // String fields.
                    if ($cmp = strcoll($a->$field, $b->$field)) {
                        return $mult * $cmp;
                    }
                } else {
                    // Int fields.
                    if ($a->$field > $b->$field) {
                        return $mult;
                    }
                    if ($a->$field < $b->$field) {
                        return -$mult;
                    }
                }
            }
            return 0;
        });
    }
981839
protected function getDocument($record)
    {
        $document = new Document();
        $document->setData($record);
        $document->setType($this->type);
        $document->setIndex($this->index);

        return $document;
    }
543337
protected static function mongoIdsToIds($records)
    {
        foreach ($records as $key => $record) {
            $records[$key] = static::mongoIdToId($record);
        }

        return $records;
    }
87596
public static function import($records)
    {
        $objects = array();
        $className = get_called_class();
        $defaults = self::schema()->defaults();

        foreach ($records as $record) {
            $objects []= $className::fromArray()
                ->load(array_merge($defaults, $record))->markSaved(false)->save();
        }

        return $objects;
    }
431929
public function multiCreate($records)
    {
        $ids = [];

        foreach ($records as $record) {
            try {
                $createdRecord = $this->create($record);
                $ids[] = $createdRecord[$this->getIdentifier()];
            } catch (\Throwable $e) {
                // TODO: need to log record that was not created
                continue;
            }
        }

        return $ids;
    }
792332
public static function translateKeys($records, $translations)
    {
        if (!self::iterable($records)) {
            return array();
        }
        
        $out = array();
        foreach ($records as $n => $record) {
            if (!self::iterable($record)) {
                $out[$n] = $record;
                continue;
            }
            $out[$n] = array();
            
            foreach ($record as $k => $v) {
                $new_k = (array_key_exists($k, $translations)) ? $translations[$k] : $k;
                $out[$n][$new_k] = $v;
            }
        }
        return $out;
    }
743168
protected function processRecord(array $record): array
    {
        if ($this->processors) {
            foreach ($this->processors as $processor) {
                $record = PhpHelper::call($processor, $record);
            }
        }

        return $record;
    }
989395
public function format(array $record)
    {
        $data = parent::format($record);
        return $this->toJson($data, true);
    }
1106564
public function getRecordUrl($record)
    {
        if (isset($this->recordOnClick)) {
            return 'javascript:;';
        }

        if (!isset($this->recordUrl)) {
            return null;
        }

        $url = RouterHelper::replaceParameters($record, $this->recordUrl);
        return Backend::url($url);
    }
1089055
protected static function fromMongoObjects($record)
    {
        if ($record instanceof BSONDocument) {
            $record = $record->getArrayCopy();
        } elseif (is_object($record)) {
            $record = (array)$record; // std object
        }
        if (!empty($record)) {
            foreach ($record as &$data) {
                if (is_object($data)) {
                    if ($data instanceof ObjectID) {
                        $data = (string)$data;
                    } elseif ($data instanceof Timestamp) {
                        $data = (string)$data;
                    } elseif ($data instanceof UTCDateTime) {
                        if (empty($cfgFormat = DataFormatter::getDateTimeFormat('datetime'))) {
                            $cfgFormat = 'c';
                        }
                        $data = $data->toDateTime();
                        $data = ['$date' => $data->format($cfgFormat)];
                    } elseif ($data instanceof Binary) {
                        $data = $data->getData();
                    }
                }
            }
        }

        return $record;
    }
443825
public function retrieve($record)
    {
        $params['index'] = $this->getName();
        $params['type'] = $record['type'];
        $params['id'] = $record['id'];

        self::getClient()->get($params);
    }
54536
private function formatLogBatchHeader(array $records)
    {
        $firstRecord = $records[0];

        if ($this->isAsseticLog($firstRecord)) {
            return $this->formatAsSubtitle('Assetic request');
        }

        $logDate = $firstRecord['datetime'];
        $logDateAsString = $logDate->format('d/M/Y H:i:s');

        return $this->formatAsTitle($logDateAsString);
    }
97143
public static function tably($records)
    {
        if (count($records) === 0) {
            return null;
        }
        
        $htmls = array();
        $htmls[] = '<table>';
        foreach ($records as $record) {
            $htmls[] = '<tr>';
            foreach ($record as $k => $v) {
                $htmls[] = sprintf('<td class="%s">%s</td>', Str::machine($k), $v);
            }
            $htmls[] = '</tr>';
        }
        $htmls[] = '</table>';
        return join("\n", $htmls);
    }