function loadTestDefinition(array &$average = null)
{
    $start = microtime();
    $phpDoc = new PhpDocument();
    $phpDoc->load(dirname(__FILE__) . '/../../test/samples/custom/php/linear_4_items.php');
    if (is_null($average) === false) {
        spentTime($start, microtime(), $average);
    }
    return $phpDoc->getDocumentComponent();
}
$templates = array('match_correct', 'map_response', 'map_response_point');
$xmlTimings = array('match_correct' => array(), 'map_response' => array(), 'map_response_point' => array());
$phpTimings = array('match_correct' => array(), 'map_response' => array(), 'map_response_point' => array());
$iterations = 100;
foreach ($templates as $t) {
    for ($i = 0; $i < $iterations; $i++) {
        // --- XML
        $start = microtime();
        $xmlDoc = new XmlDocument('2.1');
        $xmlDoc->load(dirname(__FILE__) . $basePath . $t . '.xml');
        $end = microtime();
        $xmlTimings[$t][] = spentTime($start, $end);
        // --- PHP
        $start = microtime();
        $phpDoc = new PhpDocument();
        $phpDoc->load(dirname(__FILE__) . $basePath . $t . '.php');
        $end = microtime();
        $phpTimings[$t][] = spentTime($start, $end);
    }
}
foreach ($templates as $t) {
    // compute arithmetic mean.
    $meanXml = 0;
    foreach ($xmlTimings[$t] as $v) {
        $meanXml += $v;
    }
    $meanXml = $meanXml / $iterations;
    // compute arithmetic mean.
    $meanPhp = 0;
    foreach ($phpTimings[$t] as $v) {
        $meanPhp += $v;
Exemplo n.º 3
0
 /**
  * Retrieve the Test Definition the test session is built from as an AssessmentTest object. 
  * 
  * @param string $qtiTestCompilation (e.g. <i>'http://sample/first.rdf#i14363448108243883-|http://sample/first.rdf#i14363448109065884+'</i>)
  * 
  * @return AssessmentTest The AssessmentTest object the current test session is built from.
  */
 public static function getTestDefinition($qtiTestCompilation)
 {
     $directoryIds = explode('|', $qtiTestCompilation);
     $dirPath = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryIds[0])->getPath();
     $testFilePath = $dirPath . TAOQTITEST_COMPILED_FILENAME;
     common_Logger::d("Loading QTI-PHP file at '{$testFilePath}'.");
     $doc = new PhpDocument();
     $doc->load($testFilePath);
     return $doc->getDocumentComponent();
 }
Exemplo n.º 4
0
 public function testLoadInteractionMixSaschsen()
 {
     $xmlDoc = new XmlDocument('2.1');
     $xmlDoc->load(self::samplesDir() . 'ims/tests/interaction_mix_sachsen/interaction_mix_sachsen.xml');
     $phpDoc = new PhpDocument();
     $phpDoc->setDocumentComponent($xmlDoc->getDocumentComponent());
     $file = tempnam('/tmp', 'qsm');
     $phpDoc->save($file);
     $phpDoc = new PhpDocument();
     $phpDoc->load($file);
     $this->assertEquals('InteractionMixSachsen_1901710679', $phpDoc->getDocumentComponent()->getIdentifier());
     unlink($file);
     $this->assertFalse(file_exists($file));
 }
Exemplo n.º 5
0
 /**
  * Execute the ResponseProcessing according to the current context.
  *
  * The following sub-types of ProcessingException may be thrown:
  *
  * * RuleProcessingException: If a ResponseRule in the ResponseProcessing produces an error OR if the ExitResponse rule is invoked. In this last case, a specific exception code will be produced to deal with the situation accordingly.
  * * ExpressionProcessingException: If an Expression within a ResponseRule produces an error.
  * * ResponseProcessingException: If there is a problem with the response processing template processing bound to the ResponseProcessing.
  *
  * @throws \qtism\runtime\common\ProcessingException
  */
 public function process()
 {
     // @todo Figure out how to provide a way to the ResponseProcessingEngine to know the folder where to seek for templateLocation, which is a relative URI.
     $responseProcessing = $this->getComponent();
     $template = $responseProcessing->getTemplate();
     $templateLocation = $responseProcessing->getTemplateLocation();
     if (count($responseProcessing->getResponseRules()) > 0) {
         // Always prefer the embedded rules.
         $rules = $responseProcessing->getResponseRules();
     } else {
         $finalTemplateFile = '';
         if (empty($template) === false) {
             // try to locate the template file thanks to the given mapping.
             $mapping = $this->getTemplateMapping();
             if (isset($mapping[$template])) {
                 $finalTemplateFile = $mapping[$template];
             }
         }
         if (empty($finalTemplateFile) === true && empty($templateLocation) === false) {
             // The template could not be resolved using the mapping.
             // Try to use template location.
             if (@is_readable($templateLocation) === true) {
                 $finalTemplateFile = $templateLocation;
             }
         }
         if (empty($finalTemplateFile) === true) {
             $msg = "The template file could not be found: template='{$template}', templateLocation='{$templateLocation}'.";
             throw new ResponseProcessingException($msg, $this, ResponseProcessingException::TEMPLATE_NOT_FOUND);
         }
         // Open the file and retrieve the rules.
         $this->trace("loading response processing template '{$finalTemplateFile}'");
         $php = new PhpDocument();
         $php->load($finalTemplateFile);
         $rules = $php->getDocumentComponent()->getResponseRules();
         $this->trace(count($rules) . " responseRule(s) extracted from the response processing template");
     }
     try {
         foreach ($rules as $rule) {
             $engine = new RuleEngine($rule, $this->getContext());
             $engine->process();
             $this->trace($rule->getQtiClassName() . ' executed');
         }
     } catch (RuleProcessingException $e) {
         if ($e->getCode() !== RuleProcessingException::EXIT_RESPONSE) {
             throw $e;
         } else {
             $this->trace('Termination of response processing.');
         }
     }
 }
 /**
  * Retrieve the Test Definition the test session is built
  * from as an AssessmentTest object. This method
  * also retrieves the compilation directory.
  * 
  * @return AssessmentTest The AssessmentTest object the current test session is built from.
  */
 protected function retrieveTestDefinition()
 {
     $directories = array('private' => null, 'public' => null);
     $directoryIds = explode('|', $this->getRequestParameter('QtiTestCompilation'));
     $directories['private'] = $this->getDirectory($directoryIds[0]);
     $directories['public'] = $this->getDirectory($directoryIds[1]);
     $this->setCompilationDirectory($directories);
     $dirPath = $directories['private']->getPath();
     $testFilePath = $dirPath . TAOQTITEST_COMPILED_FILENAME;
     common_Logger::d("Loading QTI-PHP file at '{$testFilePath}'.");
     $doc = new PhpDocument();
     $doc->load($testFilePath);
     $this->setTestDefinition($doc->getDocumentComponent());
 }