From de1b8dc25e39d85d8f7d47fe189b7cd881032840 Mon Sep 17 00:00:00 2001 From: Felix Eckhofer <felix@eckhofer.com> Date: Sat, 4 Jan 2025 16:36:54 +0100 Subject: [PATCH] Add function to compare local and engelsystem assignments --- app/models/conference.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/models/conference.rb b/app/models/conference.rb index 440a35c..4e54003 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -67,4 +67,33 @@ class Conference < ApplicationRecord return nil end end + + def compare_engelsystem_shifts(additional_conferences = []) + return unless translation_angel_id = fetch_translation_angel_id + return unless data = fetch_engelsystem("angeltypes/#{translation_angel_id}/shifts") + engelsystem_shifts = data.each_with_object({}) do |shift, hash| + hash[shift['id']] = shift + &.dig("needed_angel_types") + &.find{ |t| t["angel_type"]["id"] == translation_angel_id } + &.dig("entries") + &.map{ |t| t["user"]["name"] } + end + Session.where(conference: [self]+additional_conferences).includes(:assignments).each do |session| + next if session.engelsystem_id.blank? + engelsystem_assigned = engelsystem_shifts[session.engelsystem_id] + local_assigned = session.assignments.includes(:user).map{|a|a.user.name} + + only_engelsystem = engelsystem_assigned - local_assigned + only_local = local_assigned - engelsystem_assigned + + unless only_engelsystem.blank? and only_local.blank? + puts "=============================" + puts "Session: #{session.title} (#{session.engelsystem_id})" + puts "=============================" + puts "Not signed up in engelsystem: #{only_local.join(", ")}" unless only_local.blank? + puts "Missing in local assignments: #{only_engelsystem.join(", ")}" unless only_engelsystem.blank? + puts + end + end + end end -- GitLab