Skip to content

Commit

Permalink
Fixed issue Dynamic Relevance Unit tests do not work
Browse files Browse the repository at this point in the history
Dev Removed obsolete EM debugging code
  • Loading branch information
TMSWhite committed Feb 29, 2012
1 parent c1c1ee1 commit b1933d2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 113 deletions.
136 changes: 30 additions & 106 deletions classes/eval/LimeExpressionManager.php
Expand Up @@ -12,7 +12,6 @@
define('LEM_DEBUG_VALIDATION_SUMMARY',2); // also includes SQL error messages
define('LEM_DEBUG_VALIDATION_DETAIL',4);
define('LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB',8);
define('LEM_DEBUG_TRANSLATION_DETAIL',16);
define('LEM_PRETTY_PRINT_ALL_SYNTAX',32);

class LimeExpressionManager {
Expand All @@ -35,8 +34,6 @@ class LimeExpressionManager {
private $qcode2sgq; // maps name of the variable to the SGQ name
private $alias2varName; // JavaScript array of mappings of aliases to the JavaScript variable names
private $varNameAttr; // JavaScript array of mappings of canonical JavaScript variable name to key attributes.
private $pageTailoringLog; // Debug log of tailorings done on this page
private $surveyLogicFile; // Shows current configuration and data from most recent $fieldmap

private $qans; // array of answer lists indexed by qid
private $groupId2groupSeq; // map of gid to 0-based sequence number of groups
Expand Down Expand Up @@ -1767,7 +1764,6 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
$this->knownVars = array(); // mapping of VarName to Value
$this->qcode2sgqa = array();
$this->tempVars = array();
$this->debugLog = array(); // array of mappings among values to confirm their accuracy
$this->qid2code = array(); // List of codes for each question - needed to know which to NULL if a question is irrelevant
$this->jsVar2qid = array();
$this->qcode2sgq = array();
Expand Down Expand Up @@ -2306,20 +2302,6 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
. ",'qseq':" . $questionSeq
.$ansList."}";

if (($this->debugLevel & LEM_DEBUG_TRANSLATION_DETAIL) == LEM_DEBUG_TRANSLATION_DETAIL)
{
$this->debugLog[] = array(
'sgqa' => $sgqa,
'type' => $type,
'varname' => $varName,
'jsName_on'=> $jsVarName_on,
'jsName' => $jsVarName,
'question' => $question,
'readWrite' => $readWrite,
'relevance' => $relevance,
'hidden' => $hidden,
);
}
}

$this->q2subqInfo = $q2subqInfo;
Expand Down Expand Up @@ -2350,20 +2332,6 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
'readWrite'=>'N',
);

if (($this->debugLevel & LEM_DEBUG_TRANSLATION_DETAIL) == LEM_DEBUG_TRANSLATION_DETAIL)
{
$this->debugLog[] = array(
'sgqa' => $key,
'type' => ' ',
'varname' => ' ',
'jsName_on' => ' ',
'jsName' => ' ',
'question' => ' ',
'readWrite'=>'N',
'relevance'=>'',
'hidden'=>'',
);
}
}
}
else
Expand Down Expand Up @@ -2412,25 +2380,7 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
);

$this->runtimeTimings[] = array(__METHOD__ . ' - process fieldMap',(microtime(true) - $now));
if (($this->debugLevel & LEM_DEBUG_TRANSLATION_DETAIL) == LEM_DEBUG_TRANSLATION_DETAIL)
{
$debugLog_html = "<table border='1'>";
$debugLog_html .= "<tr><th>Code</th><th>Type</th><th>VarName</th><th>CodeVal</th><th>DisplayVal</th><th>JSname</th><th>Writable?</th><th>Set On This Page?</th><th>Relevance</th><th>Hidden</th><th>Question</th></tr>";
foreach ($this->debugLog as $t)
{
$debugLog_html .= "<tr><td>" . $t['sgqa']
. "</td><td>" . $t['type']
. "</td><td>" . $t['varname']
. "</td><td>" . $t['jsName']
. "</td><td>" . $t['readWrite']
. "</td><td>" . $t['relevance']
. "</td><td>" . $t['hidden']
. "</td><td>" . $t['question']
. "</td></tr>";
}
$debugLog_html .= "</table>";
$this->surveyLogicFile = $debugLog_html;
}

