single question report basically working
This commit is contained in:
		
							parent
							
								
									2ea0689a05
								
							
						
					
					
						commit
						f935a0efb7
					
				
					 2 changed files with 68 additions and 11 deletions
				
			
		|  | @ -156,22 +156,26 @@ class SurveyView(InstitutionMixin, ConceptView): | |||
| 
 | ||||
|     def getTeamData(self, respManager): | ||||
|         result = [] | ||||
|         pred = self.conceptManager.get('ismember') | ||||
|         if pred is None: | ||||
|         pred = [self.conceptManager.get('ismember'), | ||||
|                 self.conceptManager.get('ismaster')] | ||||
|         if None in pred: | ||||
|             return result | ||||
|         inst = self.institution | ||||
|         instUid = self.getUidForObject(inst) | ||||
|         if inst: | ||||
|             for c in inst.getChildren([pred]): | ||||
|             for c in inst.getChildren(pred): | ||||
|                 uid = self.getUidForObject(c) | ||||
|                 data = respManager.load(uid, instUid) | ||||
|                 if data: | ||||
|                     resp = Response(self.adapted, None) | ||||
|                     for qu in self.adapted.questions: | ||||
|                         if qu.questionType != 'value_selection': | ||||
|                             continue | ||||
|                         if qu.uid in data: | ||||
|                             resp.values[qu] = data[qu.uid] | ||||
|                         if qu.questionType in (None, 'value_selection'): | ||||
|                             if qu.uid in data: | ||||
|                                 value = data[qu.uid] | ||||
|                                 if isinstance(value, int) or value.isdigit(): | ||||
|                                     resp.values[qu] = int(value) | ||||
|                         else: | ||||
|                             resp.texts[qu] = data.get(qu.uid) or u'' | ||||
|                     qgAvailable = True | ||||
|                     for qg in self.adapted.questionGroups: | ||||
|                         if qg.uid in data: | ||||
|  | @ -244,12 +248,30 @@ class SurveyView(InstitutionMixin, ConceptView): | |||
|         groups = self.adapted.questionGroups | ||||
|         teamValues = response.getTeamResult(groups, self.teamData) | ||||
|         for idx, r in enumerate(teamValues): | ||||
|             item = dict(category=r['group'].title, | ||||
|             group = r['group'] | ||||
|             item = dict(category=group.title, | ||||
|                         average=int(round(r['average'] * 100)), | ||||
|                         teamRank=r['rank']) | ||||
|             if group.feedbackItems: | ||||
|                 wScore = r['average'] * len(group.feedbackItems) - 0.00001 | ||||
|                 item['text'] = group.feedbackItems[int(wScore)].text | ||||
|             result.append(item) | ||||
|         return result | ||||
| 
 | ||||
|     def getTeamResultsForQuestion(self, question): | ||||
|         result = dict(average=0.0, stddev=0.0) | ||||
|         if self.teamData is None: | ||||
|             respManager = Responses(self.context) | ||||
|             self.teamData = self.getTeamData(respManager) | ||||
|         values = [r.values.get(question) for r in self.teamData] | ||||
|         values = [v for v in values if v is not None] | ||||
|         if values: | ||||
|             average = round(float(sum(values)) / len(values), 2) | ||||
|             result['average'] = average | ||||
|         texts = [r.texts.get(question) for r in self.teamData] | ||||
|         result['texts'] = '<br />'.join([unicode(t) for t in texts if t]) | ||||
|         return result | ||||
| 
 | ||||
|     def check(self, response): | ||||
|         errors = [] | ||||
|         values = response.values | ||||
|  |  | |||
|  | @ -158,8 +158,7 @@ | |||
|         <span tal:content="python:len(teamData)" /></b><br />  | ||||
|     </p> | ||||
|     <div class="button" id="show_questionnaire"> | ||||
|       <a href="" xxonclick="back(); return false" | ||||
|          i18n:translate="" | ||||
|       <a i18n:translate="" | ||||
|          tal:attributes="href string:${request/URL}${item/urlParamString}"> | ||||
|         Back to Questionnaire</a> | ||||
|       <br /> | ||||
|  | @ -174,7 +173,43 @@ | |||
| <metal:block define-macro="report_questions"> | ||||
|     <h3 i18n:translate="label_survey_report_questions"></h3> | ||||
|     <div> | ||||
|       Not yet implemented | ||||
|       <table class="listing"> | ||||
|         <tal:group repeat="group item/groups"> | ||||
|           <tr> | ||||
|             <td> </td> | ||||
|             <td> </td> | ||||
|           </tr> | ||||
|           <tr class="vpad"> | ||||
|             <td><b tal:content="group/title" /></td> | ||||
|             <td i18n:translate="">Average</td> | ||||
|           </tr> | ||||
|           <tr tal:repeat="question group/questions"> | ||||
|             <tal:question  | ||||
|                   define="qutype python: | ||||
|                               question.questionType or 'value_selection'; | ||||
|                           data python:item.getTeamResultsForQuestion(question)"> | ||||
|               <td> | ||||
|                 <div tal:content="question/text" /> | ||||
|                 <div style="width: 90%; margin-left: 20px" | ||||
|                      tal:condition="python:qutype == 'text'" | ||||
|                      tal:content="structure data/texts" /> | ||||
|               </td> | ||||
|               <td class="center"> | ||||
|                 <span tal:condition="python:qutype == 'value_selection'" | ||||
|                       tal:content="data/average" /></td> | ||||
|             </tal:question> | ||||
|           </tr> | ||||
|         </tal:group> | ||||
|       </table> | ||||
|       <p tal:define="teamData item/teamData" | ||||
|          tal:condition="teamData"> | ||||
|         <b><span i18n:translate="">Team Size</span>: | ||||
|           <span tal:content="python:len(teamData)" /></b><br />  | ||||
|       </p> | ||||
|       <div class="button" id="show_questionnaire"> | ||||
|         <a i18n:translate="" | ||||
|            tal:attributes="href string:${request/URL}${item/urlParamString}"> | ||||
|           Back to Questionnaire</a></div> | ||||
|     </div> | ||||
| </metal:block> | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue