Permalink
Browse files

Added algorithm for matching person with project.

  • Loading branch information...
1 parent c4c6151 commit 9c4aa13b8f7a257969dd3a850bc39b7f0e30b538 @rhwang201 rhwang201 committed Aug 4, 2012
Showing with 171 additions and 2 deletions.
  1. +17 −1 app/models/project.rb
  2. +90 −0 app/models/user.rb
  3. +4 −1 db/schema.rb
  4. +16 −0 test/fixtures/projects.yml
  5. +14 −0 test/fixtures/users.yml
  6. +16 −0 test/unit/project_test.rb
  7. +14 −0 test/unit/user_test.rb
View
18 app/models/project.rb
@@ -1,3 +1,19 @@
+# == Schema Information
+#
+# Table name: projects
+#
+# id :integer not null, primary key
+# name :string(255)
+# skill1 :string(255)
+# skill2 :string(255)
+# skill3 :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+# person1 :string(255)
+# person2 :string(255)
+# person3 :string(255)
+#
+
class Project < ActiveRecord::Base
- attr_accessible :name, :skill1, :skill2, :skill3
+ attr_accessible :name, :skill1, :skill2, :skill3, :person1, :person2, :person3
end
View
90 app/models/user.rb
@@ -1,3 +1,93 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# name :string(255)
+# ph_no :string(255)
+# skill1 :string(255)
+# skill2 :string(255)
+# skill3 :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
class User < ActiveRecord::Base
attr_accessible :name, :ph_no, :skill1, :skill2, :skill3
+
+ # Returns the percentage of skills covered.
+ def skillCoverage(project)
+ covered = 0
+ if project.person1 != nil
+ covered += 1
+ end
+ if project.person2 != nil
+ covered += 1
+ end
+ if project.person3 != nil
+ covered += 1
+ end
+
+ return covered / 3.0
+ end
+
+ # Returns the project with the lowest percentage
+ # of skills obtained.
+ def worst(projects)
+ lowPercent = 1
+ lowProject = nil
+ projects.each do |project|
+ percent = skillCoverage(project)
+ if percent < lowPercent
+ lowProject = project
+ end
+ end
+ return lowProject
+ end
+
+ # Returns projects that require skill and do not yet have a filling.
+ def projectsWithFree(skill)
+ ret = Projects.all.select { |project| project.skill1 == skill
+ or project.skill2 == skill
+ or project.skill3 == skill}
+ ret = ret.select { |project|
+ if project.skill1 == skill
+ return project.person1 == nil
+ elsif project.skill2 == skill
+ return project.person2 == nil
+ else
+ return project.person3 == nil
+ end
+ }
+ return ret
+ end
+
+ def getProject
+ usedSkill = skill1
+ companies = projectsWithFree(skill1)
+ if companies.empty?
+ usedSkill = skill1
+ companies = projectsWithFree(skill2)
+ if companies.empty?
+ usedSkill = skill1
+ companies = projectsWithFree(skill3)
+ if companies.empty?
+ puts 'Shit'
+ return nil
+ end
+ end
+ end
+ selected = worst(companies)
+
+ # Assign person to project
+ if usedSkill == skill1
+ selected.person1 = ph_no
+ elsif usefSkill == skill2
+ selected.person2 = ph_no
+ else
+ selected.person3 = ph_no
+ end
+
+ return selected
+ end
end
View
5 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120804094818) do
+ActiveRecord::Schema.define(:version => 20120804201839) do
create_table "projects", :force => true do |t|
t.string "name"
@@ -20,6 +20,9 @@
t.string "skill3"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.string "person1"
+ t.string "person2"
+ t.string "person3"
end
create_table "users", :force => true do |t|
View
16 test/fixtures/projects.yml
@@ -1,3 +1,19 @@
+# == Schema Information
+#
+# Table name: projects
+#
+# id :integer not null, primary key
+# name :string(255)
+# skill1 :string(255)
+# skill2 :string(255)
+# skill3 :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+# person1 :string(255)
+# person2 :string(255)
+# person3 :string(255)
+#
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
View
14 test/fixtures/users.yml
@@ -1,3 +1,17 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# name :string(255)
+# ph_no :string(255)
+# skill1 :string(255)
+# skill2 :string(255)
+# skill3 :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
View
16 test/unit/project_test.rb
@@ -1,3 +1,19 @@
+# == Schema Information
+#
+# Table name: projects
+#
+# id :integer not null, primary key
+# name :string(255)
+# skill1 :string(255)
+# skill2 :string(255)
+# skill3 :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+# person1 :string(255)
+# person2 :string(255)
+# person3 :string(255)
+#
+
require 'test_helper'
class ProjectTest < ActiveSupport::TestCase
View
14 test/unit/user_test.rb
@@ -1,3 +1,17 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# name :string(255)
+# ph_no :string(255)
+# skill1 :string(255)
+# skill2 :string(255)
+# skill3 :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
require 'test_helper'
class UserTest < ActiveSupport::TestCase

0 comments on commit 9c4aa13

Please sign in to comment.