private function getDiscriminationCoefficient(Exercise $exercise)
    {
        // get all scores for the exercise
        $papers = $this->paperRepository->findBy([
            'exercise' => $exercise,
        ]);

        $itemRepository = $this->om->getRepository('UJMExoBundle:Item\Item');
        $reportScoreOn = 100;
        // all scores obtained for an exercise
        $exerciseScores = $this->getPapersScores($papers, $reportScoreOn);
        // exercise standard deviation
        $standardDeviationE = $this->getStandardDeviation($exerciseScores);
        // get average score per exercise
        $exerciseAverageScore = $this->getMinMaxAverageScores($exercise, $reportScoreOn)['avg'];
        // all scores obtained per question
        $questionsScores = [];
        // all average scores per question
        $questionsAvgScores = [];
        // all margin marks per question
        $questionsMarginMark = [];
        // computed result to return
        $discriminationCoef = [];

        /** @var Paper $paper */
        foreach ($papers as $paper) {
            // base success compution on paper structure
            $structure = json_decode($paper->getStructure(), true);

            foreach ($structure['steps'] as $step) {
                foreach (array_filter($step['items'], function ($item) {
                    return ItemType::isSupported($item['type']);
                }) as $item) {
                    // since the compution is based on the structure the same item can come several times
                    if (!array_key_exists($item['id'], $discriminationCoef)) {
                        $itemEntity = $itemRepository->findOneBy(['uuid' => $item['id']]);
                        // set questions scores
                        $questionsScores[$item['id']] = $this->itemManager->getItemScores($exercise, $itemEntity);
                        // get average score for the item
                        $questionsAvgScores[$item['id']] = array_sum($questionsScores[$item['id']]) / count($questionsScores[$item['id']]);
                        $i = 0;

                        foreach ($questionsScores[$item['id']] as $score) {
                            $questionsMarginMark[$item['id']][] = ($score - $questionsAvgScores[$item['id']]) * ($exerciseScores[$i] - $exerciseAverageScore);
                            ++$i;
                        }

                        $questionProductMarginMark = $questionsMarginMark[$item['id']];
                        $sumPenq = array_sum($questionProductMarginMark);
                        $sumPenq = round($sumPenq, 3);
                        $standardDeviationQ = $this->getStandardDeviation($questionsScores[$item['id']]);
                        $n = count($questionProductMarginMark);
                        $nSxSy = $n * $standardDeviationQ * $standardDeviationE;
                        $coef = $nSxSy === floatval(0) ? 0 : round($sumPenq / ($nSxSy), 3);

                        $discriminationCoef[$item['id']] = [
                            'xData' => $itemEntity->getTitle() ? strip_tags($itemEntity->getTitle()) : strip_tags($itemEntity->getContent()),
                            'yData' => $coef,
                        ];
                    }
                }
            }
        }

        return $discriminationCoef;
    }
private function getDiscriminationCoefficient(Exercise $exercise)
    {
        // get all scores for the exercise
        $papers = $this->paperRepository->findBy([
            'exercise' => $exercise,
        ]);

        $itemRepository = $this->om->getRepository('UJMExoBundle:Item\Item');
        $reportScoreOn = 100;
        // all scores obtained for an exercise
        $exerciseScores = $this->getPapersScores($papers, $reportScoreOn);
        // exercise standard deviation
        $standardDeviationE = $this->getStandardDeviation($exerciseScores);
        // get average score per exercise
        $exerciseAverageScore = $this->getMinMaxAverageScores($exercise, $reportScoreOn)['avg'];
        // all scores obtained per question
        $questionsScores = [];
        // all average scores per question
        $questionsAvgScores = [];
        // all margin marks per question
        $questionsMarginMark = [];
        // computed result to return
        $discriminationCoef = [];

        /** @var Paper $paper */
        foreach ($papers as $paper) {
            // base success compution on paper structure
            $structure = json_decode($paper->getStructure(), true);

            foreach ($structure['steps'] as $step) {
                foreach (array_filter($step['items'], function ($item) {
                    return ItemType::isSupported($item['type']);
                }) as $item) {
                    // since the compution is based on the structure the same item can come several times
                    if (!array_key_exists($item['id'], $discriminationCoef)) {
                        $itemEntity = $itemRepository->findOneBy(['uuid' => $item['id']]);
                        // set questions scores
                        $questionsScores[$item['id']] = $this->itemManager->getItemScores($exercise, $itemEntity);
                        // get average score for the item
                        $questionsAvgScores[$item['id']] = array_sum($questionsScores[$item['id']]) / count($questionsScores[$item['id']]);
                        $i = 0;

                        foreach ($questionsScores[$item['id']] as $score) {
                            $questionsMarginMark[$item['id']][] = ($score - $questionsAvgScores[$item['id']]) * ($exerciseScores[$i] - $exerciseAverageScore);
                            ++$i;
                        }

                        $questionProductMarginMark = $questionsMarginMark[$item['id']];
                        $sumPenq = array_sum($questionProductMarginMark);
                        $sumPenq = round($sumPenq, 3);
                        $standardDeviationQ = $this->getStandardDeviation($questionsScores[$item['id']]);
                        $n = count($questionProductMarginMark);
                        $nSxSy = $n * $standardDeviationQ * $standardDeviationE;
                        $coef = $nSxSy === floatval(0) ? 0 : round($sumPenq / ($nSxSy), 3);

                        $discriminationCoef[$item['id']] = [
                            'xData' => $itemEntity->getTitle() ? strip_tags($itemEntity->getTitle()) : strip_tags($itemEntity->getContent()),
                            'yData' => $coef,
                        ];
                    }
                }
            }
        }

        return $discriminationCoef;
    }
