màj sondage

This commit is contained in:
Nicolas Bally 2013-07-18 11:17:41 +02:00
parent e04f9d891e
commit c0397336d5
9 changed files with 259 additions and 220 deletions

View File

@ -3,7 +3,7 @@
class AnswerSet < ActiveRecord::Base class AnswerSet < ActiveRecord::Base
belongs_to :question_set belongs_to :question_set
belongs_to :survey_item_answer belongs_to :survey_item_answer
attr_accessible :content, :survey_item_answer_id, :is_checked attr_accessible :content, :survey_item_answer_id, :is_checked, :position
before_validation do before_validation do

View File

@ -7,7 +7,7 @@ class QuestionSet < ActiveRecord::Base
accepts_nested_attributes_for :answer_sets accepts_nested_attributes_for :answer_sets
scope :dont_answered, includes(:answer_sets).where("answer_sets.is_checked == ?", false) scope :dont_answered, includes(:answer_sets).where("answer_sets.is_checked == ?", false)
end end

View File

@ -4,7 +4,7 @@ class SurveyItem < ActiveRecord::Base
attr_accessible :description, :display_type, :help, :item_type, :questions_type, :string_type, :title, :archived, :locked, :text_presentation, :max_checkboxes attr_accessible :description, :display_type, :help, :item_type, :questions_type, :string_type, :title, :archived, :locked, :text_presentation, :max_checkboxes
ITEM_TYPES = ["question", "note"] ITEM_TYPES = ["question", "note"]
QUESTIONS_TYPES = ["boolean", "string", "check_box", "radio", "little_string"] QUESTIONS_TYPES = ["boolean", "string", "check_box", "radio", "order"]
DISPLAY_TYPES = ["inline", "grid", "dropdown"] DISPLAY_TYPES = ["inline", "grid", "dropdown"]
has_many :answers, :class_name => "SurveyItemAnswer", :dependent => :destroy has_many :answers, :class_name => "SurveyItemAnswer", :dependent => :destroy

View File

@ -17,7 +17,7 @@ class SurveyType < ActiveRecord::Base
question_set = @survey_set.question_sets.build(:survey_item_id => item.id) question_set = @survey_set.question_sets.build(:survey_item_id => item.id)
if item.questions_type == 3 if item.questions_type == 3 || item.questions_type == 5
item.answers.each do |answer| item.answers.each do |answer|

View File

