'Compute statistical data for questions by counting number of vote per choice on basis of filter'

@api.model
def prepare_result(self, question, current_filters=None):

    current_filters = (current_filters if current_filters else [])
    result_summary = {}
    if (question.type in ['simple_choice', 'multiple_choice']):
        answers = {}
        comments = []
        [answers.update({label.id: {'text': label.value, 'count': 0, 'answer_id': label.id}}) for label in question.labels_ids]
        for input_line in question.user_input_line_ids:
            if ((input_line.answer_type == 'suggestion') and answers.get(input_line.value_suggested.id) and ((not current_filters) or (input_line.user_input_id.id in current_filters))):
                answers[input_line.value_suggested.id]['count'] += 1
            if ((input_line.answer_type == 'text') and ((not current_filters) or (input_line.user_input_id.id in current_filters))):
                comments.append(input_line)
        result_summary = {'answers': answers.values(), 'comments': comments}
    if (question.type == 'matrix'):
        rows = OrderedDict()
        answers = OrderedDict()
        res = dict()
        comments = []
        [rows.update({label.id: label.value}) for label in question.labels_ids_2]
        [answers.update({label.id: label.value}) for label in question.labels_ids]
        for cell in product(rows.keys(), answers.keys()):
            res[cell] = 0
        for input_line in question.user_input_line_ids:
            if ((input_line.answer_type == 'suggestion') and ((not current_filters) or (input_line.user_input_id.id in current_filters)) and input_line.value_suggested_row):
                res[(input_line.value_suggested_row.id, input_line.value_suggested.id)] += 1
            if ((input_line.answer_type == 'text') and ((not current_filters) or (input_line.user_input_id.id in current_filters))):
                comments.append(input_line)
        result_summary = {'answers': answers, 'rows': rows, 'result': res, 'comments': comments}
    if (question.type in ['free_text', 'textbox', 'datetime']):
        result_summary = []
        for input_line in question.user_input_line_ids:
            if ((not current_filters) or (input_line.user_input_id.id in current_filters)):
                result_summary.append(input_line)
    if (question.type == 'numerical_box'):
        result_summary = {'input_lines': []}
        all_inputs = []
        for input_line in question.user_input_line_ids:
            if ((not current_filters) or (input_line.user_input_id.id in current_filters)):
                all_inputs.append(input_line.value_number)
                result_summary['input_lines'].append(input_line)
        if all_inputs:
            result_summary.update({'average': round((sum(all_inputs) / len(all_inputs)), 2), 'max': round(max(all_inputs), 2), 'min': round(min(all_inputs), 2), 'sum': sum(all_inputs), 'most_common': Counter(all_inputs).most_common(5)})
    return result_summary
