protected function prepare_prediction_record($sampleid, $rangeindex, $prediction, $predictionscore, $calculations) {
        $context = $this->get_analyser()->sample_access_context($sampleid);

        $record = new \stdClass();
        $record->modelid = $this->model->id;
        $record->contextid = $context->id;
        $record->sampleid = $sampleid;
        $record->rangeindex = $rangeindex;
        $record->prediction = $prediction;
        $record->predictionscore = $predictionscore;
        $record->calculations = $calculations;
        $record->timecreated = time();

        $analysable = $this->get_analyser()->get_sample_analysable($sampleid);
        $timesplitting = $this->get_time_splitting();
        $timesplitting->set_analysable($analysable);
        $range = $timesplitting->get_range_by_index($rangeindex);
        if ($range) {
            $record->timestart = $range['start'];
            $record->timeend = $range['end'];
        }

        return array($record, $context);
    }