@ -3,217 +3,235 @@
#container #container
-@survey.items.each do |item| -@survey.items.each do |item|
%h3=item.title %h3=item.title
-if item.questions_type == 1 -if item.questions_type == 1
%table %table
%tr %tr
%th oui %th oui
%th non %th non
%th nr %th nr
%th non + nr %th non + nr
%tr %tr
%td %td
=oui = item.question_sets.where(:boolean_content => true).count =oui = item.question_sets.where(:boolean_content => true).count
%td %td
=non = item.question_sets.where(:boolean_content => false).count =non = item.question_sets.where(:boolean_content => false).count
%td %td
=nr = item.question_sets.count - non - oui =nr = item.question_sets.count - non - oui
%td %td
=nuls = nr + non =nuls = nr + non
%tr %tr
%td %td
=per_oui = number_to_percentage (oui*100.00)/(oui+nuls), :precision => 1 =per_oui = number_to_percentage (oui*100.00)/(oui+nuls), :precision => 1
%td %td
=per_non = number_to_percentage (non*100.00)/(oui+nuls), :precision => 1 =per_non = number_to_percentage (non*100.00)/(oui+nuls), :precision => 1
%td %td
=per_nr = number_to_percentage (nr*100.00)/(oui+nuls), :precision => 1 =per_nr = number_to_percentage (nr*100.00)/(oui+nuls), :precision => 1
%td %td
=number_to_percentage (nuls*100.00)/(oui+nuls), :precision => 1 =number_to_percentage (nuls*100.00)/(oui+nuls), :precision => 1
-r = rand 99999 -r = rand 99999
-chart_data = [{:name => "oui", :y => oui, :per => per_oui},{:name => "non", :y => non, :per => per_non} ,{:name => "non répondu", :y => nr, :per => per_nr} ] -chart_data = [{:name => "oui", :y => oui, :per => per_oui},{:name => "non", :y => non, :per => per_non} ,{:name => "non répondu", :y => nr, :per => per_nr} ]
%script %script
$(document).ready(function() { $(document).ready(function() {
charts.push(new Highcharts.Chart( charts.push(new Highcharts.Chart(
=raw 'getChartConfig("'+r.to_s+'", "'+item.title+'", '+chart_data.to_json+')' =raw 'getChartConfig("'+r.to_s+'", "'+item.title+'", '+chart_data.to_json+')'
)) ))
}); });
%div.chart{:id => r.to_s} %div.chart{:id => r.to_s}
-if item.questions_type == 2 -if item.questions_type == 2
%table.large %table.large
-count = 0 -count = 0
-item.question_sets.each do |question| -item.question_sets.each do |question|
-if question.content? -if question.content?
%tr %tr
%td=simple_format question.content %td=simple_format question.content
-else -else
-count = count+1 -count = count+1
%tr %tr
%td %td
non répondu : non répondu :
=count =count
( (
=per_nr = number_to_percentage (count*100.00)/(@survey.nbr_responses), :precision => 1 =per_nr = number_to_percentage (count*100.00)/(@survey.nbr_responses), :precision => 1
) )
-r = rand 99999 -r = rand 99999
-chart_data = "['répondu',#{(((@survey.nbr_responses-count)*100.00)/(@survey.nbr_responses)).round(1)}],['non répondu', #{((count*100.00)/(@survey.nbr_responses)).round(1)}]" -chart_data = "['répondu',#{(((@survey.nbr_responses-count)*100.00)/(@survey.nbr_responses)).round(1)}],['non répondu', #{((count*100.00)/(@survey.nbr_responses)).round(1)}]"
-chart_data = [{:name => "répondu", :y => (@survey.nbr_responses-count), :per => number_to_percentage(((@survey.nbr_responses-count)*100.00)/(@survey.nbr_responses), :precision => 1)} ,{:name => "non répondu", :y => count, :per => per_nr} ] -chart_data = [{:name => "répondu", :y => (@survey.nbr_responses-count), :per => number_to_percentage(((@survey.nbr_responses-count)*100.00)/(@survey.nbr_responses), :precision => 1)} ,{:name => "non répondu", :y => count, :per => per_nr} ]
%script %script
$(document).ready(function() { $(document).ready(function() {
charts.push(new Highcharts.Chart( charts.push(new Highcharts.Chart(
=raw 'getChartConfig("'+r.to_s+'", "'+item.title+'", '+chart_data.to_json+')' =raw 'getChartConfig("'+r.to_s+'", "'+item.title+'", '+chart_data.to_json+')'
)) ))
}); });
%div.chart{:id => r.to_s} %div.chart{:id => r.to_s}
-if item.questions_type == 3 -if item.questions_type == 3
-#chart_data = "['oui',#{oui}],['non',#{non}],['non répondu', #{nr}]" -#chart_data = "['oui',#{oui}],['non',#{non}],['non répondu', #{nr}]"
-chart_data = [] -chart_data = []
-categories = [] -categories = []
%table %table
-item.answers.each do |answer| -item.answers.each do |answer|
%tr %tr
%td=answer.label_text %td=answer.label_text
%td %td
=tot = answer.answer_sets.where(:is_checked => true).count =tot = answer.answer_sets.where(:is_checked => true).count
%td=per = number_to_percentage (tot*100.00)/(@survey.nbr_responses), :precision => 1 %td=per = number_to_percentage (tot*100.00)/(@survey.nbr_responses), :precision => 1
-categories << answer.label_text -categories << answer.label_text
-chart_data << {:name => answer.label_text, :y => tot, :per => per.to_s} -chart_data << {:name => answer.label_text, :y => tot, :per => per.to_s}
-count = 0 -count = 0
-item.question_sets.each do |qs| -item.question_sets.each do |qs|
-if qs.answer_sets.where(:is_checked => false).count == item.answers.count -if qs.answer_sets.where(:is_checked => false).count == item.answers.count
-count = count+1 -count = count+1
%tr %tr
%td non répondu %td non répondu
%td=count %td=count
%td=per = number_to_percentage (count*100.00)/(@survey.nbr_responses), :precision => 1 %td=per = number_to_percentage (count*100.00)/(@survey.nbr_responses), :precision => 1
-categories << "non répondu" -categories << "non répondu"
-chart_data << {:name => "non répondu", :y => count, :per => per.to_s} -chart_data << {:name => "non répondu", :y => count, :per => per.to_s}
-if item.answers.where(:field_type => [2,3]).count > 0 -if item.answers.where(:field_type => [2,3]).count > 0
-np = 0 -np = 0
-item.answers.where(:field_type => [2,3]).each do |a| -item.answers.where(:field_type => [2,3]).each do |a|
%h4 %h4
Réponses personnalisées pour " Réponses personnalisées pour "
=a.label_text =a.label_text
" "
%table.large %table.large
-a.answer_sets.each do |a| -a.answer_sets.each do |a|
-if a.content? -if a.content?
%tr %tr
%td{:colspan => 3}=a.content %td{:colspan => 3}=a.content
-else -else
-np = np +1 -np = np +1
%tr %tr
%td %td
Non précisé Non précisé
%td=np %td=np
%td=number_to_percentage (np*100.00)/(a.answer_sets.where(:is_checked => true).count), :precision => 1 %td=number_to_percentage (np*100.00)/(a.answer_sets.where(:is_checked => true).count), :precision => 1
-r = rand 99999 -r = rand 99999
%script %script
$(document).ready(function() { $(document).ready(function() {
=raw 'chartbar("'+r.to_s+'", '+chart_data.to_json+', '+categories.to_s+', "'+item.title+'");' =raw 'chartbar("'+r.to_s+'", '+chart_data.to_json+', '+categories.to_s+', "'+item.title+'");'
}); });
.bar_chart{:id => r} .bar_chart{:id => r}
-if item.questions_type == 4 -if item.questions_type == 4
-#chart_data = "['oui',#{oui}],['non',#{non}],['non répondu', #{nr}]" -#chart_data = "['oui',#{oui}],['non',#{non}],['non répondu', #{nr}]"
-chart_data = [] -chart_data = []
-categories = [] -categories = []
%table %table
-item.answers.each do |answer| -item.answers.each do |answer|
%tr %tr
%td=answer.label_text %td=answer.label_text
%td %td
=tot = item.question_sets.where(:content => answer.label_text).count =tot = item.question_sets.where(:content => answer.label_text).count
%td=per = number_to_percentage (tot*100.00)/(@survey.nbr_responses), :precision => 1 %td=per = number_to_percentage (tot*100.00)/(@survey.nbr_responses), :precision => 1
-categories << answer.label_text -categories << answer.label_text
-chart_data << {:name => answer.label_text, :y => tot, :per => per.to_s} -chart_data << {:name => answer.label_text, :y => tot, :per => per.to_s}
%tr %tr
%td non répondu %td non répondu
%td=count = item.question_sets.where(:content => nil).count %td=count = item.question_sets.where(:content => nil).count
%td=per = number_to_percentage (count*100.00)/(@survey.nbr_responses), :precision => 1 %td=per = number_to_percentage (count*100.00)/(@survey.nbr_responses), :precision => 1
-categories << "non répondu" -categories << "non répondu"
-chart_data << {:name => "non répondu", :y => count, :per => per.to_s} -chart_data << {:name => "non répondu", :y => count, :per => per.to_s}
-if item.answers.where(:field_type => 2).count > 0 -if item.answers.where(:field_type => 2).count > 0
-np = 0 -np = 0
-item.answers.where(:field_type => 2).each do |a| -item.answers.where(:field_type => 2).each do |a|
%h4 %h4
Réponses personnalisées pour " Réponses personnalisées pour "
=a.label_text =a.label_text
" "
%table.large %table.large
-a.answer_sets.where(:is_checked => true).each do |a| -a.answer_sets.where(:is_checked => true).each do |a|
-if a.content? -if a.content?
%tr %tr
%td{:colspan => 3}=a.content %td{:colspan => 3}=a.content
-else -else
-np = np +1 -np = np +1
%tr %tr
%td %td
Non précisé Non précisé
%td=np %td=np
%td=number_to_percentage (np*100.00)/(a.answer_sets.where(:is_checked => true).count), :precision => 1 %td=number_to_percentage (np*100.00)/(a.answer_sets.where(:is_checked => true).count), :precision => 1
-r = rand 99999 -r = rand 99999
%script %script
$(document).ready(function() { $(document).ready(function() {
-if item.answers.count > 4 -if item.answers.count > 4
=raw 'chartbar("'+r.to_s+'", '+chart_data.to_json+', '+categories.to_s+', "'+item.title+'");' =raw 'chartbar("'+r.to_s+'", '+chart_data.to_json+', '+categories.to_s+', "'+item.title+'");'
-else -else
charts.push(new Highcharts.Chart( charts.push(new Highcharts.Chart(
=raw 'getChartConfig("'+r.to_s+'", "'+item.title+'", '+chart_data.to_json+')' =raw 'getChartConfig("'+r.to_s+'", "'+item.title+'", '+chart_data.to_json+')'
)); ));
}); });
.bar_chart{:id => r} .bar_chart{:id => r}
.break .break
-if item.questions_type == 5
-#chart_data = "['oui',#{oui}],['non',#{non}],['non répondu', #{nr}]"
-chart_data = []
-categories = []
-item.question_sets.each do |question_set|
%table
-question_set.answer_sets.order("position ASC").each do |answer_set|
%tr
%td=answer_set.position
%td=answer_set.survey_item_answer.label_text
%td=answer_set.content
%br

