Skip to content
Permalink
Browse files

tmp

  • Loading branch information
tde-banana-odoo committed Nov 29, 2019
1 parent 901fdbc commit 7a57bac30a4c964be146ed482da501ad29fb495d
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo><data noupdate="0">

<record model="survey.survey" id="survey_demo_quiz">
<record id="survey_demo_quiz" model="survey.survey">
<field name="title">Quiz about our Company</field>
<field name="access_token">b137640d-9876-1234-abcd-344ca256531e</field>
<field name="state">open</field>
<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>
</record>

<!-- Page 1: general information -->
<record model="survey.question" id="survey_demo_quiz_p1">
<record id="survey_demo_quiz_p1" model="survey.question">
<field name="title">General Information</field>
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">1</field>
@@ -24,14 +24,14 @@
<field name="description" type="html">
<p>Some general information about you. It will be used for statistics used internally.</p></field>
</record>
<record model="survey.question" id="survey_demo_quiz_p1_q1">
<record id="survey_demo_quiz_p1_q1" model="survey.question">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">2</field>
<field name="title">Where are you from ?</field>
<field name="question_type">textbox</field>
<field name="constr_mandatory" eval="True"/>
</record>
<record model="survey.question" id="survey_demo_quiz_p1_q2">
<record id="survey_demo_quiz_p1_q2" model="survey.question">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">3</field>
<field name="title">How old are you ?</field>
@@ -40,7 +40,7 @@
</record>

<!-- Page 2: quiz about products -->
<record model="survey.question" id="survey_demo_quiz_p2">
<record id="survey_demo_quiz_p2" model="survey.question">
<field name="title">Another page</field>
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">10</field>
@@ -49,58 +49,130 @@
<field name="description" type="html">
<p>Blah bleh blih bloh bluh</p></field>
</record>
<record model="survey.question" id="survey_demo_quiz_p2_q1">
<record id="survey_demo_quiz_p2_q1" model="survey.question">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">11</field>
<field name="title">How frequently do you buy products online ?</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 id="survey_demo_quiz_p2_q2" model="survey.question">
<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 id="survey_demo_quiz_p2_q3" model="survey.question">
<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 id="survey_demo_quiz_p3" model="survey.question">
<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 id="survey_demo_quiz_p3_q1" model="survey.question">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">21</field>
<field name="title">Simple choice</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 id="survey_demo_quiz_p3_q1_sug1" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q1"/>
<field name="sequence">1</field>
<field name="value">Once a day</field>
<field name="value">Correct (2)</field>
<field name="is_correct" eval="True"/>
<field name="answer_score">2</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 id="survey_demo_quiz_p3_q1_sug2" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q1"/>
<field name="sequence">2</field>
<field name="value">Once a week</field>
<field name="value">Correct (1)</field>
<field name="is_correct" eval="True"/>
<field name="answer_score">1</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 id="survey_demo_quiz_p3_q1_sug3" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q1"/>
<field name="sequence">3</field>
<field name="value">Once a month</field>
<field name="value">Incorrect</field>
</record>
<record model="survey.question" id="survey_demo_quiz_p2_q2">
<record id="survey_demo_quiz_p3_q2" model="survey.question">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">12</field>
<field name="title">Which of the following words would you use to describe our products ?</field>
<field name="sequence">22</field>
<field name="title">Multiple choice</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"/>
<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"/>
<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"/>
<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"/>
<field name="sequence">4</field>
<field name="value">Good value for money</field>
<record id="survey_demo_quiz_p3_q2_sug1" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">1</field>
<field name="value">High quality</field>
<field name="is_correct" eval="True"/>
<field name="answer_score">2</field>
</record>
<record id="survey_demo_quiz_p3_q2_sug2" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">2</field>
<field name="value">Useful</field>
</record>
<record id="survey_demo_quiz_p3_q2_sug3" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">3</field>
<field name="value">Unique</field>
</record>
<record id="survey_demo_quiz_p3_q2_sug4" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="sequence">4</field>
<field name="value">Good value for money</field>
<field name="is_correct" eval="True"/>
<field name="answer_score">1</field>
</record>
<record id="survey_demo_quiz_p3_q3" model="survey.question">
<field name="survey_id" ref="survey_demo_quiz"/>
<field name="sequence">22</field>
<field name="title">Matrix</field>
<field name="question_type">matrix</field>
<field name="comments_allowed" eval="True"/>
</record>
<record id="survey_demo_quiz_p3_q3_sug1" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q3"/>
<field name="sequence">1</field>
<field name="value">High quality</field>
<field name="is_correct" eval="True"/>
<field name="answer_score">2</field>
</record>
<record id="survey_demo_quiz_p3_q3_sug2" model="survey.question.answer">
<field name="question_id" ref="survey_demo_quiz_p3_q3"/>
<field name="sequence">2</field>
<field name="value">Useful</field>
</record>
<record id="survey_demo_quiz_p3_q3_sug3" model="survey.question.answer">
<field name="matrix_question_id" ref="survey_demo_quiz_p3_q3"/>
<field name="sequence">3</field>
<field name="value">Row 1</field>
</record>
<record id="survey_demo_quiz_p3_q3_sug4" model="survey.question.answer">
<field name="matrix_question_id" ref="survey_demo_quiz_p3_q3"/>
<field name="sequence">4</field>
<field name="value">Row 2</field>
</record>
</data></odoo>
@@ -47,6 +47,42 @@
<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_1_p3_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_p3_q1"/>
<field name="suggested_answer_id" ref="survey_demo_quiz_p3_q1_sug1"/>
</record>
<record id="survey_demo_quiz_answer_1_p3_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_p3_q2"/>
<field name="suggested_answer_id" ref="survey_demo_quiz_p3_q2_sug1"/>
</record>
<record id="survey_demo_quiz_answer_1_p3_q2_l2" model="survey.user_input.line">
<field name="user_input_id" ref="survey_demo_quiz_answer_1"/>
<field name="question_id" ref="survey_demo_quiz_p3_q2"/>
<field name="suggested_answer_id" ref="survey_demo_quiz_p3_q2_sug2"/>
</record>
<!-- <record id="survey_demo_quiz_answer_1_p3_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_p3_q1"/>
<field name="suggested_answer_id" ref="survey_demo_quiz_p3_q3_sug1"/>
<field name="matrix_row_id" ref="survey_demo_quiz_p3_q3_sug3"/>
</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):

0 comments on commit 7a57bac

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