protected function execute_prediction_callbacks(&$predictions, $indicatorcalculations) {

        // Here we will store all predictions' contexts, this will be used to limit which users will see those predictions.
        $samplecontexts = array();
        $records = array();

        foreach ($predictions as $uniquesampleid => $prediction) {

            // The unique sample id contains both the sampleid and the rangeindex.
            list($sampleid, $rangeindex) = $this->get_time_splitting()->infer_sample_info($uniquesampleid);
            if ($this->get_target()->triggers_callback($prediction->prediction, $prediction->predictionscore)) {

                // Prepare the record to store the predicted values.
                list($record, $samplecontext) = $this->prepare_prediction_record($sampleid, $rangeindex, $prediction->prediction,
                    $prediction->predictionscore, json_encode($indicatorcalculations[$uniquesampleid]));

                // We will later bulk-insert them all.
                $records[$uniquesampleid] = $record;

                // Also store all samples context to later generate insights or whatever action the target wants to perform.
                $samplecontexts[$samplecontext->id] = $samplecontext;

                $this->get_target()->prediction_callback($this->model->id, $sampleid, $rangeindex, $samplecontext,
                    $prediction->prediction, $prediction->predictionscore);
            }
        }

        if (!empty($records)) {
            $this->save_predictions($records);
        }

        return [$samplecontexts, $records];
    }