Skip to content
Permalink
Browse files

tmp

  • Loading branch information
tde-banana-odoo committed Nov 29, 2019
1 parent 8dcd918 commit fb9498d284d185eb7fc7c7358adf76c031d112e8
@@ -8,7 +8,7 @@
<field name="access_mode">public</field>
<field name="users_can_go_back" eval="False"/>
<field name="scoring_type">scoring_with_answers</field>
<field name="passing_score">55</field>
<field name="scoring_success_min">55</field>
<field name="questions_layout">page_per_section</field>
<field name="description" type="html">
<p>This small quiz will test your knowledge about our Company. Be prepared !</p></field>
@@ -52,54 +52,89 @@
<record model="survey.question" id="survey_demo_quiz_p2_q1">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">11</field>
<field name="title">Insert a date</field>
<field name="question_type">date</field>
<field name="comments_allowed" eval="False"/>
<field name="constr_mandatory" eval="True"/>
</record>
<record model="survey.question" id="survey_demo_quiz_p2_q2">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">12</field>
<field name="title">Insert a datetime</field>
<field name="question_type">datetime</field>
<field name="comments_allowed" eval="True"/>
<field name="constr_mandatory" eval="False"/>
</record>
<record model="survey.question" id="survey_demo_quiz_p2_q3">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">13</field>
<field name="title">Insert a text</field>
<field name="question_type">free_text</field>
<field name="comments_allowed" eval="False"/>
<field name="constr_mandatory" eval="False"/>
</record>

<!-- Page 2: quiz about products -->
<record model="survey.question" id="survey_demo_quiz_p3">
<field name="title">Another page</field>
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">20</field>
<field name="question_type" eval="False"/>
<field name="is_page" eval="True"/>
<field name="description" type="html">
<p>Blah bleh blih bloh bluh</p></field>
</record>
<record model="survey.question" id="survey_demo_quiz_p3_q1">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">21</field>
<field name="title">How frequently do you buy products online ?</field>
<field name="question_type">simple_choice</field>
<field name="display_mode">dropdown</field>
<field name="comments_allowed" eval="True"/>
<field name="comment_count_as_answer" eval="True"/>
<field name="constr_mandatory" eval="True"/>
</record>
<record model="survey.question.answer" id="survey_demo_quiz_p2_q1_sug1">
<field name="question_id" ref="survey_demo_quiz_p2_q1"/>
<record model="survey.question.answer" id="survey_demo_quiz_p3_q1_sug1">
<field name="question_id" ref="survey_demo_quiz_p3_q1"/>
<field name="sequence">1</field>
<field name="value">Once a day</field>
</record>
<record model="survey.question.answer" id="survey_demo_quiz_p2_q1_sug2">
<field name="question_id" ref="survey_demo_quiz_p2_q1"/>
<record model="survey.question.answer" id="survey_demo_quiz_p3_q1_sug2">
<field name="question_id" ref="survey_demo_quiz_p3_q1"/>
<field name="sequence">2</field>
<field name="value">Once a week</field>
</record>
<record model="survey.question.answer" id="survey_demo_quiz_p2_q1_sug3">
<field name="question_id" ref="survey_demo_quiz_p2_q1"/>
<record model="survey.question.answer" id="survey_demo_quiz_p3_q1_sug3">
<field name="question_id" ref="survey_demo_quiz_p3_q1"/>
<field name="sequence">3</field>
<field name="value">Once a month</field>
</record>
<record model="survey.question" id="survey_demo_quiz_p2_q2">
<record model="survey.question" id="survey_demo_quiz_p3_q2">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">12</field>
<field name="sequence">22</field>
<field name="title">Which of the following words would you use to describe our products ?</field>
<field name="question_type">multiple_choice</field>
<field name="constr_mandatory" eval="True"/>
<field name="comments_allowed" eval="True"/>
<field name="comment_count_as_answer" eval="False"/>
</record>
<record model="survey.question.answer" id="survey_demo_quiz_p2_q2_sug1">
<field name="question_id" ref="survey_demo_quiz_p2_q2"/>
<record model="survey.question.answer" id="survey_demo_quiz_p3_q2_sug1">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">1</field>
<field name="value">High quality</field>
</record>
<record model="survey.question.answer" id="survey_demo_quiz_p2_q2_sug2">
<field name="question_id" ref="survey_demo_quiz_p2_q2"/>
<record model="survey.question.answer" id="survey_demo_quiz_p3_q2_sug2">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">2</field>
<field name="value">Useful</field>
</record>
<record model="survey.question.answer" id="survey_demo_quiz_p2_q2_sug3">
<field name="question_id" ref="survey_demo_quiz_p2_q2"/>
<record model="survey.question.answer" id="survey_demo_quiz_p3_q2_sug3">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">3</field>
<field name="value">Unique</field>
</record>
<record model="survey.question.answer" id="survey_demo_quiz_p2_q2_sug4">
<field name="question_id" ref="survey_demo_quiz_p2_q2"/>
<record model="survey.question.answer" id="survey_demo_quiz_p3_q2_sug4">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">4</field>
<field name="value">Good value for money</field>
</record>
@@ -47,6 +47,21 @@
<field name="question_id" ref="survey_demo_quiz_p1_q2"/>
<field name="value_number">42</field>
</record>
<record id="survey_demo_quiz_answer_1_p2_q1_l1" model="survey.user_input.line">
<field name="user_input_id" ref="survey_demo_quiz_answer_1"/>
<field name="question_id" ref="survey_demo_quiz_p2_q1"/>
<field name="value_date" eval="DateTime.today()"/>
</record>
<record id="survey_demo_quiz_answer_1_p2_q2_l1" model="survey.user_input.line">
<field name="user_input_id" ref="survey_demo_quiz_answer_1"/>
<field name="question_id" ref="survey_demo_quiz_p2_q2"/>
<field name="value_datetime" eval="DateTime.now().replace(hour=2, minute=0)"/>
</record>
<record id="survey_demo_quiz_answer_1_p2_q3_l1" model="survey.user_input.line">
<field name="user_input_id" ref="survey_demo_quiz_answer_1"/>
<field name="question_id" ref="survey_demo_quiz_p2_q3"/>
<field name="value_free_text">Youpie</field>
</record>

