Skip to content

Commit

Permalink
Dev: statistics, fix for text questions and single choice questions
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Feb 23, 2016
1 parent 3a41638 commit f8ce4c7
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 161 deletions.
63 changes: 45 additions & 18 deletions application/controllers/admin/statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ function graph()
*/
public function simpleStatistics($surveyid)
{
$usegraph=1;
$iSurveyId = sanitize_int($surveyid);
$aData['surveyid'] = $iSurveyId;
$showcombinedresults = 0;
Expand All @@ -685,26 +686,54 @@ public function simpleStatistics($surveyid)
foreach($rows as $row)
{
$type=$row['type'];
if($type=="M" || $type=="P" || $type=="T" || $type=="S" || $type=="Q" || $type=="R" || $type=="|" || $type=="" || $type=="N" || $type=="K" || $type=="D")
if($type=="M" || $type=="P" || $type=="T" || $type=="S" || $type=="R" || $type=="|" || $type=="" || $type=="N" || $type=="K" || $type=="D")
{
$summary[] = $type.$iSurveyId.'X'.$row['gid'].'X'.$row['qid'];
}
if($type=="A")
switch ( $type )
{
$qid = $row['qid'];
$results = Question::model()->getQuestionsForStatistics('title, question', "parent_qid='$qid' AND language = '{$language}'", 'question_order');
//$counter2=0;

//check all the results
foreach($results as $result)
{
$result = array_values($result);
$summary[] = $iSurveyId.'X'.$row['gid'].'X'.$row['qid'].$result[0];
}
}
else // single question
{
$summary[] = $iSurveyId.'X'.$row['gid'].'X'.$row['qid'];
case "A":
$qid = $row['qid'];
$results = Question::model()->getQuestionsForStatistics('title, question', "parent_qid='$qid' AND language = '{$language}'", 'question_order');
//$counter2=0;

//check all the results
foreach($results as $result)
{
$result = array_values($result);
$summary[] = $iSurveyId.'X'.$row['gid'].'X'.$row['qid'].$result[0];
}
break;

/*
* all "free text" types (T, U, S) get the same prefix ("T")
*/
case "T": // Long free text
case "U": // Huge free text
//$usegraph=0;
break;

case "Q": // Multiple Short Text
$qid = $row['qid'];
//get subqestions
$results = Question::model()->getQuestionsForStatistics('title as code, question as answer', "parent_qid='$qid' AND language = '{$language}'", 'question_order');
//loop through all answers
foreach($results as $result)
{
$result = array_values($result);
$summary[] = 'Q'.$iSurveyId.'X'.$row['gid'].'X'.$row['qid'].$result[0];
}

break;

case "S":
$summary[] = 'T'.$iSurveyId.'X'.$row['gid'].'X'.$row['qid'];
break;

default:
$usegraph=1;
$summary[] = $iSurveyId.'X'.$row['gid'].'X'.$row['qid'];
break;
}
}

Expand All @@ -717,13 +746,11 @@ public function simpleStatistics($surveyid)
$aData['showtextinline'] = $showtextinline;

//Show Summary results
$usegraph=1;
$aData['usegraph'] = $usegraph;
$outputType = 'html';
$statlang=returnGlobal('statlang');
$statisticsoutput .= $helper->generate_simple_statistics($surveyid,$summary,$summary,$usegraph,$outputType,'DD',$statlang);

$aData['usegraph'] = 1;
$aData['sStatisticsLanguage']=$statlang;
$aData['output'] = $statisticsoutput;
$aData['summary'] = $summary;
Expand Down
152 changes: 21 additions & 131 deletions application/helpers/admin/statistics_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1614,22 +1614,17 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
$ColumnName_RM=array();
foreach ($outputs['alist'] as $al)
{
//picks out answer list ($outputs['alist']/$al)) that come from the multiple list above
if (isset($al[2]) && $al[2])
{
//handling for "other" option
if ($al[0] == gT("Other"))
{
if($outputs['qtype']=='!' || $outputs['qtype']=='L')
{
// It is better for single choice question types to filter on the number of '-oth-' entries, than to
// just count the number of 'other' values - that way with failing Javascript the statistics don't get messed up
/* This query selects a count of responses where "other" has been selected */
$query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ".Yii::app()->db->quoteColumnName(substr($al[2],0,strlen($al[2])-5))."='-oth-'";
}
else
{
//get data - select a count of responses where no answer is provided
$query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ";
$query .= ($sDatabaseType == "mysql")? Yii::app()->db->quoteColumnName($al[2])." != ''" : "NOT (".Yii::app()->db->quoteColumnName($al[2])." LIKE '')";
}
Expand Down Expand Up @@ -1885,58 +1880,6 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
} //end while (data available)

} //end if -> noncompleted checked

//noncompleted is NOT checked
else
{
/*
//calculate total number of incompleted records
$TotalIncomplete = $results - $TotalCompleted;
//output
if ((incompleteAnsFilterState() != "complete"))
{
$fname=gT("Not completed or Not displayed");
}
else
{
$fname=gT("Not displayed");
}
//we need some data
if ($results > 0)
{
//calculate percentage
$gdata[] = ($TotalIncomplete/$results)*100;
}
//no data :(
else
{
$gdata[] = "N/A";
}
//put data of incompleted records into array
$grawdata[]=$TotalIncomplete;
//put question title ("Not completed") into array
$label[]= $fname;
//put the code ("Not completed") into the array
$justcode[]=$fname;
//edit labels and put them into another array
if ((incompleteAnsFilterState() != "complete"))
{
$lbl[wordwrap(flattenText(gT("Not completed or Not displayed")), 20, "\n")] = $TotalIncomplete;
}
else
{
$lbl[wordwrap(flattenText(gT("Not displayed")), 20, "\n")] = $TotalIncomplete;
}
*/
} //end else -> noncompleted NOT checked

}

// For multi question type, we have to check non completed with ALL sub question set to NULL
Expand Down Expand Up @@ -2013,6 +1956,7 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
$aData['outputs'] = (isset($outputs))?$outputs:'';
$aData['bSum'] = (isset($bSum))?$bSum:'';
$aData['bAnswer'] = (isset($bAnswer))?$bAnswer:'';
$aData['usegraph'] = $usegraph;

$statisticsoutput = Yii::app()->getController()->renderPartial('/admin/export/generatestats/simplestats/_statisticsoutput_header', $aData, true);

Expand Down Expand Up @@ -2249,21 +2193,6 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
}
switch($outputType)
{
case 'xls':
$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,gT("Arithmetic mean"));
$this->sheet->writeNumber($this->xlsRow,1,$am);
$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,gT("Standard deviation"));
$this->sheet->writeNumber($this->xlsRow,1,$stddev);
break;