View File

@ -1,19 +1,31 @@
-if @item.questions_type == 3
.answer_p
.answer_p
=f.check_box :is_checked, :class => "checkboxe_#{answer.survey_item.id}" =f.check_box :is_checked, :class => "checkboxe_#{answer.survey_item.id}"
-checkboxe_class = "checkboxe_#{answer.survey_item.id}" -checkboxe_class = "checkboxe_#{answer.survey_item.id}"
=f.label :is_checked, answer.label_text =f.label :is_checked, answer.label_text
=f.text_field :content if answer.field_type == 2 =f.text_field :content if answer.field_type == 2
%br %br
=f.text_area :content, :class => "large" if answer.field_type == 3 =f.text_area :content, :class => "large" if answer.field_type == 3
-if @item.questions_type == 5
.answer_p
=f.text_field :position, :style => "width:1.5em;"
=f.label :position, answer.label_text
=f.text_field :content if answer.field_type == 2
%br
=f.text_area :content, :class => "large" if answer.field_type == 3

View File

@ -1,5 +1,5 @@
.question=item.title .question=item.title
-@item = item
-if item.questions_type == 1 -if item.questions_type == 1
.answer_p .answer_p
@ -27,6 +27,12 @@
=f.radio_button :content, answer.label_text =f.radio_button :content, answer.label_text
=f.label :content, answer.label_text, :value => answer.label_text =f.label :content, answer.label_text, :value => answer.label_text
-elsif item.questions_type == 5
= f.fields_for(:answer_sets) do |f|
=f.hidden_field :survey_item_answer_id
=render :partial => "survey_sets/answer_set", :locals => {:f => f, :answer => f.object.survey_item_answer}