<record id="survey_demo_quiz_answer_2_p1_q1_l1" model="survey.user_input.line">
<field name="user_input_id" ref="survey_demo_quiz_answer_2"/>
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import collections
import json
import itertools

@@ -314,6 +315,7 @@ def _prepare_statistics(self, user_input_lines):
# prepare table and graph data
question_data['graph_data'] = json.dumps(question._get_stats_graph_data(answer_line_ids))
question_data['table_data'] = question._get_stats_table_data(answer_line_ids)
question_data['summary_data'] = question._get_stats_summary_data(answer_line_ids)

all_questions_data.append(question_data)
return all_questions_data
@@ -365,10 +367,7 @@ def _get_stats_table_data(self, user_input_lines):
return self._get_stats_table_data_choice(user_input_lines)
elif self.question_type in ['matrix']:
return self._get_stats_table_data_matrix(user_input_lines)
elif self.question_type in ['free_text', 'textbox', 'date', 'datetime', 'numerical_box']:
return self._get_stats_table_data_linear(user_input_lines)
else:
raise ValueError(_('Unexpected %s question' % self.question_type))
return [line for line in user_input_lines]

def _get_stats_table_data_choice(self, user_input_lines):
""" Table data for simple choice and multiple choice """
@@ -405,9 +404,21 @@ def _get_stats_table_data_matrix(self, user_input_lines):
for sug_answer in suggested_answers
]

def _get_stats_table_data_linear(self, user_input_lines):
""" Table data for free_text, text_box, date, datetime, numerical_box """
return [line for line in user_input_lines]
def _get_stats_summary_data(self, user_input_lines):
if self.question_type in ['numerical_box']:
return self._get_stats_summary_data_numerical(user_input_lines)
return ''

