From af00b7a8813153bb6aab28c50e77d17a5f02d244 Mon Sep 17 00:00:00 2001 From: Kaleb Murphy Date: Wed, 8 Apr 2009 20:03:41 +0000 Subject: [PATCH] Survey summaries now use YUI datatables and charts for extra bling. --- docs/changelog/7.x.x.txt | 1 - ...import_survey_default-survey-summary.wgpkg | Bin 1161 -> 1255 bytes ...ot_import_survey_default-survey-take.wgpkg | Bin 0 -> 1203 bytes lib/WebGUI/Asset/Wobject/Survey.pm | 6 +- .../Asset/Wobject/Survey/ResponseJSON.pm | 55 ++++---- www/extras/wobject/Survey/administersurvey.js | 123 +++++++++++++++++- .../wobject/Survey/administersurvey/comm.js | 2 +- 7 files changed, 149 insertions(+), 38 deletions(-) create mode 100644 docs/upgrades/packages-7.7.3/root_import_survey_default-survey-take.wgpkg diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 829f6de64..54ab2d8c4 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,7 +4,6 @@ - Survey summaries now added. In the Survey edit, select quiz mode, and a summary will be shown to the user at the end of the survey. - fixed #10110: Matrix 2.0 - "Data Error" on Pending Product Listing Updates - rfe #9965: matrix/pls reverse dropped event variables - 7.7.2 - fixed #10056: YUI javascripts included while adminOff (BNC) - fixed a bug that required you to hit "update cart" before the checkout diff --git a/docs/upgrades/packages-7.7.3/root_import_survey_default-survey-summary.wgpkg b/docs/upgrades/packages-7.7.3/root_import_survey_default-survey-summary.wgpkg index 5037d556a2b910e3d8ad855d49b65a401be956c8..8f43ba00960474e8cb74ca9167b0c65b4a4c9df3 100644 GIT binary patch literal 1255 zcmVM;7_YNuQ66dlluqn_YdWdAsg@ow57!s1KCzx_=qd@*NV-ar(ZQgMM7q=|g= z+wb3-rBv{g2t|q1t42+0MuK2P;^VDeZFZYRSql;@)#+`@1xSyK4a<_G6vHi3#(y)- z!i35ti7Q)1HlHYq`NlYPDuLWGo=W=A9p5k_t|bxUcozt{RRW(A98dA$p&^!%C~G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--git a/docs/upgrades/packages-7.7.3/root_import_survey_default-survey-take.wgpkg b/docs/upgrades/packages-7.7.3/root_import_survey_default-survey-take.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..7f00c0c5945f89188358c1cad95ca807fc4b706b GIT binary patch literal 1203 zcmV;k1WfxMiwFP!000001MOFBZz4Ak=JWlE6`xwEWOoTKfpU?qcS(bKM6@AI)zY5K z+OQ5@du4keTy_7wV|!s2F6gRDwo;|61h(w)Joe0Z=J83b`Y#BAZo6HpK^t^}qV;xP zPz%Gb(`^RLAPj3>7}^GwRR3j4BMDnWDT-op9Pdl>=5RrNIMe=5KD+C%_;0y>`{Z5; z{!C{8?VVPu@Vh}Xage*e(>^^t@PDh>>D0Xc#EMn<|KypBSFxJEUx63uN(+e=r0(^- zKmPpA4y970L~2Tu8MR_YGLi&of`8bU(fVoK3Y!Url)iXKg@oBRb`8%M+fBnQ(^h{y z&1Q_MnBZb9C+j=Pu~=KBK{25=T%?MAu1>5uk++J-AwJv)dC(GF5rijbVHeg1jPj)? z341+-lWrIRbfTwqPj6BJV;YwDky0=cOEQO%zb=dt_01-u{w$*m`*Xpya{rBl@)HpM z_Ip_1pHJnKKL-L*iU5RKQV#zpvArkb_$retvN3vgyEQv5Y;19JGvc%R(P;Dw#y3BA z^?KZ5;qN!Ybs?KcX3Z^y&^}F!w{rj=lR3(mZaBP#MoUtxqw0!cOt@VfmdD3ZXkq+t z==y~eSvtfQm}OxdNz!@XR-VRRPR0tp$ghX_~4) zBE$&C2<(-2ssbX6fU&fnw~ZOms46UsG*Tjy5%G&|RbYlf_~!2@fVnu^Z}7DjD2kDU z#Oay_d4RG-jX@Es7S|Y1qZxCiw7sK%Ps|aLDEg83uBi${F^VBQxaK$r6q<1H2 zQ}?c@Sdnd%mk=mVv%Fr!wmKRWwi=I-j=dFP8F@Xh)nu7F+{z- zmF!ZAWQ-)l|6xT17DRHAS1$;EU}1g3Kew9gR7uzA{RHsQ_JE)X@<%%Qz=T*7mq;+g7Oh~>oKS4tdR>=sj0 z8M-D<5UK`%n#f~Id zQ3cj`x8+igxrM4Rik92JDV;~fVm;)SLMF}{r6~?^V`-K}c5d|d-AH&OH>nW9 z(IV%gcT0L34OresponseJSON->showSummary(); my $out = $self->processTemplate( $summary, $self->get('surveySummaryTemplateId') ); - return $out; + + return ($summary,$out); # return $self->session->style->process( $out, $self->get('styleTemplateId') ); } #------------------------------------------------------------------- @@ -1191,7 +1192,8 @@ sub www_loadQuestions { $self->session->log->debug('Response surveyEnd, so calling surveyEnd'); if ( $self->get('quizModeSummary') ) { if(! $self->session->form->param('shownsummary')){ - my $json = to_json( { type => 'summary', summary => $self->getSummary() }); + my ($summary,$html) = $self->getSummary(); + my $json = to_json( { type => 'summary', summary => $summary, html => $html }); return $json; } } diff --git a/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm index 8ee6c40db..36894d0d8 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/ResponseJSON.pm @@ -1074,9 +1074,8 @@ sub showSummary{ return if(! $responses); - my ($sectionIndex, $questionIndex, $answerIndex) = (-1, -1, -1); - my ($currentSection,$currentQuestion) = (-1, -1); - + my ($sectionIndex, $responseIndex) = (-1, 1); + my ($currentSection,$currentQuestion) = (-1,-1); ($summaries->{totalCorrect},$summaries->{totalIncorrect}) = (0,0); for my $response (@$responses){ @@ -1090,62 +1089,54 @@ sub showSummary{ if($currentSection != $response->{address}->[0]){ $summaries->{totalSections}++; $sectionIndex++; - $questionIndex = -1; - $answerIndex = -1; - $currentQuestion = -1; + $responseIndex = -1; $currentSection = $response->{address}->[0]; - _loadSectionIntoSummary(\%{$summaries->{sections}->[$sectionIndex]},$response); } if($currentQuestion != $response->{address}->[1]){ $summaries->{totalQuestions}++; - $questionIndex++; - $answerIndex = -1; - $currentQuestion = $response->{address}->[1]; - _loadQuestionIntoSummary(\%{$summaries->{sections}->[$sectionIndex]->{questions}->[$questionIndex]},$response); } - $answerIndex++; - _loadAnswerIntoSummary(\%{$summaries->{sections}->[$sectionIndex]->{questions}->[$questionIndex]->{answers}->[$answerIndex]}, + _loadSectionIntoSummary(\%{$summaries->{sections}->[$sectionIndex]}, $response); + $responseIndex++; + _loadResponseIntoSummary(\%{$summaries->{sections}->[$sectionIndex]->{responses}->[$responseIndex]}, $response, $self->survey->{multipleChoiceTypes}); } return $summaries; } -sub _loadAnswerIntoSummary{ +sub _loadResponseIntoSummary{ my $node = shift; my $response = shift; my $types = shift; - $node->{id} = $response->{address}->[2] + 1; + $node->{"Question ID"} = $response->{address}->[1] + 1; + $node->{"Question Text"} = $response->{questionText}; + $node->{"Answer ID"} = $response->{address}->[2] + 1; if($response->{isCorrect}){ - $node->{iscorrect} = 1; - $node->{score} = $response->{value}; + $node->{Correct} = "Y"; + $node->{Score} = $response->{value}; }else{ - $node->{iscorrect} = 0; - $node->{score} = 0; + $node->{Correct} = "N"; + $node->{Score} = 0; } - $node->{text} = $response->{answerText}; + $node->{"Answer Text"} = $response->{answerText}; #test if it is a multiple choide type if($types->{$response->{questionType}}){ - $node->{value} = $response->{value}; + $node->{Value} = $response->{value}; }else{ - $node->{value} = $response->{recordedValue}; + $node->{Value} = $response->{recordedValue}; } } -sub _loadQuestionIntoSummary{ - my $node = shift; - my $response = shift; - $node->{id} = $response->{address}->[1] + 1; - $node->{text} = $response->{questionText}; -} sub _loadSectionIntoSummary{ my $node = shift; my $response = shift; $node->{id} = $response->{address}->[0] + 1; - $node->{inCorrect} = 0 if(!defined $node->{section}->{inCorrect}); - $node->{score} = 0 if(!defined $node->{section}->{score}); - $node->{correct} = 0 if(!defined $node->{section}->{correct}); - if($response->{isCorrect}){ + $node->{inCorrect} = 0 if(!defined $node->{inCorrect}); + $node->{score} = 0 if(!defined $node->{score}); + $node->{correct} = 0 if(!defined $node->{correct}); + $node->{total} = 0 if(!defined $node->{total}); + $node->{total}++; + if($response->{isCorrect} == 1){ $node->{score} += $response->{value}; $node->{correct}++; }else{ diff --git a/www/extras/wobject/Survey/administersurvey.js b/www/extras/wobject/Survey/administersurvey.js index 486ddb094..755364f55 100644 --- a/www/extras/wobject/Survey/administersurvey.js +++ b/www/extras/wobject/Survey/administersurvey.js @@ -324,14 +324,125 @@ if (typeof Survey === "undefined") { } */ } - + + YAHOO.widget.Chart.SWFURL = "/extras/yui/build/charts/assets/charts.swf"; // Public API Survey.Form = { - showSummary: function(html){ + globalSummaryDataTip: function(item, index, series){ + var toolTipText = "hello"; + //var toolTipText = series.displayName + " for " + item.section; + //toolTipText += "\n" + item[series.yField]; + return toolTipText; + }, + showSummary: function(summary,html){ var html = html; document.getElementById('survey').innerHTML = html; + + + //Add totoal summary pie chart + totalSummary = + [ + { correct: "Correct", count: summary.totalCorrect }, + { correct: "Incorrect", count: summary.totalIncorrect } + ] + + var totalSummaryDS = new YAHOO.util.DataSource( totalSummary ); + totalSummaryDS.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; + totalSummaryDS.responseSchema = { fields: [ "correct", "count" ] }; + + new YAHOO.widget.PieChart( "chart", totalSummaryDS, + { + dataField: "count", + categoryField: "correct", + style: + { + padding: 10, + legend: + { + display: "left", + padding: 10, + spacing: 2, + font: + { + family: "Arial", + size: 13 + } + } + }, + //only needed for flash player express install + expressInstall: "/extras/yui/build/charts/assets/charts.swf" + }); + + //define section datatable columns + var myColumnDefs = [ + {key:"Question ID", sortable:true, resizeable:true}, + {key:"Question Text", formatter: YAHOO.widget.DataTable.formatText, sortable:true, resizeable:true}, + {key:"Answer ID", sortable:true, resizeable:true}, + {key:"Correct", sortable:true, resizeable:true}, + {key:"Answer Text", formatter: YAHOO.widget.DataTable.formatText, sortable:true, resizeable:true}, + {key:"Score", sortable:true, resizeable:true}, + {key:"Value", formatter: YAHOO.widget.DataTable.formatText, sortable:true, resizeable:true} + ]; + var sectionSummary = []; + //Load up datatables and create section data for bar chart + for(var i = 0; i < summary.sections.length; i++){ + var temp = summary.sections[i]; + sectionSummary[sectionSummary.length] = {"Total Responses": temp.total, "Correct": temp.correct, "Incorrect": temp.inCorrect, "section": (i+1)}; + var myDataSource = new YAHOO.util.DataSource(summary.sections[i].responses); +//These needs to be put in a destroy call list for when the html dom is recreated, if summaries are going to be uses with page reloads, else memory leak. + myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; + myDataSource.responseSchema = { + fields: ["Question ID","Question Text","Answer ID","Correct","Answer Text","Score","Value"] + }; + var tempText = "section"+ (i+1) + "datatable"; + new YAHOO.widget.DataTable(tempText, myColumnDefs, myDataSource, {caption:"Section "+(i+1)}); + } + + //Now create section summary bar charts + var sectionSummaryDS = new YAHOO.util.DataSource( sectionSummary ); + sectionSummaryDS.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; + sectionSummaryDS.responseSchema = + { + fields: [ "Total Responses", "Correct", "Incorrect", "section" ] + }; + var sectionSummarySeriesDef = + [ + { + displayName: "Total Responses", + yField: "Total Responses", + style:{size:10} + }, + { + displayName: "Correct", + yField: "Correct", + style:{size:10} + }, + { + displayName: "Incorrect", + yField: "Incorrect", + style:{size:10} + } + ]; + //create a Numeric Axis for displaying dollars + var responseAxis = new YAHOO.widget.NumericAxis(); + responseAxis.title = "Responses"; + //create Category Axis to specify a title for the months + var sectionAxis = new YAHOO.widget.CategoryAxis(); + sectionAxis.title = "Sections"; + //create the Chart + var mychart = new YAHOO.widget.ColumnChart( "summarychart", sectionSummaryDS, + { + series: sectionSummarySeriesDef, + xField: "section", + xAxis: sectionAxis, + yAxis: responseAxis, +// dataTipFunction: Survey.Form.globalSummaryDataTip, //try again in 2.7 + expressInstall: "/extras/yui/build/charts/assets/charts.swf" + }); + YAHOO.util.Event.addListener("submitbutton", "click", function(){ Survey.Comm.submitSummary(); }); }, + displayQuestions: function(params){ toValidate = []; var qs = params.questions; @@ -530,3 +641,11 @@ YAHOO.util.Event.onDOMReady(function(){ // Survey.Comm.setUrl('/' + document.getElementById('assetPath').value); Survey.Comm.callServer('', 'loadQuestions'); }); + +YAHOO.example.getDataTipText = function( item, index, series ) +{ + var toolTipText = series.displayName + " for " + item.month; +// toolTipText += "\n" + YAHOO.example.formatCurrencyAxisLabel( item[series.yField] ); + return toolTipText; +} + diff --git a/www/extras/wobject/Survey/administersurvey/comm.js b/www/extras/wobject/Survey/administersurvey/comm.js index b68a4ca68..4c97afc58 100644 --- a/www/extras/wobject/Survey/administersurvey/comm.js +++ b/www/extras/wobject/Survey/administersurvey/comm.js @@ -55,7 +55,7 @@ if (typeof Survey === "undefined") { window.location = url; } else if(response.type === 'summary'){ - Survey.Form.showSummary(response.summary); + Survey.Form.showSummary(response.summary,response.html); } else { alert("bad response");