Skip to content

Commit

Permalink
♻️ Simplifie le regroupement par code cléa
Browse files Browse the repository at this point in the history
  • Loading branch information
marouria authored and cprodhomme committed Oct 28, 2024
1 parent 9bb302e commit 9522c19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 3 additions & 6 deletions app/models/restitution/export_positionnement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def nom_du_fichier
end

def regroupe_par_code_clea(evenements)
evenements.group_by do |evenement|
code = evenement.code_clea
[code.nil? ? 1 : 0, code]
end
evenements.group_by(&:code_clea)
end

private
Expand All @@ -64,8 +61,8 @@ def remplie_la_feuille(sheet)
end

def remplis_reponses_par_code(sheet, ligne, code, evenements)
if code[1].present?
sheet[ligne, 0] = "#{code[1]} - score: #{pourcentage_reussite(evenements)}%"
if code.present?
sheet[ligne, 0] = "#{code} - score: #{pourcentage_reussite(evenements)}%"
sheet.merge_cells(ligne, 0, ligne, 6)
end
ligne += 1
Expand Down
8 changes: 4 additions & 4 deletions spec/models/restitution/export_positionnement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@

describe '#regroupe_par_code_clea' do
it 'trie les evenements par code clea' do
evenement3 = create :evenement_reponse, partie: partie, donnees: { metacompetence: 'LOdi3' }
evenement1 = create :evenement_reponse, partie: partie,
donnees: { metacompetence: 'perimetres' }
evenement2 = create :evenement_reponse, partie: partie,
donnees: { metacompetence: 'estimation' }
evenement3 = create :evenement_reponse, partie: partie, donnees: { metacompetence: 'LOdi3' }

results = {
[0, '2.1.4'] => [evenement2],
[0, '2.3.7'] => [evenement1],
[1, nil] => [evenement3]
'2.1.4' => [evenement2],
'2.3.7' => [evenement1],
nil => [evenement3]
}

expect(response_service.regroupe_par_code_clea(Evenement.all)).to eq(results)
Expand Down

0 comments on commit 9522c19

Please sign in to comment.