-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchmaker.java
More file actions
157 lines (128 loc) · 4.53 KB
/
Matchmaker.java
File metadata and controls
157 lines (128 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Comparator;
/**
* <h3> COMP90041, Sem2, 2022: Final Project </h3>
* <p>Class Match contains the logic for matchmaking algorithm
* @author Gia Han Ly
*/
public class Matchmaker {
private Jobs job;
private Applicant applicant;
private Applied applied = new Applied();
private static List<List<Long>> applicantsApplied = new ArrayList<>();
private String requiredDegree;
private double averageWAMThreshold = 0;
private List<Applicant> selected = new ArrayList<>();
// Contains Match(Jobs, Applicant)
protected static List<Matchmaker> listOfMatches = new ArrayList<>();
public Matchmaker(){};
/**
* Constructor for Match
* @param job job matched
* @param applicant applicant matched
*/
public Matchmaker(Jobs job, Applicant applicant){
this.job = job;
this.applicant = applicant;
}
// Setters and getters
/**
* Get matched applicant
* @return matched applicant
*/
protected Applicant getApplicant(){
return this.applicant;
}
/**
* Copy list of jobs and its applications
*/
private void copyOfAppliedList() {
applied.loadApplied();
for (ArrayList<Long> row : Applied.getAppliedList()){
applicantsApplied.add(row);
}
}
/**
* Save matches
*/
public void saveMatches(){
copyOfAppliedList();
for (List<Long> row : applicantsApplied){
// Create new Match
Matchmaker match = new Matchmaker();
match.matchMaker(row);
// Add match to list of matches
listOfMatches.add(match);
}
}
/**
* Print applicant matched for each job
*/
protected static void printMatches(){
int listItem = 1;
for (Matchmaker match : listOfMatches){
Jobs matchJob = match.job;
Applicant matchApplicant = match.applicant;
// If there is no match, conitnue to next job
if (matchApplicant == null){
continue;
}
System.out.print("["+ listItem +"] ");
Jobs.printJob(matchJob);
System.out.print(" Applicant match: ");
Applicant.printApplicant(matchApplicant);
listItem++;
}
}
/**
* Select applicant based on WAM threshold (average WAM of all applications for the job) and minimum degree requirement
* @param row - job with its applications
*/
public void matchMaker(List<Long> row){
// Calculate WAM for applications
Applicant.wamCalc();
// Get requirements for the job (degree, WAM threshold)
jobRequirements(row);
for (int i = 1; i<row.size(); i++){
Applicant temp = Applicant.getApplicant(row.get(i));
// Check if applicant meets minium degree requirement
int check = new ApplicantDegreeComparator().compare(temp, requiredDegree);
// If applicant pass the WAM threshold and degree requirement, add to list of potential applicants
if (check <= 1 && temp.wam >= this.averageWAMThreshold){
this.selected.add(temp);
}
}
// Sort for wam, followed by oldest applicant
Collections.sort(selected, Comparator.comparing(Applicant :: getAge, Comparator.reverseOrder()).thenComparing(new ApplicantWAMComparator()));
// Select the highest rank applicant
if (selected.size() > 0){
this.applicant = selected.get(0);
}
else {
this.applicant = null;
}
}
/**
* Get requirements for job (WAM, degree)
* @param row - job with applications
*/
private void jobRequirements(List<Long> row){
// Get job object from timestamp and get minimum degree required
this.job = Jobs.getJob(row.get(0));
this.requiredDegree = job.degree;
double sumWAM = 0;
for (int i = 1; i<row.size(); i++){
Applicant temp = Applicant.getApplicant(row.get(i));
// Check if applicant pass the minimum degree requirement, if yes, add to average WAM threshold calculation
int check = new ApplicantDegreeComparator().compare(temp, requiredDegree);
if (check >= 0){
sumWAM += temp.wam;
}
}
if (row.size()-1 > 0){
this.averageWAMThreshold = sumWAM/(row.size()-1);
}
}
}