From f773aa7f7664365e72c6f773cd123c08caf44a27 Mon Sep 17 00:00:00 2001 From: Godwin Date: Thu, 22 Sep 2016 13:19:17 -0700 Subject: [PATCH] Improved schedule conflict algorithm --- app/controllers/application_controller.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a785901..fe74085 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -606,17 +606,6 @@ class ApplicationController < LinguaFrancaApplicationController end end - (0..ids.length).each do | j | - workshop_j = time_data[:item][:workshops][ids[j]].present? ? time_data[:item][:workshops][ids[j]][:workshop] : nil - if workshop_i.present? && workshop_j.present? && workshop_i.id != workshop_j.id - workshop_i.interested.each do | interested_i | - workshop_j.interested.each do | interested_j | - conflicts[interested_i.id] ||= true - end - end - end - end - location = workshop_i.event_location || EventLocation.new needs = JSON.parse(workshop_i.needs || '[]').map &:to_sym amenities = JSON.parse(location.amenities || '[]').map &:to_sym @@ -635,7 +624,16 @@ class ApplicationController < LinguaFrancaApplicationController } unless amenities.include? need end - @schedule[day][:times][time][:item][:workshops][ids[i]][:status][:conflict_score] = (conflicts || []).length + # collect common interested users + interests = [] + (0..ids.length).each do | j | + workshop_j = time_data[:item][:workshops][ids[j]].present? ? time_data[:item][:workshops][ids[j]][:workshop] : nil + if workshop_i.present? && workshop_j.present? && workshop_i.id != workshop_j.id + interests = interests | workshop_j.interested.map { | u | u.user_id } + end + end + + @schedule[day][:times][time][:item][:workshops][ids[i]][:status][:conflict_score] = (interests & (workshop_i.interested.map { | u | u.user_id })).length end end end