Example #1
0
function makeRoster($code, $course_count = false, $name_count = false)
{
    global $names, $courses;
    $MT = new Mersenne_Twister($code);
    $retval = array();
    $cc = 0;
    foreach ($courses as $k => $course) {
        $cc = $cc + 1;
        if ($course_count && $cc > $course_count) {
            break;
        }
        $new = $MT->shuffle($names);
        $new = array_slice($new, 0, $MT->getNext(17, 53));
        $inst = 1;
        $nc = 0;
        foreach ($new as $k2 => $name) {
            $nc = $nc + 1;
            if ($name_count && $nc > $name_count) {
                break;
            }
            $retval[] = array($name, $course, $inst);
            $inst = 0;
        }
    }
    return $retval;
}
Example #2
0
function getRandomNumbers($code, $count = 400, $max = 10000)
{
    $retval = array();
    $MT = new Mersenne_Twister($code);
    for ($i = 0; $i < $count; $i++) {
        $retval[] = $MT->getNext(1, $max);
    }
    return $retval;
}
Example #3
0
function makeRoster($code)
{
    global $names, $courses;
    $MT = new Mersenne_Twister($code);
    $retval = array();
    foreach ($courses as $k => $course) {
        $new = $MT->shuffle($names);
        $new = array_slice($new, 0, $MT->getNext(17, 53));
        $inst = 1;
        foreach ($new as $k2 => $name) {
            $retval[] = array($name, $course, $inst);
            $inst = 0;
        }
    }
    return $retval;
}
Example #4
0
<?php

use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Net;
use Tsugi\Util\Mersenne_Twister;
$sanity = array('urllib' => 'You should use urllib to retrieve the data from the API', 'urlencode' => 'You should use urlencode add parameters to the API url', 'json' => 'You should use the json library to parse the API data');
// Compute the stuff for the output
$code = 42;
$MT = new Mersenne_Twister($code);
$sample = $MT->shuffle($LOCATIONS);
$sample_location = $sample[0];
$code = $USER->id + $LINK->id + $CONTEXT->id;
$MT = new Mersenne_Twister($code);
$actual = $MT->shuffle($LOCATIONS);
$actual_location = $actual[0];
// Retrieve the data
$url = curPageUrl();
$api_url = str_replace('index.php', 'data/geojson', $url);
$google_api = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=University+of+Michigan';
$sample_url = $api_url . '?sensor=false&address=' . urlencode($sample_location);
$actual_url = $api_url . '?sensor=false&address=' . urlencode($actual_location);
$sample_data = Net::doGet($sample_url);
$sample_count = strlen($sample_data);
$response = Net::getLastHttpResponse();
$sample_json = json_decode($sample_data);
if ($response != 200 || $sample_json == null || !isset($sample_json->results[0])) {
    error_log("DIE: Sample response={$response} url={$sample_url} json_error=" . json_last_error_msg());
    die("Sample response={$response} url={$sample_url} json_error=" . json_last_error_msg());
}
// echo("<pre>\n");echo(jsonIndent(json_encode($sample_json)));echo("</pre>\n");
Example #5
0
File: a01.php Project: 4sp1r3/tsugi
<?php

