#!/usr/bin/env php Notes: - Script has be be executable (chmod +x). - INPUT: total points for the student as first parameter (can be negative if negative marking has been used) - OUTPUT: non-rounded mark, with '.' as decimal separator "; exit; } if (!empty($options['current-dir'])) { $total_points = $options['current-dir']; $filename = array(); foreach(scandir('./') as $f) if (preg_match('/\.csv$/', $f)) $filename[] = $f; if (count($filename)) { $csv = ""; $first = true; foreach($filename as $f) { if (!$first) $csv .= ','; $csv .= ucfirst(preg_replace('/\.csv$/', '', $f)); $csv .= "/$f/$total_points"; $first = false; } } else { echo "No AMC stat files found in this directory.\n"; exit; } } $only_questions = null; if (!empty($options['only-questions'])) { $filename = $options['only-questions']; if(!is_file($filename)) { echo "File not found: $filename\n"; exit; } $only_questions = file($filename, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); } $external = null; if (!empty($options['external'])) { $external = $options['external']; if(!is_file($external)) { echo "External script/exec not found: $external\n"; exit; } } $inverse_filter = false; if (array_key_exists('inverse-filter', $options)) { $inverse_filter = true; } if (!empty($options['csv'])) $csv = $options['csv']; if (!empty($options['sample'])) $samples = explode(',', $options['sample']); else $samples = array( 'global'); if (!empty($options['type'])) $types = explode(',', $options['type']); else $types = array( 'average' ); // Create ExamCalcs object $Global = new ExamCalcs(); // Load files $loaded = array(); foreach(explode(',', $csv) as $file_info) { $details = explode('/', $file_info); if (count($details) < 3 ) { echo "CSV file list should look like: tournesol/tournesol.csv/30[,favre@favre.csv@29,...]\n"; exit; } $name = $details[0]; $filename = $details[1]; $total = $details[2]; if(!is_file($filename)) { echo "File not found: $filename\n"; exit; } if (in_array($filename, $loaded)) { echo "Trying to load $filename a second time...\n"; exit; } $Global->addFile($name, $filename, $total, $only_questions, $inverse_filter, $external); $loaded[] = $filename; } foreach ($types as $type) { // Build samples foreach ($samples as $sample) { // Print header $sample_header = strtoupper($sample); switch ($type) { case 'average': printAverage($sample_header); break; case 'dist': case 'dist_percentage': printDistribution($sample_header); break; case 'marks': break; } // Build samples $Samples = array(); switch ($sample) { case 'global': $Samples['global'] = new ExamCalcs($Global->getDataSet()); break; case 'sections': foreach ($Global->getSections() as $section) { $tmpSample = new ExamCalcs($Global->getDataSet()); $tmpSample->filterBySections($section); $Samples[$section] = $tmpSample; } break; case 'profs': foreach ($Global->getTeachers() as $prof) { $tmpSample = new ExamCalcs($Global->getDataSet()); $tmpSample->filterByTeachers($prof); $Samples[$prof] = $tmpSample; } break; } // Print stats $is_first = true; foreach ($Samples as $name => $S) { if (!$is_first) echo "\n"; else $is_first = false; $stats = $S->getStats(); switch ($type) { case 'average': printAverage($name, $stats); break; case 'dist_percentage': printDistribution($name, $stats, true); break; case 'dist': printDistribution($name, $stats); break; case 'discrimination': echo "\"STATS ON QUESTIONS: ".strtoupper($name)."\"\n"; try { $S->printStatsOnCommonItems(); } catch (Exception $e) { echo "\"Not enough data\"\n"; } break; case 'marks': $marks = $S->getMarks(); foreach ($marks as $student) { echo implode(';', $student)."\n"; } break; case 'questions': $questions = $S->getQuestions(); foreach ($questions as $student) { echo implode(';', $student)."\n"; } break; } } } } exit; ?>