usort($this->questionSeq2relevance,'cmpQuestionSeq');
$this->numQuestions = count($this->questionSeq2relevance);
$this->numGroups = count($this->groupId2groupSeq);
Expand Down Expand Up @@ -2597,13 +2547,6 @@ static function ProcessString($string, $questionNum=NULL, $replacementFields=arr
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
}

if (($LEM->debugLevel & LEM_DEBUG_TRANSLATION_DETAIL) == LEM_DEBUG_TRANSLATION_DETAIL)
{
$varsUsed = $LEM->em->GetJSVarsUsed();
if (is_array($varsUsed) and count($varsUsed) > 0) {
$LEM->pageTailoringLog .= '<tr><td>' . $LEM->groupNum . '</td><td>' . $string . '</td><td>' . $LEM->em->GetLastPrettyPrintExpression() . '</td><td>' . $result . "</td></tr>\n";
}
}

return $result;
}
Expand Down Expand Up @@ -2858,8 +2801,6 @@ static function StartProcessingPage($allOnOnePage=false,$rooturl=NULL)
$LEM->pageRelevanceInfo=array();
$LEM->pageTailorInfo=array();
$LEM->allOnOnePage=$allOnOnePage;
$LEM->pageTailoringLog='';
$LEM->surveyLogicFile='';
$LEM->processedRelevance=false;
if (!is_null($rooturl)) {
$LEM->surveyOptions['rooturl'] = $rooturl;
Expand All @@ -2868,10 +2809,6 @@ static function StartProcessingPage($allOnOnePage=false,$rooturl=NULL)

// $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));

if (($LEM->debugLevel & LEM_DEBUG_TRANSLATION_DETAIL) == LEM_DEBUG_TRANSLATION_DETAIL)
{
$LEM->pageTailoringLog .= '<tr><th>Source</th><th>Pretty Print</th><th>Result</th></tr>';
}
$LEM->initialized=true;
}

Expand Down Expand Up @@ -3045,7 +2982,7 @@ static function NavigateBackwards()
$result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq);
$message .= $result['message'];
$gRelInfo = $LEM->gRelInfo[$LEM->currentGroupSeq];
$grel = $gRelInfo['result'];
$grel = $gRelInfo['result'];