View File

@ -49,14 +49,14 @@ item.answers.build(:label_text => "Lusage agricole, irrigation des cultures",
item.answers.build(:label_text => "Lusage touristique (neige artificielle, arrosage espaces verts, piscine, spa, aménagement détangs de loisir)", :field_type => 1) item.answers.build(:label_text => "Lusage touristique (neige artificielle, arrosage espaces verts, piscine, spa, aménagement détangs de loisir)", :field_type => 1)
item = @survey.items.build(:questions_type => 3, :title => "Parmi les solutions proposées pour diminuer les problèmes de quantité de la ressource en eau, quelle priorisation souhaiteriez-vous appliquer dans votre département ? (merci dindiquer lordre de priorité par des chiffres, de 1 à 6, devant les carrés)", :item_type => 1) item = @survey.items.build(:questions_type => 5, :title => "Parmi les solutions proposées pour diminuer les problèmes de quantité de la ressource en eau, quelle priorisation souhaiteriez-vous appliquer dans votre département ? (merci dindiquer lordre de priorité par des chiffres, de 1 à 6, devant les carrés)", :item_type => 1)
item.answers.build(:label_text => "Adaptation des cultures (plantes et méthodes) et des techniques dirrigation", :field_type => 1) item.answers.build(:label_text => "Adaptation des cultures (plantes et méthodes) et des techniques dirrigation", :field_type => 1)
item.answers.build(:label_text => "Sensibilisation des ménages/collectivités et restrictions obligatoires plus sévères en cas de sécheresse, aide à la mise en place de dispositifs/bonnes pratiques pour limiter les prélèvements.", :field_type => 1) item.answers.build(:label_text => "Sensibilisation des ménages/collectivités et restrictions obligatoires plus sévères en cas de sécheresse, aide à la mise en place de dispositifs/bonnes pratiques pour limiter les prélèvements.", :field_type => 1)
item.answers.build(:label_text => "Changement et adaptation des procédés et des productions industriels", :field_type => 1) item.answers.build(:label_text => "Changement et adaptation des procédés et des productions industriels", :field_type => 1)
item.answers.build(:label_text => "Adaptation de lurbanisation en fonction de la disponibilité de la ressource en eau", :field_type => 1) item.answers.build(:label_text => "Adaptation de lurbanisation en fonction de la disponibilité de la ressource en eau", :field_type => 1)
item.answers.build(:label_text => "Adaptation de lusage touristique de la ressource en eau en cas de sécheresse", :field_type => 1) item.answers.build(:label_text => "Adaptation de lusage touristique de la ressource en eau en cas de sécheresse", :field_type => 1)
item.answers.build(:label_text => "Suspension ou interdiction de certains usages, précisez lesquels : ", :field_type => 3) item.answers.build(:label_text => "Suspension ou interdiction de certains usages, précisez lesquels : ", :field_type => 2)
item.answers.build(:label_text => "Autres > Précisez ", :field_type => 3) item.answers.build(:label_text => "Autres > Précisez ", :field_type => 2)
@ -66,11 +66,13 @@ item.answers.build(:label_text => "Autres > Précisez ", :field_type => 3)
@survey.save @survey.save
add_column :answer_sets, :position, :integer
end end
def down def down
remove_column :answer_sets, :position
@survey = SurveyType.find_by_slug("07-13-ressource-en-eau").destroy @survey = SurveyType.find_by_slug("07-13-ressource-en-eau").destroy
end end
end end

View File

@ -42,6 +42,7 @@ ActiveRecord::Schema.define(:version => 20130717000000) do
t.boolean "is_checked" t.boolean "is_checked"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.integer "position"
end end
add_index "answer_sets", ["question_set_id"], :name => "index_answer_sets_on_question_set_id" add_index "answer_sets", ["question_set_id"], :name => "index_answer_sets_on_question_set_id"