Beispiel #1
0
    /**
     * @param array $examples all the examples in the workshop
     * @param int $n the number of examples that will be shown to users ($workshop->numexamples)
     */
    public function __construct($examples,$n) {

        $slices = workshop::slice_example_submissions($examples,$n);
        
        $this->slices = array();
        foreach ($slices as $i => $s) {
            
            $slice = new stdClass;
            
            $slice->min = (float)(reset($s)->grade);
            if ($i < count($slices) - 1)
                $slice->max = (float)(end($s)->grade);
            else
                $slice->max = 100;
            
            $slice->colour = $this->get_colour($i,$n,1);
            $slice->title = workshop_random_examples_helper::$descriptors[count($slices)][$i];
            $slice->width = $slice->max - $slice->min . "%";
            
            $grades = array();
            foreach($s as $v) $grades[] = $v->grade;
            $slice->mean = array_sum($grades) / count($grades);
            $slice->meancolour = $this->get_colour($i,$n,-1);

            $slice->submissions = $s;
            $slice->subcolour = $this->get_colour($i,$n,0);
            
            //identify warnings
            
            if ($i > 0) {
                $prev = $this->slices[$i - 1];
                if ($slice->min == $prev->max) {
                    //overlap
                    $prev->warnings[] = get_string('randomexamplesoverlapwarning','workshop',array("prev" => $prev->title, "next" => $slice->title));
                }
            }
            
            $this->slices[$i] = $slice;
        }
        
    }