private function add_model_metadata(array &$data, \core_analytics\local\time_splitting\base $timesplitting,
            \core_analytics\local\target\base $target) {
        global $CFG;

        // If no target the first column is the sampleid, if target the last column is the target.
        // This will need to be updated when we support unsupervised learning models.
        $metadata = array(
            'timesplitting' => $timesplitting->get_id(),
            'nfeatures' => count(current($data)) - 1,
            'moodleversion' => $CFG->version,
            'targetcolumn' => $target->get_id()
        );
        if ($target->is_linear()) {
            $metadata['targettype'] = 'linear';
            $metadata['targetmin'] = $target::get_min_value();
            $metadata['targetmax'] = $target::get_max_value();
        } else {
            $metadata['targettype'] = 'discrete';
            $metadata['targetclasses'] = json_encode($target::get_classes());
        }

        // The first 2 samples will be used to store metadata about the dataset.
        $metadatacolumns = [];
        $metadatavalues = [];
        foreach ($metadata as $key => $value) {
            $metadatacolumns[] = $key;
            $metadatavalues[] = $value;
        }

        // This will also reset samples' dataset keys.
        array_unshift($data, $metadatacolumns, $metadatavalues);
    }