protected function save_prediction_samples(array $sampleids, array $ranges,
            \core_analytics\local\time_splitting\base $timesplitting, ?\stdClass $predictsamplesrecord = null) {
        global $DB;

        if (count($ranges) > 1) {
            throw new \coding_exception('$ranges argument should only contain one range');
        }

        $rangeindex = key($ranges);

        if ($predictsamplesrecord) {
            // Append the new samples used for prediction.
            $predictsamplesrecord->sampleids = json_encode($predictsamplesrecord->sampleids + $sampleids);
            $predictsamplesrecord->timemodified = time();
            $DB->update_record('analytics_predict_samples', $predictsamplesrecord);
        } else {
            $predictsamplesrecord = (object)[
                'modelid' => $this->analyser->get_modelid(),
                'analysableid' => $timesplitting->get_analysable()->get_id(),
                'timesplitting' => $timesplitting->get_id(), 'rangeindex' => $rangeindex
            ];
            $predictsamplesrecord->sampleids = json_encode($sampleids);
            $predictsamplesrecord->timecreated = time();
            $predictsamplesrecord->timemodified = $predictsamplesrecord->timecreated;
            $DB->insert_record('analytics_predict_samples', $predictsamplesrecord);
        }
    }