case 'pdf':

$tablePDF[] = array(gT("Arithmetic mean"),$am,'','');
$tablePDF[] = array(gT("Standard deviation"),$stddev,'','');
break;

case 'html':
//calculate standard deviation
$aData['am'] = $am;
Expand All @@ -2278,61 +2207,6 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
}
}

if($outputType=='pdf') //XXX TODO PDF
{
//$tablePDF = array();
$tablePDF = array_merge_recursive($tablePDF, $footPDF);
$this->pdf->headTable($headPDF,$tablePDF);
//$this->pdf->tableintopdf($tablePDF);

// if(isset($footPDF))
// foreach($footPDF as $foot)
// {
// $footA = array($foot);
// $this->pdf->tablehead($footA);
// }
if (isset($headPDF2))
{
$this->pdf->headTable($headPDF2,$tablePDF2);
}
}

if($outputType=='xls' && (isset($headXLS) || isset($tableXLS)))
{
if (isset($headXLS))
{
$this->xlsRow++;
$this->xlsRow++;
foreach($headXLS as $aRow)
{
$this->xlsRow++;
$iColumn=0;
foreach ($aRow as $sValue)
{
$this->sheet->write($this->xlsRow,$iColumn,$sValue,$this->formatBold);
$iColumn++;
}
}
}
if (isset($tableXLS))
{
foreach($tableXLS as $aRow)
{
$this->xlsRow++;
$iColumn=0;
foreach ($aRow as $sValue)
{
$this->sheet->write($this->xlsRow,$iColumn,$sValue);
$iColumn++;
}
}

}
}


if ($outputType=='html') {
}

// _statisticsoutput_graphs.php

Expand Down Expand Up @@ -2379,6 +2253,10 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s

}
}
else
{

}


if(isset($aattr["statistics_graphtype"]))
Expand Down Expand Up @@ -2466,9 +2344,14 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
$statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/simplestats/_statisticsoutput_graphs', $aData, true);

}
$statisticsoutput .= "</div><br /> \n";
else
{
$statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/simplestats/_statisticsoutput_nograph', array(), true);
}
$statisticsoutput .= "</div>\n";
}


return array("statisticsoutput"=>$statisticsoutput, "pdf"=>$this->pdf, "astatdata"=>$astatdata);
}

Expand Down Expand Up @@ -3742,17 +3625,24 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show='all',
$aData['surveyid'] = $surveyid;
$aData['sql'] = $sql;

$sOutputHTML = "";
$sOutputHTML = '<div class="row">';

//let's run through the survey
$runthrough=$summary;

//START Chop up fieldname and find matching questions

//loop through all selected questions
$count=0;
foreach ($runthrough as $rt)
{

$count=$count+1;
if($count==3)
{
$sOutputHTML .= '</div>';
$sOutputHTML .= '<div class="row">';
$count=0;
}
////Step 1: Get information about this response field (SGQA) for the summary
$outputs=$this->buildOutputList($rt, $language, $surveyid, $outputType, $sql, $sLanguageCode);
//$sOutputHTML .= $outputs['statisticsoutput']; // Nothing interesting for us in this output
Expand All @@ -3771,7 +3661,7 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show='all',
unset($display);
}


$sOutputHTML .= '</div>';

$sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
if ($sGoogleMapsAPIKey!='')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
*/
?>

<div class="col-sm-4">
<h4><?php echo $outputs['qquestion'];?></h4>

<div class="col-sm-4" style="margin-top: 2em;margin-bottom: 2em;">
<h4><?php echo $outputs['qtitle'];?></h4>
<?php /*
<table class='statisticstable table table-bordered'>
<thead>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* This view render the 'no simple graph' message
*/
?>
<div class="row">
<div class="col-sm-12">
<div class="alert alert-warning" role="alert" style="height: 300px;">
<?php eT('No simple graph for this question type');?>
</div>
</div>
</div>

0 comments on commit f8ce4c7

Please sign in to comment.