private function getDiscriminationCoefficient ( Exercise $ exercise ) { // get all scores for the exercise $ papers = $ this -> paperRepository -> findBy ( [ 'exercise' => $ exercise , ] ) ; $ itemRepository = $ this -> om -> getRepository ( 'UJMExoBundle:Item\Item' ) ; $ reportScoreOn = 100 ; // all scores obtained for an exercise $ exerciseScores = $ this -> getPapersScores ( $ papers , $ reportScoreOn ) ; // exercise standard deviation $ standardDeviationE = $ this -> getStandardDeviation ( $ exerciseScores ) ; // get average score per exercise $ exerciseAverageScore = $ this -> getMinMaxAverageScores ( $ exercise , $ reportScoreOn ) [ 'avg' ] ; // all scores obtained per question $ questionsScores = [ ] ; // all average scores per question $ questionsAvgScores = [ ] ; // all margin marks per question $ questionsMarginMark = [ ] ; // computed result to return $ discriminationCoef = [ ] ; /** @var Paper $paper */ foreach ( $ papers as $ paper ) { // base success compution on paper structure $ structure = json_decode ( $ paper -> getStructure ( ) , true ) ; foreach ( $ structure [ 'steps' ] as $ step ) { foreach ( array_filter ( $ step [ 'items' ] , function ( $ item ) { return ItemType :: isSupported ( $ item [ 'type' ] ) ; } ) as $ item ) { // since the compution is based on the structure the same item can come several times if ( ! array_key_exists ( $ item [ 'id' ] , $ discriminationCoef ) ) { $ itemEntity = $ itemRepository -> findOneBy ( [ 'uuid' => $ item [ 'id' ] ] ) ; // set questions scores $ questionsScores [ $ item [ 'id' ] ] = $ this -> itemManager -> getItemScores ( $ exercise , $ itemEntity ) ; // get average score for the item $ questionsAvgScores [ $ item [ 'id' ] ] = array_sum ( $ questionsScores [ $ item [ 'id' ] ] ) / count ( $ questionsScores [ $ item [ 'id' ] ] ) ; $ i = 0 ; foreach ( $ questionsScores [ $ item [ 'id' ] ] as $ score ) { $ questionsMarginMark [ $ item [ 'id' ] ] [ ] = ( $ score - $ questionsAvgScores [ $ item [ 'id' ] ] ) * ( $ exerciseScores [ $ i ] - $ exerciseAverageScore ) ; ++ $ i ; } $ questionProductMarginMark = $ questionsMarginMark [ $ item [ 'id' ] ] ; $ sumPenq = array_sum ( $ questionProductMarginMark ) ; $ sumPenq = round ( $ sumPenq , 3 ) ; $ standardDeviationQ = $ this -> getStandardDeviation ( $ questionsScores [ $ item [ 'id' ] ] ) ; $ n = count ( $ questionProductMarginMark ) ; $ nSxSy = $ n * $ standardDeviationQ * $ standardDeviationE ; $ coef = $ nSxSy === floatval ( 0 ) ? 0 : round ( $ sumPenq / ( $ nSxSy ) , 3 ) ; $ discriminationCoef [ $ item [ 'id' ] ] = [ 'xData' => $ itemEntity -> getTitle ( ) ? strip_tags ( $ itemEntity -> getTitle ( ) ) : strip_tags ( $ itemEntity -> getContent ( ) ) , 'yData' => $ coef , ] ; } } } } return $ discriminationCoef ; }
Get discrimination coefficient for an exercise.

@param Exercise $exercise

@return array
Get discrimination coefficient for an exercise .