Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Tri dans l'ordre croissant les groupes de codes cléas de l'export n… #1785

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions app/models/restitution/positionnement/export_numeratie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ def initialize(partie, sheet)
end

def regroupe_par_codes_clea
questions_classees = questions_repondues_et_non_repondues.group_by do |e|
Metacompetence.new(e['metacompetence']).code_clea_sous_domaine
end

questions_classees.transform_values do |groupes|
groupes.group_by do |e|
Metacompetence.new(e['metacompetence']).code_clea_sous_sous_domaine
end
end
groupes_clea = regroupe_par_sous_domaine
regroupe_par_sous_sous_domaine(groupes_clea)
end

def questions_non_repondues
Expand All @@ -31,14 +24,6 @@ def questions_non_repondues
end
end

def questions_repondues_et_non_repondues
non_repondues = questions_non_repondues.map(&:as_json).each do |q|
q['scoreMax'] = q.delete('score')
q['question'] = q.delete('nom_technique')
end
@evenements_reponses.map(&:donnees) + non_repondues
end

def remplis_reponses(ligne, reponses)
reponses.each do |reponse|
question = Question.find_by(nom_technique: reponse['question'])
Expand All @@ -47,6 +32,32 @@ def remplis_reponses(ligne, reponses)
ligne
end

private

def regroupe_par_sous_domaine
groupes_clea = questions_repondues_et_non_repondues.group_by do |e|
Metacompetence.new(e['metacompetence']).code_clea_sous_domaine
end
tri_par_ordre_croissant(groupes_clea)
end

def regroupe_par_sous_sous_domaine(groupes_clea)
groupes_clea.transform_values do |groupes|
sous_groupes_clea = groupes.group_by do |e|
Metacompetence.new(e['metacompetence']).code_clea_sous_sous_domaine
end
tri_par_ordre_croissant(sous_groupes_clea)
end
end

def questions_repondues_et_non_repondues
non_repondues = questions_non_repondues.map(&:as_json).each do |q|
q['scoreMax'] = q.delete('score')
q['question'] = q.delete('nom_technique')
end
@evenements_reponses.map(&:donnees) + non_repondues
end

def remplis_ligne(ligne, donnees, question)
code = Metacompetence.new(donnees['metacompetence']).code_clea_sous_sous_domaine
@sheet.row(ligne).replace([code,
Expand All @@ -73,6 +84,10 @@ def remplis_choix(ligne, donnees, question)
def question_rattrapage(nom_technique)
nom_technique.start_with?('N1R', 'N2R', 'N3R')
end

def tri_par_ordre_croissant(groupes_clea)
groupes_clea.sort_by { |code, _| code.to_s }.to_h
end
end
end
end
49 changes: 32 additions & 17 deletions spec/models/restitution/positionnement/export_numeratie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,40 @@
end

describe 'quand il y a des questions non répondues' do
let(:question1) { create(:question_qcm, nom_technique: 'LOdi3', metacompetence: :surfaces) }
let(:question2) { create(:question_qcm, nom_technique: 'LOdi2', metacompetence: :estimation) }
let(:questions) do
[
create(:question_qcm, nom_technique: 'LOdi3', metacompetence: :surfaces),
create(:question_qcm, nom_technique: 'LOdi2', metacompetence: :estimation),
create(:question_qcm, nom_technique: 'LOdi4', metacompetence: :tableaux_graphiques)
]
end

it 'trie les evenements et les questions non répondues par code clea' do
let!(:evenements) do
[
create(:evenement_reponse, partie: partie,
donnees: { question: 'LOdi1', metacompetence: :surfaces }),
create(:evenement_reponse, partie: partie,
donnees: { question: 'LOdi2', metacompetence: :estimation })
]
end

let(:liste) { response_service.regroupe_par_codes_clea }

before do
partie.situation.update(questionnaire: create(:questionnaire))
partie.situation.questionnaire.questions << question1
evenement1 = create :evenement_reponse,
partie: partie,
donnees: { question: 'LOdi1', metacompetence: :surfaces }
evenement2 = create :evenement_reponse,
partie: partie,
donnees: { question: 'LOdi2', metacompetence: :estimation }

service = response_service.regroupe_par_codes_clea

expect(service['2.1']['2.1.4']).to eq([evenement2.donnees])
expect(service['2.3']['2.3.7'][0]).to eq(evenement1.donnees)
expect(service['2.3']['2.3.7'][1]['question']).to eq(question1.nom_technique)
expect(service['2.3']['2.3.7'][1]['scoreMax']).to eq(question1.score)
partie.situation.questionnaire.questions.push(*questions)
end

it 'trie les evenements et les questions non répondues par code clea' do
expect(liste['2.1']['2.1.4']).to eq([evenements[1].donnees])
expect(liste['2.3']['2.3.7'][0]).to eq(evenements[0].donnees)
expect(liste['2.3']['2.3.7'][1]['question']).to eq(questions[0].nom_technique)
expect(liste['2.3']['2.3.7'][1]['scoreMax']).to eq(questions[0].score)
end

it "tri dans l'ordre croissant" do
expect(liste.keys).to eq(['2.1', '2.3'])
expect(liste['2.3'].keys).to eq(['2.3.5', '2.3.7'])
end
end
end
Expand Down
Loading