Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added algorithm for matching person with project.

  • Loading branch information...
commit 9c4aa13b8f7a257969dd3a850bc39b7f0e30b538 1 parent c4c6151
rhwang201 rhwang201 authored
18 app/models/project.rb
... ... @@ -1,3 +1,19 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: projects
  4 +#
  5 +# id :integer not null, primary key
  6 +# name :string(255)
  7 +# skill1 :string(255)
  8 +# skill2 :string(255)
  9 +# skill3 :string(255)
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +# person1 :string(255)
  13 +# person2 :string(255)
  14 +# person3 :string(255)
  15 +#
  16 +
1 17 class Project < ActiveRecord::Base
2   - attr_accessible :name, :skill1, :skill2, :skill3
  18 + attr_accessible :name, :skill1, :skill2, :skill3, :person1, :person2, :person3
3 19 end
90 app/models/user.rb
... ... @@ -1,3 +1,93 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: users
  4 +#
  5 +# id :integer not null, primary key
  6 +# name :string(255)
  7 +# ph_no :string(255)
  8 +# skill1 :string(255)
  9 +# skill2 :string(255)
  10 +# skill3 :string(255)
  11 +# created_at :datetime not null
  12 +# updated_at :datetime not null
  13 +#
  14 +
1 15 class User < ActiveRecord::Base
2 16 attr_accessible :name, :ph_no, :skill1, :skill2, :skill3
  17 +
  18 + # Returns the percentage of skills covered.
  19 + def skillCoverage(project)
  20 + covered = 0
  21 + if project.person1 != nil
  22 + covered += 1
  23 + end
  24 + if project.person2 != nil
  25 + covered += 1
  26 + end
  27 + if project.person3 != nil
  28 + covered += 1
  29 + end
  30 +
  31 + return covered / 3.0
  32 + end
  33 +
  34 + # Returns the project with the lowest percentage
  35 + # of skills obtained.
  36 + def worst(projects)
  37 + lowPercent = 1
  38 + lowProject = nil
  39 + projects.each do |project|
  40 + percent = skillCoverage(project)
  41 + if percent < lowPercent
  42 + lowProject = project
  43 + end
  44 + end
  45 + return lowProject
  46 + end
  47 +
  48 + # Returns projects that require skill and do not yet have a filling.
  49 + def projectsWithFree(skill)
  50 + ret = Projects.all.select { |project| project.skill1 == skill
  51 + or project.skill2 == skill
  52 + or project.skill3 == skill}
  53 + ret = ret.select { |project|
  54 + if project.skill1 == skill
  55 + return project.person1 == nil
  56 + elsif project.skill2 == skill
  57 + return project.person2 == nil
  58 + else
  59 + return project.person3 == nil
  60 + end
  61 + }
  62 + return ret
  63 + end
  64 +
  65 + def getProject
  66 + usedSkill = skill1
  67 + companies = projectsWithFree(skill1)
  68 + if companies.empty?
  69 + usedSkill = skill1
  70 + companies = projectsWithFree(skill2)
  71 + if companies.empty?
  72 + usedSkill = skill1
  73 + companies = projectsWithFree(skill3)
  74 + if companies.empty?
  75 + puts 'Shit'
  76 + return nil
  77 + end
  78 + end
  79 + end
  80 + selected = worst(companies)
  81 +
  82 + # Assign person to project
  83 + if usedSkill == skill1
  84 + selected.person1 = ph_no
  85 + elsif usefSkill == skill2
  86 + selected.person2 = ph_no
  87 + else
  88 + selected.person3 = ph_no
  89 + end
  90 +
  91 + return selected
  92 + end
3 93 end
5 db/schema.rb
@@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13
14   -ActiveRecord::Schema.define(:version => 20120804094818) do
  14 +ActiveRecord::Schema.define(:version => 20120804201839) do
15 15
16 16 create_table "projects", :force => true do |t|
17 17 t.string "name"
@@ -20,6 +20,9 @@
20 20 t.string "skill3"
21 21 t.datetime "created_at", :null => false
22 22 t.datetime "updated_at", :null => false
  23 + t.string "person1"
  24 + t.string "person2"
  25 + t.string "person3"
23 26 end
24 27
25 28 create_table "users", :force => true do |t|
16 test/fixtures/projects.yml
... ... @@ -1,3 +1,19 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: projects
  4 +#
  5 +# id :integer not null, primary key
  6 +# name :string(255)
  7 +# skill1 :string(255)
  8 +# skill2 :string(255)
  9 +# skill3 :string(255)
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +# person1 :string(255)
  13 +# person2 :string(255)
  14 +# person3 :string(255)
  15 +#
  16 +
1 17 # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2 18
3 19 one:
14 test/fixtures/users.yml
... ... @@ -1,3 +1,17 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: users
  4 +#
  5 +# id :integer not null, primary key
  6 +# name :string(255)
  7 +# ph_no :string(255)
  8 +# skill1 :string(255)
  9 +# skill2 :string(255)
  10 +# skill3 :string(255)
  11 +# created_at :datetime not null
  12 +# updated_at :datetime not null
  13 +#
  14 +
1 15 # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2 16
3 17 one:
16 test/unit/project_test.rb
... ... @@ -1,3 +1,19 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: projects
  4 +#
  5 +# id :integer not null, primary key
  6 +# name :string(255)
  7 +# skill1 :string(255)
  8 +# skill2 :string(255)
  9 +# skill3 :string(255)
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +# person1 :string(255)
  13 +# person2 :string(255)
  14 +# person3 :string(255)
  15 +#
  16 +
1 17 require 'test_helper'
2 18
3 19 class ProjectTest < ActiveSupport::TestCase
14 test/unit/user_test.rb
... ... @@ -1,3 +1,17 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: users
  4 +#
  5 +# id :integer not null, primary key
  6 +# name :string(255)
  7 +# ph_no :string(255)
  8 +# skill1 :string(255)
  9 +# skill2 :string(255)
  10 +# skill3 :string(255)
  11 +# created_at :datetime not null
  12 +# updated_at :datetime not null
  13 +#
  14 +
1 15 require 'test_helper'
2 16
3 17 class UserTest < ActiveSupport::TestCase

0 comments on commit 9c4aa13

Please sign in to comment.
Something went wrong with that request. Please try again.