Get Score by question level

@return array
338065
public function getScoreByLevel()
    {
        $levels = array();

        /** @var TemplateInterface $template */
        foreach ($this->getData() as $template) {
            $question = $template->getQuestion();

            if (!isset($levels[$question->getLevel()])) {
                $levels[$question->getLevel()] = array(
                    'name' => $question->getLevel(),
                    'valid' => 0,
                    'total' => 0,
                    'color' => '#'.substr('00000'.dechex(mt_rand(0, 0xffffff)), -6)
                );
            }

            if ($template->isValid()) {
                $levels[$question->getLevel()]['valid']++;
            }

            $levels[$question->getLevel()]['total']++;
        }

        sort($levels);

        return $levels;
    }
1183355
public function get_sections() {
        global $DB;
        if ($this->sections === null) {
            $this->sections = array_values($DB->get_records('quiz_sections',
                    array('quizid' => $this->get_quizid()), 'firstslot'));
        }
        return $this->sections;
    }
795439
private function getTopNestingLevel()
    {
        $highestLevel = $this->getNestingLevel();
        foreach ($this->getChildren() as $child) {
            $childLevel = $child->getNestingLevel();
            if ($highestLevel < $childLevel) {
                $highestLevel = $childLevel;
            }
        }

        return $highestLevel;
    }
543092
private function getReviewScore($bottom_area)
    {
        $score = [];
        $score_area = $bottom_area->find('table', 0);
        if ($score_area) {
            foreach ($score_area->find('tr') as $each_score) {
                $score_type = strtolower($each_score->find('td', 0)->plaintext);
                $score_value = $each_score->find('td', 1)->plaintext;
                $score[$score_type] = $score_value;
            }
        }

        return $score;
    }
786949
private function getAllInfo()
    {
        $data = [];
        $review_area = $this->_parser->find('.borderDark', 0);

        $top_area = $review_area->find('.spaceit', 0);
        $bottom_area = $top_area->next_sibling();

        $data['id'] = $this->getId();
        $data['source'] = $this->getReviewSource($top_area, $bottom_area);
        $data['username'] = $this->getReviewUser($top_area);
        $data['image'] = $this->getReviewImage($top_area);
        $data['helpful'] = $this->getReviewHelpful($top_area);
        $data['date'] = $this->getReviewDate($top_area);
        if ($this->_type == 'anime') {
            $data['episode'] = $this->getReviewEpisode($top_area);
        } else {
            $data['chapter'] = $this->getReviewEpisode($top_area);
        }
        $data['score'] = $this->getReviewScore($bottom_area);
        $data['review'] = $this->getReviewText($bottom_area);

        return $data;
    }
197694
public function getGradeAllowableValues()
    {
        return [
            self::GRADE__1,
            self::GRADE__2,
            self::GRADE__3,
            self::GRADE__4,
            self::GRADE__5,
            self::GRADE__6,
            self::GRADE__7,
            self::GRADE__8,
            self::GRADE__9,
            self::GRADE__10,
            self::GRADE__11,
            self::GRADE__12,
            self::GRADE_PRE_KINDERGARTEN,
            self::GRADE_KINDERGARTEN,
            self::GRADE_POST_GRADUATE,
            self::GRADE_OTHER,
        ];
    }
1038803
public function getPercentagePartial()
    {
        $total = $this->getTotal();

        return round((($this->score->getValid() + $this->score->getPartial())/$total) * 100);
    }
624839
public static function get_questions_returns() {
        return new external_single_structure(
            array(
                'questions' => new external_multiple_structure(
                    new external_single_structure(
                        array(
                            'id' => new external_value(PARAM_INT, 'Question id'),
                            'text' => new external_value(PARAM_RAW, 'Question text'),
                            'shorttext' => new external_value(PARAM_RAW, 'Question short text'),
                            'multi' => new external_value(PARAM_RAW, 'Subquestions ids'),
                            'intro' => new external_value(PARAM_RAW, 'The question intro'),
                            'type' => new external_value(PARAM_INT, 'Question type'),
                            'options' => new external_value(PARAM_RAW, 'Question options'),
                            'parent' => new external_value(PARAM_INT, 'Parent question (for subquestions)'),
                        ), 'Questions'
                    )
                ),
                'warnings' => new external_warnings()
            )
        );
    }
257345
private function getScore()
    {
        $score = $this->_parser->find('div[class="fl-l score"]', 0)->plaintext;
        $score = trim($score);

        return $score != 'N/A' ? $score : null;
    }
1285801
public function getTopLevelSections()
    {
        $this->sortSectionsByDepth();
        $topLevelSections = array();

        foreach ($this->sections as $section) {
            if ($section->getDepth() != 0) {
                break;
            }
            $topLevelSections[] = $section;
        }

        return $topLevelSections;
    }
904961
public function get_total_mark() {
        $mark = 0;
        foreach ($this->questionattempts as $qa) {
            if ($qa->get_max_mark() > 0 && $qa->get_state() == question_state::$needsgrading) {
                return null;
            }
            $mark += $qa->get_mark();
        }
        return $mark;
    }
1091761
public function fetchSingleValue()
	{
		$result = $this->query();
		$value = $result->fetchColumn(0);
		$result->closeCursor();
		return $value;
	}
1129027
public function getTotal()
    {
        return $this->score->getValid() + $this->score->getPartial() + $this->score->getNotValid();
    }
299801
public function getScore()
    {
        $ipLkup = $this->get('ipLkup', ['ip' => $this->ip]);

        $score = $ipLkup['response'][$this->ip];

        if ($score) {
            return (string) $score;
        } else {
            return 'unknown';
        }
    }
1176024
public function getLevels(int $from = 1, ?int $to = null, ?callable $callback = null): array
    {
        $parts = explode('.', $this->env);
        $n = isset($to) ? min(count($parts), $to) : count($parts);

        $levels = [];

        for ($i = $from; $i <= $n; $i++) {
            $level = join('.', array_slice($parts, 0, $i));
            $levels[] = isset($callback) ? $callback($level) : $level;
        }

        return $levels;
    }
1017831
public function getNextQuestion()
    {
        $nextQuestionId = $this->getCurrentQuestion() + 1;
        $questions = $this->getUserConfiguration()->getQuestions();

        if (!isset($questions[$nextQuestionId])) {
            return false;
        }

        $this->setQuestion($nextQuestionId);

        return $this->getQuestion();
    }
221813
public function getMissingQuestions($categories, $limit, $questions, $questionsLevel = array())
    {
        $query = $this->createQueryBuilder('q')
            ->addSelect('RAND() as HIDDEN rand, q, c, a')
            ->leftJoin('q.category', 'c')
            ->leftJoin('q.answers', 'a')
            ->where('q.category IN(:category)')
            ->andWhere('q.enabled = 1')
            ->andWhere('q.id NOT IN (:questions)')
            ->setParameter('category', $categories)
            ->setParameter('questions', $questions)
            ->setMaxResults($limit)
            ->orderBy('rand');

        if (!empty($questionsLevel)) {
            $query->andWhere('q.level IN(:level)')
                ->setParameter('level', $questionsLevel);
        }

        $questions = $query->getQuery()->getResult();

        return $questions;
    }