public function calculate($sampleids, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {

        if (!PHPUNIT_TEST && CLI_SCRIPT) {
            echo '.';
        }

        $calculations = [];
        foreach ($sampleids as $sampleid => $unusedsampleid) {

            // No time limits when calculating the target to train models.
            $calculatedvalue = $this->calculate_sample($sampleid, $analysable, $starttime, $endtime);

            if (!is_null($calculatedvalue)) {
                if ($this->is_linear() &&
                        ($calculatedvalue > static::get_max_value() || $calculatedvalue < static::get_min_value())) {
                    throw new \coding_exception('Calculated values should be higher than ' . static::get_min_value() .
                        ' and lower than ' . static::get_max_value() . '. ' . $calculatedvalue . ' received');
                } else if (!$this->is_linear() && static::is_a_class($calculatedvalue) === false) {
                    throw new \coding_exception('Calculated values should be one of the target classes (' .
                        json_encode(static::get_classes()) . '). ' . $calculatedvalue . ' received');
                }
            }
            $calculations[$sampleid] = $calculatedvalue;
        }
        return $calculations;
    }