protected static function delete_stats(int $courseid, int $userid = null) {
        global $DB;
        $params = (isset($userid)) ? ['courseid' => $courseid, 'userid' => $userid] : ['courseid' => $courseid];
        $DB->delete_records('stats_user_daily', $params);
        $DB->delete_records('stats_user_weekly', $params);
        $DB->delete_records('stats_user_monthly', $params);
    }