Skip to content

Instantly share code, notes, and snippets.

@mboya
Last active May 15, 2024 16:07
Show Gist options
  • Save mboya/17e79612ef775bd950af17f006679fa4 to your computer and use it in GitHub Desktop.
Save mboya/17e79612ef775bd950af17f006679fa4 to your computer and use it in GitHub Desktop.
Task Scheduler
# automation methis 'assign_task' to be able to match work with eng based on skills and availability
def assign_task(available_eng, tasks)
assigned = Hash.new { |hash, key| hash[key] = [] }
tasks.each do |task|
eng_suited = available_eng.select do |eng|
eng.availability && ((eng.skills & task.skills_required).sort).eql?(task.skills_required.sort)
end
assign = eng_suited.sort_by { |e| assigned[e].sum(&:duration) }.first
if assign
assigned[assign] << task
else
"failed to assign #{task.title}"
end
end
assigned
end
# Engineer class with the following attributes
# - name
# - skills
# - availability
class Engineer
attr_accessor :name, :skills, :availability
def initialize(name, skills, availability)
@name = name
@skills = skills
@availability = availability
end
end
# Task class with the following attributes
# - title
# - skills_required
# - duration
class Task
attr_accessor :title, :skills_required, :duration
def initialize(title, skills_required, duration)
@title = title
@skills_required = skills_required
@duration = duration
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment