provide team evaluation of survey
This commit is contained in:
		
							parent
							
								
									2fc7709c56
								
							
						
					
					
						commit
						66bf217ee8
					
				
					 3 changed files with 57 additions and 16 deletions
				
			
		|  | @ -60,9 +60,30 @@ class SurveyView(ConceptView): | ||||||
|         sft = self.adapted.showFeedbackText |         sft = self.adapted.showFeedbackText | ||||||
|         return sft is None and True or sft |         return sft is None and True or sft | ||||||
| 
 | 
 | ||||||
|  |     def getTeamData(self, respManager, myResponse): | ||||||
|  |         result = [myResponse] | ||||||
|  |         pred = self.conceptManager.get('ismember') | ||||||
|  |         if pred is None: | ||||||
|  |             return result | ||||||
|  |         personId = respManager.personId | ||||||
|  |         person = self.getObjectForUid(personId) | ||||||
|  |         inst = person.getParents([pred]) | ||||||
|  |         if inst: | ||||||
|  |             for c in inst[0].getChildren([pred]): | ||||||
|  |                 uid = self.getUidForObject(c) | ||||||
|  |                 if uid != personId: | ||||||
|  |                     data = respManager.load(uid) | ||||||
|  |                     if data: | ||||||
|  |                         resp = Response(self.adapted, None) | ||||||
|  |                         for qu in self.adapted.questions: | ||||||
|  |                             resp.values[qu] = data[qu.uid] | ||||||
|  |                         result.append(resp) | ||||||
|  |         return result | ||||||
|  | 
 | ||||||
|     def results(self): |     def results(self): | ||||||
|         result = [] |         values = [] | ||||||
|         response = None |         response = None | ||||||
|  |         respManager = Responses(self.context) | ||||||
|         form = self.request.form |         form = self.request.form | ||||||
|         if 'submit' in form: |         if 'submit' in form: | ||||||
|             self.data = {} |             self.data = {} | ||||||
|  | @ -75,15 +96,25 @@ class SurveyView(ConceptView): | ||||||
|                         value = int(value) |                         value = int(value) | ||||||
|                         self.data[uid] = value |                         self.data[uid] = value | ||||||
|                         response.values[question] = value |                         response.values[question] = value | ||||||
|             Responses(self.context).save(self.data) |             respManager.save(self.data) | ||||||
|             self.errors = self.check(response) |             self.errors = self.check(response) | ||||||
|             if self.errors: |             if self.errors: | ||||||
|                 return [] |                 return [] | ||||||
|  |         ranks = averages = [] | ||||||
|         if response is not None: |         if response is not None: | ||||||
|             result = response.getGroupedResult() |             if self.adapted.showTeamResults: | ||||||
|         return [dict(category=r[0].title, text=r[1].text,  |                 values, ranks, averages = response.getTeamResult( | ||||||
|  |                                             self.getTeamData(respManager, response)) | ||||||
|  |             else: | ||||||
|  |                 values = response.getGroupedResult() | ||||||
|  |         result = [dict(category=r[0].title, text=r[1].text,  | ||||||
|                             score=int(round(r[2] * 100))) |                             score=int(round(r[2] * 100))) | ||||||
|                         for r in result] |                         for r in values] | ||||||
|  |         if ranks or averages: | ||||||
|  |             for idx, qgdata in enumerate(result): | ||||||
|  |                 qgdata['rank'] = ranks[idx] | ||||||
|  |                 qgdata['average'] = int(round(averages[idx] * 100)) | ||||||
|  |         return result | ||||||
| 
 | 
 | ||||||
|     def check(self, response): |     def check(self, response): | ||||||
|         errors = [] |         errors = [] | ||||||
|  |  | ||||||
|  | @ -43,9 +43,11 @@ class Responses(BaseRecordManager): | ||||||
|             self.storage.saveUserTrack(self.uid, 0, self.personId, data,  |             self.storage.saveUserTrack(self.uid, 0, self.personId, data,  | ||||||
|                                         update=True, overwrite=True) |                                         update=True, overwrite=True) | ||||||
| 
 | 
 | ||||||
|     def load(self): |     def load(self, personId=None): | ||||||
|         if self.personId: |         if personId is None: | ||||||
|             tracks = self.storage.getUserTracks(self.uid, 0, self.personId) |             personId = self.personId | ||||||
|  |         if personId: | ||||||
|  |             tracks = self.storage.getUserTracks(self.uid, 0, personId) | ||||||
|             if tracks: |             if tracks: | ||||||
|                 return tracks[0].data |                 return tracks[0].data | ||||||
|         return {} |         return {} | ||||||
|  |  | ||||||
|  | @ -19,22 +19,30 @@ | ||||||
|         <th i18n:translate="">Category</th> |         <th i18n:translate="">Category</th> | ||||||
|         <th tal:condition="item/showFeedbackText" |         <th tal:condition="item/showFeedbackText" | ||||||
|             i18n:translate="">Response</th> |             i18n:translate="">Response</th> | ||||||
|         <th i18n:translate="">%</th> |         <th class="center" | ||||||
|  |             i18n:translate="">%</th> | ||||||
|         <tal:team condition="item/adapted/showTeamResults"> |         <tal:team condition="item/adapted/showTeamResults"> | ||||||
|           <th i18n:translate="">Rank</th> |           <th class="center" | ||||||
|           <th i18n:translate="">Team Score %</th> |               i18n:translate="">Rank</th> | ||||||
|           <th i18n:translate="">Team Rank</th> |           <th class="center" | ||||||
|  |               i18n:translate="">Team Score %</th> | ||||||
|  |           <th class="center" | ||||||
|  |               tal:condition="nothing" | ||||||
|  |               i18n:translate="">Team Rank</th> | ||||||
|         </tal:team> |         </tal:team> | ||||||
|       </tr> |       </tr> | ||||||
|       <tr tal:repeat="fbitem feedback"> |       <tr tal:repeat="fbitem feedback"> | ||||||
|         <td tal:content="fbitem/category" /> |         <td tal:content="fbitem/category" /> | ||||||
|         <td tal:condition="item/showFeedbackText" |         <td tal:condition="item/showFeedbackText" | ||||||
|             tal:content="fbitem/text" /> |             tal:content="fbitem/text" /> | ||||||
|         <td tal:content="fbitem/score" /> |         <td class="center" | ||||||
|  |             tal:content="fbitem/score" /> | ||||||
|         <tal:team condition="item/adapted/showTeamResults"> |         <tal:team condition="item/adapted/showTeamResults"> | ||||||
|           <td /> |           <td class="center" | ||||||
|           <td /> |               tal:content="fbitem/rank" /> | ||||||
|           <td /> |           <td class="center" | ||||||
|  |               tal:content="fbitem/average" /> | ||||||
|  |           <td tal:condition="nothing" /> | ||||||
|         </tal:team> |         </tal:team> | ||||||
|       </tr> |       </tr> | ||||||
|     </table> |     </table> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue