# -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## import pooler from report.interface import report_rml from tools import to_xml import tools import time from report import report_sxw class survey_analysis(report_rml): def create(self, cr, uid, ids, datas, context): surv_obj = pooler.get_pool(cr.dbname).get('survey') user_obj = pooler.get_pool(cr.dbname).get('res.users') rml_obj=report_sxw.rml_parse(cr, uid, surv_obj._name,context) company=user_obj.browse(cr,uid,[uid],context)[0].company_id rml =""" """ if datas.has_key('form') and datas['form']['survey_ids']: ids = datas['form']['survey_ids'] for survey in surv_obj.browse(cr, uid, ids): rml += """ Answer Summary Survey Title Total Started Survey Total Completed Survey """ + to_xml(tools.ustr(survey.title)) + """ """ + str(survey.tot_start_survey) + """ """ + str(survey.tot_comp_survey) + """ """ for page in survey.page_ids: rml += """ Page :- """ + to_xml(tools.ustr(page.title)) + """ """ for que in page.question_ids: rml +=""" """ + to_xml(tools.ustr(que.question)) + """ """ cols_widhts = [] if que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans']: cols_widhts.append(200) for col in range(0, len(que.column_heading_ids) + 1): cols_widhts.append(float(300 / (len(que.column_heading_ids) + 1))) colWidths = ",".join(map(tools.ustr, cols_widhts)) matrix_ans = [(0,'')] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append((col.id,col.title)) rml += """""" for mat_col in range(0, len(matrix_ans)): rml+="""""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """""" rml += """Answer Count """ last_col = cols_widhts[-1] for ans in que.answer_choice_ids: rml += """""" + to_xml(tools.ustr(ans.answer)) + """""" cr.execute("select count(id) from survey_response_answer sra where sra.answer_id = %s", (ans.id,)) tot_res = cr.fetchone()[0] cr.execute("select count(id) ,sra.column_id from survey_response_answer sra where sra.answer_id=%s group by sra.column_id", (ans.id,)) calc_res = cr.dictfetchall() for mat_col in range(1, len(matrix_ans)): percantage = 0.0 cal_count = 0 for cal in calc_res: if cal['column_id'] == matrix_ans[mat_col][0]: cal_count = cal['count'] if tot_res: percantage = round(float(cal_count)*100 / tot_res,2) if percantage: rml += """""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)""" else: rml += """""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)""" rml += """""" + tools.ustr(tot_res) + """ """ rml += """""" if que.is_comment_require: cr.execute("select count(id) from survey_response_line where question_id = %s 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['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'multiple_textboxes','date_and_time','date','multiple_textboxes_diff_type']: rml += """""" rml += """ Answer Percentage Answer Count """ for ans in que.answer_choice_ids: progress = ans.average * 7 / 100 rml += """""" + to_xml(tools.ustr(ans.answer)) + """ """ 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 = %s 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 = %s 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 = %s and single_text!=''",(que.id,)) rml += """ Answer Count """ + tools.ustr(cr.fetchone()[0]) + """ """ elif que.type in['comment']: cr.execute("select count(id) from survey_response_line where question_id = %s and comment !=''", (que.id,)) rml += """ Answer Count """ + tools.ustr(cr.fetchone()[0]) + """ """ elif que.type in['rating_scale']: cols_widhts.append(200) for col in range(0,len(que.column_heading_ids) + 2): cols_widhts.append(float(300 / (len(que.column_heading_ids) + 2))) colWidths = ",".join(map(tools.ustr, cols_widhts)) matrix_ans = [(0,'')] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append((col.id,col.title)) rml += """""" for mat_col in range(0,len(matrix_ans)): rml += """""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """""" rml += """Rating Average Answer Count """ for ans in que.answer_choice_ids: rml += """""" + to_xml(tools.ustr(ans.answer)) + """""" res_count = 0 rating_weight_sum = 0 for mat_col in range(1, len(matrix_ans)): cr.execute("select count(sra.answer_id) from survey_response_line sr, survey_response_answer sra\ where sr.id = sra.response_id and sra.answer_id = %s and sra.column_id ='%s'", (ans.id,matrix_ans[mat_col][0])) tot_res = cr.fetchone()[0] cr.execute("select count(sra.answer_id),sqc.rating_weight from survey_response_line sr, survey_response_answer sra ,\ survey_question_column_heading sqc where sr.id = sra.response_id and \ sqc.question_id = sr.question_id and sra.answer_id = %s and sqc.title ='%s'\ + group by sra.answer_id,sqc.rating_weight", (ans.id,matrix_ans[mat_col][1])) col_weight = cr.fetchone() if not col_weight: col_weight= (0,0) elif not col_weight[1]: col_weight = (col_weight[0],0) res_count = col_weight[0] if tot_res and res_count: rating_weight_sum += int(col_weight[1]) * tot_res tot_per = round((float(tot_res) * 100) / int(res_count), 2) else: tor_res = 0 tot_per = 0.0 if tot_res: rml += """""" + tools.ustr(tot_per) + "%(" + tools.ustr(tot_res) + """)""" else: rml += """""" + tools.ustr(tot_per)+"%(" + tools.ustr(tot_res) + """)""" percantage = 0.00 if res_count: percantage = round((float(rating_weight_sum)/res_count), 2) 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: rml += """ """ + to_xml(tools.ustr(column.title)) + """""" menu_choices = column.menu_choice.split('\n') cols_widhts = [] cols_widhts.append(200) for col in range(0, len(menu_choices) + 1): cols_widhts.append(float(300 / (len(menu_choices) + 1))) colWidths = ",".join(map(tools.ustr, cols_widhts)) rml += """ """ for menu in menu_choices: rml += """""" + to_xml(tools.ustr(menu)) + """""" rml += """Answer 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() cr.execute("select count(sra.id),sra.value_choice, sra.answer_id, sra.column_id from survey_response_answer sra \ where sra.column_id='%s' group by sra.value_choice ,sra.answer_id, sra.column_id", (column.id,)) calc_percantage = cr.dictfetchall() for ans in que.answer_choice_ids: rml += """""" + to_xml(tools.ustr(ans.answer)) + """""" for mat_col in range(0, len(menu_choices)): calc = 0 response = 0 for res in res_count: if res['answer_id'] == ans.id: response = res['count'] for per in calc_percantage: if ans.id == per['answer_id'] and menu_choices[mat_col] == per['value_choice']: calc = per['count'] percantage = 0.00 if calc and response: percantage = round((float(calc)* 100) / response,2) if calc: rml += """""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)""" else: rml += """""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)""" response = 0 for res in res_count: if res['answer_id'] == ans.id: response = res['count'] rml += """""" + tools.ustr(response) + """""" rml += """""" elif que.type in['numerical_textboxes']: rml += """ Answer Average Answer Total Answer Count """ for ans in que.answer_choice_ids: cr.execute("select answer from survey_response_answer where answer_id=%s group by answer", (ans.id,)) tot_res = cr.dictfetchall() total = 0 for tot in tot_res: total += int(tot['answer']) per = 0.00 if len(tot_res): per = round((float(total) / len(tot_res)),2) rml+="""""" + to_xml(tools.ustr(ans.answer)) + """ """ + tools.ustr(per) +""" """ + tools.ustr(total) + """ """ + tools.ustr(len(tot_res)) + """""" rml+="""""" rml +=""" Answered Question """ + tools.ustr(que.tot_resp) + """ Skipped Question """ + tools.ustr(survey.tot_start_survey - que.tot_resp) + """ """ rml += """""" rml += """""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] self.internal_header=True pdf = create_doc(rml, title=self.title) return (pdf, report_type) survey_analysis('report.survey.analysis', 'survey','','') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: