From 3a305be1cd8fc0c05f0612996b70f5a4d28d8b5f Mon Sep 17 00:00:00 2001 From: apa-tiny Date: Fri, 5 Feb 2010 16:55:40 +0530 Subject: [PATCH] [IMP]:survey:(Ref-YSA,APA) - Improved Survey Analysis report with progress bar. bzr revid: apa@tinyerp.com-20100205112540-d28bjop6qrsv0ey6 --- .../survey/report/survey_analysis_report.py | 83 +++++++++++-------- addons/survey/survey.py | 10 +-- 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/addons/survey/report/survey_analysis_report.py b/addons/survey/report/survey_analysis_report.py index 2a95d144625..3f0bb345503 100755 --- a/addons/survey/report/survey_analysis_report.py +++ b/addons/survey/report/survey_analysis_report.py @@ -82,6 +82,7 @@ class survey_analysis(report_rml): + @@ -89,6 +90,7 @@ class survey_analysis(report_rml): + @@ -151,7 +153,7 @@ class survey_analysis(report_rml): rml+="""""" for mat_col in range(0, len(matrix_ans)): rml+="""""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """""" - rml+="""Response Count + rml+="""Response Count """ last_col = cols_widhts[-1] for ans in que.answer_choice_ids: @@ -161,7 +163,7 @@ class survey_analysis(report_rml): cr.execute("select count(id) ,sra.column_id from survey_response_answer sra where sra.answer_id = %d group by sra.column_id" % ans.id) calc_res = cr.dictfetchall() for mat_col in range(1, len(matrix_ans)): - percantage = 0 + percantage = 0.0 cal_count = 0 for cal in calc_res: if cal['column_id'] == matrix_ans[mat_col][0]: @@ -172,7 +174,7 @@ class survey_analysis(report_rml): rml += """""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)""" else: rml += """""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)""" - rml+="""""" + tools.ustr(tot_res) + """ + rml+="""""" + tools.ustr(tot_res) + """ """ rml+="""""" if que.is_comment_require: @@ -182,52 +184,65 @@ class survey_analysis(report_rml): """ + tools.ustr(tot_res) + """""" elif que.type in['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'multiple_textboxes','date_and_time','date','multiple_textboxes_diff_type']: - rml +="""""" + rml +="""""" rml += """ - Response Percentage - Response Count + Response Percentage + Response Count """ for ans in que.answer_choice_ids: + progress = ans.average * 7 / 100 rml+="""""" + to_xml(tools.ustr(ans.answer)) + """ - """ + tools.ustr(ans.average) + """% - """ + tools.ustr(ans.response) + """""" + + + + + """ + if progress: + rml += """ + """ + rml +=""" + + + """ + tools.ustr(ans.average) + """% + + """ + tools.ustr(ans.response) + """""" rml+="""""" if que.is_comment_require: - if que.make_comment_field: - cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id) - tot_res = cr.fetchone()[0] - tot_avg = 0.00 - if que.tot_resp: - tot_avg = round(float(tot_res * 100)/ que.tot_resp,2) - rml+="""""" +to_xml(tools.ustr(que.comment_label)) + """ - """ + str(tot_avg) + """% - """ + tools.ustr(tot_res) + """""" - else: - cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id) - tot_res = cr.fetchone()[0] - rml+="""""" + to_xml(tools.ustr(que.comment_label)) + """ - """ + tools.ustr(tot_res) + """""" +# if que.make_comment_field: +# cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id) +# tot_res = cr.fetchone()[0] +# tot_avg = 0.00 +# if que.tot_resp: +# tot_avg = round(float(tot_res * 100)/ que.tot_resp,2) +# rml+="""""" +to_xml(tools.ustr(que.comment_label)) + """ +# """ + str(tot_avg) + """% +# """ + tools.ustr(tot_res) + """""" +# else: + cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id) + tot_res = cr.fetchone()[0] + rml+="""""" + to_xml(tools.ustr(que.comment_label)) + """ + """ + tools.ustr(tot_res) + """""" elif que.type in['single_textbox']: cr.execute("select count(id) from survey_response_line where question_id = %d and single_text!=''" % que.id) rml +=""" - Response Count + Response Count - """ + tools.ustr(cr.fetchone()[0]) + """ + """ + tools.ustr(cr.fetchone()[0]) + """ """ elif que.type in['comment']: cr.execute("select count(id) from survey_response_line where question_id = %d and comment !=''" % que.id) rml +=""" - Response Count + Response Count - """ + tools.ustr(cr.fetchone()[0]) + """ + """ + tools.ustr(cr.fetchone()[0]) + """ """ elif que.type in['rating_scale']: cols_widhts.append(200) @@ -241,8 +256,8 @@ class survey_analysis(report_rml): rml+="""""" for mat_col in range(0,len(matrix_ans)): rml+="""""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """""" - rml+="""Rating Average - Response Count + rml+="""Rating Average + Response Count """ for ans in que.answer_choice_ids: rml+="""""" + to_xml(tools.ustr(ans.answer)) + """""" @@ -275,8 +290,8 @@ class survey_analysis(report_rml): percantage = 0.00 if res_count: percantage = round((float(rating_weight_sum)/res_count), 2) - rml+="""""" + tools.ustr(percantage) + """ - """ + tools.ustr(res_count) + """""" + rml+="""""" + tools.ustr(percantage) + """ + """ + tools.ustr(res_count) + """""" rml+="""""" elif que.type in['matrix_of_drop_down_menus']: for column in que.column_heading_ids: @@ -292,7 +307,7 @@ class survey_analysis(report_rml): """ for menu in menu_choices: rml += """""" + to_xml(tools.ustr(menu)) + """""" - rml += """Response Count""" + rml += """Response Count""" cr.execute("select count(id), sra.answer_id from survey_response_answer sra \ where sra.column_id='%s' group by sra.answer_id " % (column.id)) res_count = cr.dictfetchall() @@ -319,7 +334,7 @@ class survey_analysis(report_rml): response = 0 for res in res_count: if res['answer_id'] == ans.id: response = res['count'] - rml += """""" + tools.ustr(response) + """""" + rml += """""" + tools.ustr(response) + """""" rml += """""" elif que.type in['numerical_textboxes']: rml +=""" @@ -328,7 +343,7 @@ class survey_analysis(report_rml): Response Average Response Total - Response Count + Response Count """ for ans in que.answer_choice_ids: cr.execute("select answer from survey_response_answer where answer_id=%d group by answer" % ans.id) @@ -343,7 +358,7 @@ class survey_analysis(report_rml): """ + tools.ustr(per) +""" """ + tools.ustr(total) + """ - """ + tools.ustr(len(tot_res)) + """""" + """ + tools.ustr(len(tot_res)) + """""" rml+="""""" rml +=""" diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 808f900dcd4..282ced97419 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -92,10 +92,10 @@ class survey(osv.osv): def survey_cancel(self, cr, uid, ids, arg): self.write(cr, uid, ids, { 'state' : 'cancel' }) return True - + def copy(self, cr, uid, id, default=None,context={}): raise osv.except_osv(_('Error !'),_('You cannot duplicate the resource!')) - + survey() class survey_history(osv.osv): @@ -155,7 +155,7 @@ class survey_page(osv.osv): def copy(self, cr, uid, id, default=None,context={}): raise osv.except_osv(_('Error !'),_('You cannot duplicate the resource!')) - + survey_page() class survey_question(osv.osv): @@ -408,7 +408,7 @@ class survey_question(osv.osv): def default_get(self, cr, uid, fields, context={}): data = super(survey_question, self).default_get(cr, uid, fields, context) if context.has_key('line_order') and context['line_order']: - + if len(context['line_order'][-1]) > 2 and type(context['line_order'][-1][2]) == type({}) and context['line_order'][-1][2].has_key('sequence'): data['sequence'] = context['line_order'][-1][2]['sequence'] + 1 if context.has_key('page_id'): @@ -484,7 +484,7 @@ class survey_answer(osv.osv): 'sequence' : fields.integer('Sequence'), 'response' : fields.function(_calc_response_avg, method=True, string="#Response", multi='sums'), 'average' : fields.function(_calc_response_avg, method=True, string="#Avg", multi='sums'), - 'type' : fields.selection([('char','Character'),('date','Date'),('datetime','Date & Time'),('integer','Integer'),('float','Float'),('selection','Selection'),('email','Email Address')], "Type of Answer",required=1), + 'type' : fields.selection([('char','Character'),('date','Date'),('datetime','Date & Time'),('integer','Integer'),('float','Float'),('selection','Selection'),('email','Email')], "Type of Answer",required=1), 'menu_choice' : fields.text('Menu Choices'), 'in_visible_answer_type':fields.boolean('Is Answer Type Invisible??') }