if (!$grel || !$result['relevant'] || $result['hidden'])
{
Expand Down Expand Up @@ -3208,7 +3145,7 @@ static function NavigateForwards($force=false) {
$updatedValues = array_merge($updatedValues,$result['updatedValues']);
$gRelInfo = $LEM->gRelInfo[$LEM->currentGroupSeq];
$grel = $gRelInfo['result'];

if ($grel && !is_null($result) && ($result['mandViolation'] || !$result['valid']))
{
// redisplay the current question
Expand Down Expand Up @@ -3265,7 +3202,7 @@ static function NavigateForwards($force=false) {
$message .= $result['message'];
$updatedValues = array_merge($updatedValues,$result['updatedValues']);
$gRelInfo = $LEM->gRelInfo[$LEM->currentGroupSeq];
$grel = $gRelInfo['result'];
$grel = $gRelInfo['result'];

if (!$grel || !$result['relevant'] || $result['hidden'])
{
Expand Down Expand Up @@ -3639,7 +3576,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
$message .= $result['message'];
$updatedValues = array_merge($updatedValues,$result['updatedValues']);
$gRelInfo = $LEM->gRelInfo[$LEM->currentGroupSeq];
$grel = $gRelInfo['result'];
$grel = $gRelInfo['result'];
if ($grel && ($result['mandViolation'] || !$result['valid']))
{
// redisplay the current question
Expand Down Expand Up @@ -3703,7 +3640,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
$updatedValues = array_merge($updatedValues,$result['updatedValues']);
$gRelInfo = $LEM->gRelInfo[$LEM->currentGroupSeq];
$grel = $gRelInfo['result'];

if (!$preview && (!$grel || !$result['relevant'] || $result['hidden']))
{
// then skip this question
Expand Down Expand Up @@ -4816,8 +4753,6 @@ static function GetDebugTimingMessage()
static function FinishProcessingPage()
{
$LEM =& LimeExpressionManager::singleton();
$_SESSION['EM_pageTailoringLog'] = $LEM->pageTailoringLog;
$_SESSION['EM_surveyLogicFile'] = $LEM->surveyLogicFile;

$totalTime = 0.;
if ((($LEM->debugLevel & LEM_DEBUG_TIMING) == LEM_DEBUG_TIMING) && count($LEM->runtimeTimings)>0) {
Expand Down Expand Up @@ -4864,30 +4799,6 @@ static function FinishProcessingPage()
$_SESSION['LEMsingleton']=serialize($LEM);
}

/**
* Show the HTML for the logic file if $debugLevel has LEM_DEBUG_TRANSLATION_DETAIL bit set
* @return <type>
*/
static function ShowLogicFile()
{
if (isset($_SESSION['EM_surveyLogicFile'])) {
return $_SESSION['EM_surveyLogicFile'];
}
return '';
}

/**
* Show the HTML of the tailorings on this page if $debugLevel has LEM_DEBUG_TRANSLATION_DETAIL bit set
* @return <type>
*/
static function ShowPageTailorings()
{
if (isset($_SESSION['EM_pageTailoringLog'])) {
return $_SESSION['EM_pageTailoringLog'];
}
return '';
}

/*
* Generate JavaScript needed to do dynamic relevance and tailoring
* Also create list of variables that need to be declared
Expand Down Expand Up @@ -4994,8 +4905,8 @@ static function GetRelevanceAndTailoringJavaScript()
{
$gid_qidList[$arg['gid']] = array();
}
$gid_qidList[$arg['gid']][$arg['qid']] = '0'; // means the qid is within this gid, but may not have a relevance equation
$gid_qidList[$arg['gid']][$arg['qid']] = '0'; // means the qid is within this gid, but may not have a relevance equation


// Now check whether any sub-question validation needs to be performed
$subqValidations = array();
Expand Down Expand Up @@ -5032,7 +4943,7 @@ static function GetRelevanceAndTailoringJavaScript()
continue;
}
$relevance = ($relevance == '') ? '1' : $relevance;

$relParts[] = "\nif (" . $relevance . ")\n{\n";
////////////////////////////////////////////////////////////////////////
// DO ALL ARRAY FILTERING FIRST - MAY AFFECT VALIDATION AND TAILORING //
Expand Down Expand Up @@ -5307,13 +5218,13 @@ static function GetRelevanceAndTailoringJavaScript()
if (count($qrelGIDs) > 0)
{
$qrelJS .= " if(" . implode(' || ', $qrelGIDs) . "){\n ;\n }\n else";
}
}
$qrelJS .= " if (typeof sgqa !== 'undefined' && !LEMregexMatch('/ java' + sgqa + ' /', UsesVars)) {\n return;\n }\n";
$qrelJS .= implode("",$relParts);
$qrelJS .= "}\n";
$relEqns[] = $qrelJS;

$gid_qidList[$arg['gid']][$arg['qid']] = '1'; // means has an explicit LEMrel() function
$gid_qidList[$arg['gid']][$arg['qid']] = '1'; // means has an explicit LEMrel() function
}
}

Expand Down Expand Up @@ -5346,7 +5257,7 @@ static function GetRelevanceAndTailoringJavaScript()
$jsParts[] = " LEMrel" . $_qid . "(sgqa);\n";
}
}

$jsParts[] = "}\nelse {\n";
$jsParts[] = " $('#group-" . $gr['gid'] . "').hide();\n";
$jsParts[] = " if ($('#relevanceG" . $gr['gid'] . "').val()=='1') { relChangeG" . $gr['gid'] . "=true; }\n";
Expand Down Expand Up @@ -5695,7 +5606,8 @@ static function UnitTestRelevance()
foreach(explode("\n",$tests) as $test)
{
$args = explode("~",$test);
$vars[$args[0]] = array('sgqa'=>$args[0], 'code'=>'', 'jsName'=>'java' . $args[0], 'jsName_on'=>'java' . $args[0], 'readWrite'=>'Y', 'type'=>'X', 'relevanceStatus'=>'1','gseq'=>1, 'qseq'=>$i);
$type = (($args[1]=='expr') ? '*' : ($args[1]=='message') ? 'X' : 'S');
$vars[$args[0]] = array('sgqa'=>$args[0], 'code'=>'', 'jsName'=>'java' . $args[0], 'jsName_on'=>'java' . $args[0], 'readWrite'=>'Y', 'type'=>$type, 'relevanceStatus'=>'1', 'gid'=>1, 'gseq'=>1, 'qseq'=>$i, 'qid'=>$i);
$varSeq[] = $args[0];
$testArgs[] = $args;
$LEM->questionId2questionSeq[$i] = $i;
Expand All @@ -5706,14 +5618,24 @@ static function UnitTestRelevance()
'qseq'=>$i,
'gseq'=>1,
'jsResultVar'=>'java' . $args[0],
'type'=>(($args[1]=='expr') ? '*' : ($args[1]=='message') ? 'X' : 'S'),
'type'=>$type,
'hidden'=>false,
'gid'=>1, // ($i % 3),
);
++$i;
}

$LEM->tempVars = $vars;
$LEM->knownVars = $vars; // this overwrites local values, so must set dirty flag when done with this function
$LEM->gRelInfo[1] = array(
'gid' => 1,
'gseq' => 1,
'eqn' => '',
'result' => 1,
'numJsVars' => 0,
'relevancejs' => '',
'relevanceVars' => '',
'prettyPrint'=> '',
);
$LEM->ProcessAllNeededRelevance();

// collect relevance
Expand All @@ -5731,6 +5653,7 @@ static function UnitTestRelevance()
$argInfo[] = array(
'num' => $i,
'name' => $jsVarName,
'sgqa' => $testArg[0],
'type' => $testArg[2],
'question' => $question,
'relevance' => $testArg[1],
Expand All @@ -5754,6 +5677,7 @@ static function UnitTestRelevance()
print <<< EOD
<script type='text/javascript'>
<!--
var LEMradix='.';
function checkconditions(value, name, type, evt_type)
{
if (typeof evt_type === 'undefined')
Expand Down Expand Up @@ -5790,10 +5714,10 @@ function checkconditions(value, name, type, evt_type)
{
case 'yesno':
case 'text':
print "<td><input type='text' id='" . $arg['name'] . "' value='' onchange='ExprMgr_process_relevance_and_tailoring(\"onchange\")'/></td>\n";
print "<td><input type='text' id='" . $arg['name'] . "' name='" . $arg['sgqa'] . "' value='' onchange='checkconditions(this.value, this.name, this.type)'/></td>\n";
break;
case 'message':
print "<input type='hidden' id='" . $arg['name'] . "' name='" . $arg['name'] . "' value=''/>\n";
print "<input type='hidden' id='" . $arg['name'] . "' name='" . $arg['sgqa'] . "' value=''/>\n";
break;
}
print "</tr>\n</table>\n";
Expand Down
4 changes: 0 additions & 4 deletions classes/eval/test/navigation_test.php
Expand Up @@ -45,7 +45,6 @@
<li><input type='checkbox' name='LEM_DEBUG_VALIDATION_DETAIL' id='LEM_DEBUG_VALIDATION_DETAIL' value='Y' checked="checked"/>Validation Detail (Validation Summary must also be checked to see detail)</li>
<li><input type='checkbox' name='LEM_PRETTY_PRINT_ALL_SYNTAX' id='LEM_PRETTY_PRINT_ALL_SYNTAX' value='Y' checked="checked"/>Pretty Print Syntax</li>
<li><input type='checkbox' name='LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB' id='LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB' value='Y'/>Log Syntax Errors to Database</li>
<li><input type='checkbox' name='LEM_DEBUG_TRANSLATION_DETAIL' id='LEM_DEBUG_TRANSLATION_DETAIL' value='Y'/>Translation Detail</li>
</ul></td>
</tr>
<tr><td colspan='2'><input type='submit'/></td></tr>
Expand All @@ -72,7 +71,6 @@
((isset($_POST['LEM_DEBUG_VALIDATION_SUMMARY']) && $_POST['LEM_DEBUG_VALIDATION_SUMMARY'] == 'Y') ? LEM_DEBUG_VALIDATION_SUMMARY : 0) +
((isset($_POST['LEM_DEBUG_VALIDATION_DETAIL']) && $_POST['LEM_DEBUG_VALIDATION_DETAIL'] == 'Y') ? LEM_DEBUG_VALIDATION_DETAIL : 0) +
((isset($_POST['LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB']) && $_POST['LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB'] == 'Y') ? LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB : 0) +
((isset($_POST['LEM_DEBUG_TRANSLATION_DETAIL']) && $_POST['LEM_DEBUG_TRANSLATION_DETAIL'] == 'Y') ? LEM_DEBUG_TRANSLATION_DETAIL : 0) +
((isset($_POST['LEM_PRETTY_PRINT_ALL_SYNTAX']) && $_POST['LEM_PRETTY_PRINT_ALL_SYNTAX'] == 'Y') ? LEM_PRETTY_PRINT_ALL_SYNTAX : 0)
);

Expand All @@ -94,10 +92,8 @@

while(true) {
$now = microtime(true);
// LimeExpressionManager::StartProcessingPage();
$result = LimeExpressionManager::NavigateForwards(true);
print $result['message'] . "<br/>";
// LimeExpressionManager::FinishProcessingGroup(); // move this internally? This is what is needed to save group data so visible to GetRelevanceAndTailoringJavaScript()
LimeExpressionManager::FinishProcessingPage();
// print LimeExpressionManager::GetRelevanceAndTailoringJavaScript();
if (($LEMdebugLevel & LEM_DEBUG_TIMING) == LEM_DEBUG_TIMING) {
Expand Down
2 changes: 0 additions & 2 deletions classes/eval/test/survey_logic_file.php
Expand Up @@ -66,7 +66,6 @@
<li><input type='checkbox' name='LEM_DEBUG_VALIDATION_DETAIL' id='LEM_DEBUG_VALIDATION_DETAIL' value='Y'/>Validation Detail (Validation Summary must also be checked to see detail)</li>
<li><input type='checkbox' name='LEM_PRETTY_PRINT_ALL_SYNTAX' id='LEM_PRETTY_PRINT_ALL_SYNTAX' value='Y' checked="checked"/>Pretty Print Syntax</li>
<li><input type='checkbox' name='LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB' id='LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB' value='Y'/>Log Syntax Errors to Database</li>
<li><input type='checkbox' name='LEM_DEBUG_TRANSLATION_DETAIL' id='LEM_DEBUG_TRANSLATION_DETAIL' value='Y'/>Translation Detail</li>
</ul></td>
</tr>
<tr><td colspan='2'><input type='submit'/></td></tr>
Expand All @@ -93,7 +92,6 @@
((isset($_POST['LEM_DEBUG_VALIDATION_SUMMARY']) && $_POST['LEM_DEBUG_VALIDATION_SUMMARY'] == 'Y') ? LEM_DEBUG_VALIDATION_SUMMARY : 0) +
((isset($_POST['LEM_DEBUG_VALIDATION_DETAIL']) && $_POST['LEM_DEBUG_VALIDATION_DETAIL'] == 'Y') ? LEM_DEBUG_VALIDATION_DETAIL : 0) +
((isset($_POST['LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB']) && $_POST['LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB'] == 'Y') ? LEM_DEBUG_LOG_SYNTAX_ERRORS_TO_DB : 0) +
((isset($_POST['LEM_DEBUG_TRANSLATION_DETAIL']) && $_POST['LEM_DEBUG_TRANSLATION_DETAIL'] == 'Y') ? LEM_DEBUG_TRANSLATION_DETAIL : 0) +
((isset($_POST['LEM_PRETTY_PRINT_ALL_SYNTAX']) && $_POST['LEM_PRETTY_PRINT_ALL_SYNTAX'] == 'Y') ? LEM_PRETTY_PRINT_ALL_SYNTAX : 0)
);

Expand Down
2 changes: 1 addition & 1 deletion group.php
Expand Up @@ -713,7 +713,7 @@
<script type='text/javascript'>
<!--\n";

echo "var LEMradix='" . $radix . "'\n";
echo "var LEMradix='" . $radix . "';\n";

print <<<END
function fixnum_checkconditions(value, name, type, evt_type)
Expand Down

0 comments on commit b1933d2

Please sign in to comment.