Wrinkle for 12in23: include exercise if previously completed in all tracks

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
2 Likes

@glennj Thanks :slight_smile:
@ErikSchierboom It might be worth rustling something up for this nowish, even if we don’t need it till December, so we have less of a rush at the end of the year.

1 Like

PR opened: Add badge for year-long #12in23 challenge by ErikSchierboom · Pull Request #5342 · exercism/website · GitHub