def _get_stats_summary_data_numerical(self, user_input_lines):
all_values = user_input_lines.filtered(lambda line: not line.skipped).mapped('value_number')
lines_sum = sum(all_values)
return {
'max': max(all_values, default=0),
'min': min(all_values, default=0),
'sum': lines_sum,
'average': lines_sum / len(all_values) or 1,
'most_common': collections.Counter(all_values).most_common(5),
}


class SurveyQuestionAnswer(models.Model):
@@ -39,21 +39,22 @@

<template id="question_result_number_new" name="Question: number result (numerical_box)">
<t t-set="table_data" t-value="question_data['table_data']"/>
<!-- <span class="float-right mt8">
<span class="badge badge-secondary only_left_radius">Sum </span> <span class="badge badge-info only_right_radius" t-esc="number_result['sum']"></span>
<span class="badge badge-secondary only_left_radius">Maximum </span> <span class="badge badge-success only_right_radius" t-esc="number_result['max']"></span>
<span class="badge badge-secondary only_left_radius">Minimum </span> <span class="badge badge-danger only_right_radius" t-esc="number_result['min']"></span>
<span class="badge badge-secondary only_left_radius">Average </span> <span class="badge badge-warning only_right_radius" t-esc="number_result['average']"></span>
<t t-set="summary_data" t-value="question_data['summary_data']"/>
<span class="float-right mt8">
<span class="badge badge-secondary only_left_radius">Sum </span> <span class="badge badge-info only_right_radius" t-esc="summary_data['sum']"></span>
<span class="badge badge-secondary only_left_radius">Maximum </span> <span class="badge badge-success only_right_radius" t-esc="summary_data['max']"></span>
<span class="badge badge-secondary only_left_radius">Minimum </span> <span class="badge badge-danger only_right_radius" t-esc="summary_data['min']"></span>
<span class="badge badge-secondary only_left_radius">Average </span> <span class="badge badge-warning only_right_radius" t-esc="summary_data['average']"></span>
</span>
-->

<ul class="nav nav-tabs d-print-none" role="tablist">
<!-- <li class="nav-item">
<li class="nav-item">
<a t-att-href="'#survey_stats_question_%d' % question.id"
t-att-aria-controls="'survey_stats_question_%d' % question.id"
class="nav-link active" data-toggle="tab" role="tab">
<i class="fa fa-list-ol"></i> Most Common <span t-esc="len(number_result['most_common'])"></span>
<i class="fa fa-list-ol"></i> Most Common
</a>
</li> -->
</li>
<li class="nav-item">
<a t-att-href="'#survey_data_question_%d' % question.id"
t-att-aria-controls="'survey_data_question_%d' % question.id"
@@ -65,22 +66,18 @@
<div class="tab-content">
<div role="tabpanel" class="tab-pane active with-3d-shadow with-transitions" t-att-id="'survey_stats_question_%d' % question.id">
<table class="table table-hover table-sm">
<thead>
<tr>
<th>User Responses</th>
<th>Occurence</th>
</tr>
</thead>
<tbody>
<!-- <tr t-foreach="number_result['most_common']" t-as="row">
<td>
<span t-esc="row[0]"></span>
</td>
<td>
<span t-esc="row[1]"></span>
</td>
</tr> -->
</tbody>
<thead>
<tr>
<th>User Responses</th>
<th>Occurence</th>
</tr>
</thead>
<tbody>
<tr t-foreach="summary_data['most_common']" t-as="common_value">
<td><span t-esc="common_value[0]"></span></td>
<td><span t-esc="common_value[1]"></span></td>
</tr>
</tbody>
</table>
</div>
<div role="tabpanel" class="tab-pane" t-att-id="'survey_data_question_%d' % question.id">

0 comments on commit fb9498d

Please sign in to comment.
You can’t perform that action at this time.