use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Mersenne_Twister;
require_once "names.php";
// Compute the stuff for the output
$code = $USER->id + $LINK->id + $CONTEXT->id;
$MT = new Mersenne_Twister($code);
$my_names = array();
$my_age = array();
$howmany = $MT->getNext(4, 6);
for ($i = 0; $i < $howmany; $i++) {
    $name = $names[$MT->getNext(0, count($names))];
    $age = $MT->getNext(13, 40);
    $sha = sha1($name . $age);
    $database[] = array($sha, $name, $age);
}
$sorted = $database;
sort($sorted);
$goodsha = $sorted[0][0];
$oldgrade = $RESULT->grade;
if (isset($_POST['sha1'])) {
    if ($_POST['sha1'] != $goodsha) {
        $_SESSION['error'] = "Your code did not match";
        header('Location: ' . addSession('index.php'));
        return;
    }
    $gradetosend = 1.0;
    $scorestr = "Your answer is correct, score saved.";
    if ($dueDate->penalty > 0) {
Example #6
0
 if (strpos($local_path, "regex_sum_") === 0 && strpos($local_path, ".txt") !== false) {
     header('Content-Type: text/plain');
     $code = 42;
     $pieces = preg_split('/[_.]/', $local_path);
     if (count($pieces) == 4 && $pieces[2] + 0 > 0) {
         $code = $pieces[2] + 0;
     }
     if ($code == 42) {
         echo "This file contains the sample data\n\n";
     } else {
         echo "This file contains the actual data for your assignment - good luck!\n\n";
     }
     $handle = fopen("../static/intro.txt", "r");
     if ($handle) {
         $count = 0;
         $MT = new Mersenne_Twister($code);
         // header('Content-Disposition: attachment; filename='.$local_path.';');
         while (($line = fgets($handle)) !== false) {
             $count++;
             $choose = $count < 400 ? $MT->getNext(0, 9) : 1;
             if ($choose != 0) {
                 echo $line;
                 continue;
             }
             $howmany = $MT->getNext(1, 3);
             if ($howmany == 1) {
                 echo $MT->getNext(1, 10000) . ' ' . $line;
             } else {
                 if ($howmany == 2) {
                     echo $MT->getNext(1, 10000) . ' ' . rtrim($line) . ' ' . $MT->getNext(1, 10000) . "\n";
                 } else {
Example #7
0
function make_quiz($submit, $questions, $errors, $seed = -1)
{
    $retval = array("status" => "failure", "errors" => $errors);
    if (count($questions) < 1) {
        $retval["message"] = "No questions found";
        return $retval;
    }
    // Load the gift submission
    $submit = isset($_SESSION['gift_submit']) ? $_SESSION['gift_submit'] : array();
    $doscore = count($submit) > 0;
    $retval['status'] = 'success';
    $retval['scored'] = $doscore;
    $safe = array();
    $count = 1;
    $cumulative_score = 0;
    $cumulative_total = 0;
    // Filter out questions for the user-visible stuff
    foreach ($questions as $question) {
        $nq = new stdClass();
        if (!isset($question->question)) {
            continue;
        }
        if (!isset($question->type)) {
            continue;
        }
        if (!isset($question->code)) {
            continue;
        }
        $nq->question = $question->question;
        $nq->scored = $doscore;
        $q_code = $question->code;
        $nq->code = $q_code;
        $t = $question->type;
        $nq->type = $t;
        if (isset($question->name)) {
            $nq->name = $question->name;
        }
        if ($t == 'short_answer_question') {
            if (isset($submit[$q_code])) {
                $nq->value = $submit[$q_code];
            }
        }
        // Because Handlebars can't tell the difference between not set and false
        if ($t == 'true_false_question') {
            if (isset($submit[$q_code])) {
                $nq->value_true = $submit[$q_code] == 'T';
                $nq->value_false = $submit[$q_code] == 'F';
            }
        }
        // Score the questions that don't have answers
        $score = null;
        $correct = null;
        if ($doscore && $t == 'short_answer_question') {
            if (isset($submit[$q_code])) {
                $nq->value = $submit[$q_code];
                foreach ($question->parsed_answer as $answer) {
                    $ans = preg_replace('/\\s+/', '', $answer[1]);
                    $sub = preg_replace('/\\s+/', '', $submit[$q_code]);
                    if (strcasecmp($sub, $ans) == 0) {
                        $score = 1;
                        $correct = true;
                        break;
                    }
                }
            }
            if ($score === null) {
                $score = 0;
                $correct = false;
            }
        } else {
            if ($doscore && $t == 'true_false_question') {
                if (isset($submit[$q_code])) {
                    $ans = substr($question->answer, 0, 1);
                    $score = strtolower($submit[$q_code]) == strtolower($ans) ? 1 : 0;
                    $correct = $score == 1;
                } else {
                    $score = 0;
                    $correct = false;
                }
            }
        }
        if ($t == 'multiple_choice_question' && isset($question->parsed_answer) && is_array($question->parsed_answer)) {
            $answers = array();
            $value = false;
            if ($doscore) {
                $score = 0;
                $correct = false;
            }
            if (isset($submit[$q_code])) {
                $value = $submit[$q_code];
                $nq->value = $submit[$q_code];
            }
            foreach ($question->parsed_answer as $answer) {
                $ans = new stdClass();
                if (!is_array($answer)) {
                    continue;
                }
                if (count($answer) != 4) {
                    continue;
                }
                $expected = $answer[0];
                // An actual boolean
                $ans->text = $answer[1];
                $a_code = $answer[3];
                $ans->code = $a_code;
                if ($value == $a_code) {
                    $ans->checked = true;
                    if ($doscore && $expected) {
                        $correct = true;
                        $score = 1;
                    }
                }
                $answers[] = $ans;
            }
            $mt = new Mersenne_Twister($seed);
            $answers = $mt->shuffle($answers);
        }
        if ($t == 'multiple_answers_question' && isset($question->parsed_answer) && is_array($question->parsed_answer)) {
            $answers = array();
            $got = 0;
            $need = 0;
            $oneanswer = false;
            foreach ($question->parsed_answer as $answer) {
                $ans = new stdClass();
                if (!is_array($answer)) {
                    continue;
                }
                if (count($answer) != 4) {
                    continue;
                }
                $ans->text = $answer[1];
                $a_code = $answer[3];
                $expected = $answer[0];
                // An actual boolean
                $oneanswer = $oneanswer || isset($submit[$a_code]);
                $ans->checked = isset($submit[$a_code]);
                $actual = isset($submit[$a_code]) ? ($submit[$a_code] == 'true') === $expected : false;
                if ($actual === $expected) {
                    $got++;
                }
                $need++;
                $ans->code = $a_code;
                if ($doscore) {
                    $ans->correct = $actual == $expected;
                }
                $answers[] = $ans;
            }
            if ($doscore) {
                $correct = $got == $need;
                if ($correct || $oneanswer) {
                    $score = $correct + 0;
                } else {
                    $score = 0;
                }
            }
            $mt = new Mersenne_Twister($seed);
            $nq->answers = $mt->shuffle($answers);
        }
        if ($correct !== null) {
            $nq->correct = $correct;
        }
        if ($score !== null) {
            $nq->score = $score;
            $cumulative_score += $score;
            $cumulative_total += 1;
            // $nq->cumulative_total = $cumulative_total;
            // $nq->cumulative_score = $cumulative_score;
        }
        $nq->count = $count;
        $count++;
        $safe[] = $nq;
    }
    $retval["questions"] = $safe;
    $retval["submit"] = $submit;
    if ($doscore) {
        if ($cumulative_total == 0) {
            $retval["score"] = 0;
        } else {
            $retval["score"] = $cumulative_score / $cumulative_total;
        }
    }
    return $retval;
}