Some users may have previously published a featured exercise in all the monthly featured tracks prior to 2023. This would render the user ineligible for the yearlong 12in23 badge.
Suggested logic to consider that exercise as completed for the challenge:
- construct a hash where the keys are exercise slugs and the values are hashes mapping the tracks to nil
- loop over the user’s solutions and populate the published year for the exercise and track (my Rails-fu is weak)
- find the exercises where the track map includes a value 2023 or all the values are not nil
challenge_exercise_map = {}
feb_exercises.each {|e| challenge_exercise_map[e] = feb_tracks.inject({}) {|h, t| h[t] = nil; h}}
march_exercises.each {|e| challenge_exercise_map[e] = march_tracks.inject({}) {|h, t| h[t] = nil; h}}
april_exercises.each {|e| challenge_exercise_map[e] = april_tracks.inject({}) {|h, t| h[t] = nil; h}}
current_user.solutions.published.
joins(:track).pluck('tracks.slug', 'exercises.slug').
select do |track_slug, exercise_slug|
if challenge_exercise_map.has_key?(exercise_slug) && challenge_exercise_map[exercise_slug].has_key?(track_slug)
challenge_exercise_map[exercise_slug][track_slug] = YEAR(solution.published_at) # TODO handwaving
end
end
challenge_exercise_map.select! {|exercise_slug, track_map|
years = track_map.values
years.any? {|y| y == 2023} || years.none?(&nil?)
end
@badge_progress_exercises = challenge_exercise_map.keys