-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudit.java
More file actions
254 lines (228 loc) · 7.51 KB
/
Audit.java
File metadata and controls
254 lines (228 loc) · 7.51 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import java.util.ArrayList;
/**
* <h3>COMP90041, Sem2, 2022: Final Project</h3>
* <p>Class Audit has methods to calculate statistics of matches.
*
* @author Gia Han Ly
*/
public class Audit {
private Jobs jobs = new Jobs();
private Applicant applications = new Applicant();
private Applied applied = new Applied();
private ArrayList<Applicant> removed = new ArrayList<>();
private int jobsAvail;
private int applicantAvail;
private int numOfSuccessMatch = 0;
//Constructor
/**
* Constructor for Audit
* @param jobsFile - jobs file name
* @param applicationsFile - applicantions file name
*/
public Audit(String jobsFile, String applicationsFile){
jobs.read(jobsFile);
applications.read(applicationsFile);
}
// Methods
/**
* Print out the statistics
*/
public void printStatistics(){
setUp();
printHeader();
availJobs();
numOfApplicants();
successfulMatches();
avgAgeSuccessful();
avgWAMSuccessful();
numOfGender("male");
numOfGender("female");
degreeStats("PHD");
}
/**
* Match all applicants available with all jobs available and select an applicant to move forward.
*
*/
private void setUp(){
applied.initialiseList();
for (ArrayList<Long> row : Applied.getAppliedList()){
for (Applicant a : Applicant.getApplicantsList()){
if (removedApplicant(a.createdAt) == true){
continue;
}
row.add(a.createdAt);
}
matchGenerate(row);
}
}
/**
* Generate match for each jobs, applicant that had been considered will not be considered for the next job
* @param row - job and its applications
*/
private void matchGenerate(ArrayList<Long> row){
Matchmaker matches = new Matchmaker();
matches.matchMaker(row);
Matchmaker.listOfMatches.add(matches);
removed.add(matches.getApplicant());
}
/**
* Check whether an applicant has been considered
* @param timestamp - timestamp of applications
* @return boolean true if the applicant has been considered, false if no
*/
private boolean removedApplicant(long timestamp){
for (Applicant applicant : removed){
if (timestamp == applicant.createdAt){
return true;
}
}
return false;
}
/**
* Display number of available jobs
*/
private void availJobs(){
this.jobsAvail = Jobs.getNumberofJobs();
if (jobsAvail == 0){
System.out.println("No jobs available for interrogation.");
}
System.out.println("Available jobs: " + jobsAvail);
}
/**
* Get the number of successful applicants
*/
private void successfulMatches(){
for (int i = 0; i < Matchmaker.listOfMatches.size(); i++){
Matchmaker match = Matchmaker.listOfMatches.get(i);
if (match.getApplicant() != null){
this.numOfSuccessMatch += 1;
}
}
System.out.println("Number of successful matches: " + numOfSuccessMatch);
}
/**
* Display number of available applicants
*/
private void numOfApplicants(){
this.applicantAvail = Applicant.getNumberOfApplicant();
if (applicantAvail == 0){
System.out.println("No applicants available for interrogation.");
}
System.out.println("Total number of applicants: " + applicantAvail);
}
/**
* Calculate and print the average age of successful applicants
*/
private void avgAgeSuccessful(){
int totalAge = 0;
double averageAge;
for (int i = 0; i < Matchmaker.listOfMatches.size(); i++){
Matchmaker match = Matchmaker.listOfMatches.get(i);
if (match.getApplicant() == null){
break;
}
totalAge += match.getApplicant().getAge();
}
averageAge = totalAge/numOfSuccessMatch;
System.out.printf("Average age: %.2f ",averageAge);
avgAgeAll();
}
/**
* Calculate and print the age of all applicants
*/
private void avgAgeAll(){
int totalAge = 0;
double averageAge;
for (Applicant applicant : Applicant.getApplicantsList()){
totalAge += applicant.getAge();
}
averageAge = totalAge/Applicant.getNumberOfApplicant();
System.out.printf("(average age of all applicants: %.2f) \n",averageAge);
}
/**
* Calculate and print the average WAM of successful applicants
*/
private void avgWAMSuccessful(){
double totalWAM = 0;
double averageWAM;
for (int i = 0; i < Matchmaker.listOfMatches.size(); i++){
Matchmaker match = Matchmaker.listOfMatches.get(i);
if (match.getApplicant() == null){
break;
}
totalWAM += match.getApplicant().wam;
}
averageWAM = totalWAM/numOfSuccessMatch;
System.out.printf("Average WAM: %.2f ", averageWAM);
avgWAMAll();
}
/**
* Calculate and print the average WAM of all applicants
*/
private void avgWAMAll(){
double totalWAM = 0;
double averageWAM;
for (Applicant applicant : Applicant.getApplicantsList()){
totalWAM += applicant.wam;
}
averageWAM = totalWAM/Applicant.getNumberOfApplicant();
System.out.printf("(average WAM of all applicants: %.2f) \n", averageWAM);
}
/**
* Calculate and print out the gender ratio between successful and all applicants
* @param gender - gender for ratio to be calculated
*/
private void numOfGender(String gender){
double numOfGenderSuccessful = 0;
double numOfGenderTotal = 0;
for (Applicant a : Applicant.getApplicantsList()){
if (a.getGender().equals(gender)){
numOfGenderTotal += 1;
}
}
for (Matchmaker match : Matchmaker.listOfMatches){
if (match.getApplicant() == null){
continue;
}
if (match.getApplicant().getGender().equals(gender)){
numOfGenderSuccessful += 1;
}
}
double stat = numOfGenderSuccessful/numOfGenderTotal;
System.out.printf("%s: %.1f\n", gender, stat);
}
/**
* Calculate degree statistics
* @param degree - degree type for ratios to be calculated
*/
private void degreeStats(String degree){
double numOfDegreeSuccessful = 0;
double numOfDegreeTotal = 0;
for (Applicant a : Applicant.getApplicantsList()){
if (a.degree.equals(degree)){
numOfDegreeTotal += 1;
}
}
for (Matchmaker match : Matchmaker.listOfMatches){
if (match.getApplicant() == null){
continue;
}
if (match.getApplicant().degree.equals(degree)){
numOfDegreeSuccessful += 1;
}
}
if (numOfDegreeTotal != 0){
double stat = numOfDegreeSuccessful/numOfDegreeTotal;
System.out.printf("%s: %.1f\n",degree, stat);
}
}
/**
* Print header for audit menu
*/
private void printHeader(){
String header = "======================================\n" +
"# Matchmaking Audit\n" +
"======================================\n";
System.out.print(header);
}
}