-
Notifications
You must be signed in to change notification settings - Fork 0
/
RespondentMatcher.js
122 lines (109 loc) · 3.8 KB
/
RespondentMatcher.js
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
// Load project params as JS object
const projectParams = require("./data/project.json");
// Load utils functions
const { readRespondentsData } = require("./utils/parseInputData");
const matchRespondents = require("./utils/matchRespondentsToParams");
// Declare class
class RespondentMatcher {
constructor(respondentsDataFilePath, projectParams) {
this.respondentsDataFilePath = respondentsDataFilePath;
this.projectParams = projectParams;
this.results = [];
this.parsedData = {};
}
// Class getters
getRespondentsDataFilePath() {
return this.respondentsDataFilePath;
}
getProjectParams() {
return this.projectParams;
}
getResults() {
return this.results;
}
// Parse data method
async parseData() {
this.parsedData = await readRespondentsData(
this.respondentsDataFilePath
);
}
// Match respondents to project parameters
matchRespondentsToProjectParams() {
this.results = matchRespondents(this.parsedData, this.projectParams);
}
// Returns top eight results
returnTopEightResults() {
let results = [];
for (let i = 0; i < 8; i++) {
results.push(this.results[this.results.length - 1 - i]);
}
return results;
}
// Display all matches on terminal
displayAllMatchedRespondents() {
console.log("\nAll matches- ordered by matching scores:");
console.log("===================================\n");
for (let i = 0; i < this.results.length; i++) {
const curr = this.results[this.results.length - 1 - i];
console.log(i);
console.log(
`Name: ${curr.name.slice(0, 1).toUpperCase()}${curr.name.slice(
1
)}`
);
console.log(
`Number of matching industries: ${curr.industriesMatch.number}`
);
console.log(
`Job matches: ${(() =>
curr.jobMatches.match
? curr.jobMatches.jobTitle
: "No job matches")()}`
);
console.log(
`Closest available city: ${curr.closestAvailableCity.city}`
);
console.log(
`Distance to closest available city: ${curr.closestAvailableCity.distance}km`
);
console.log(`Matching Score: ${curr.score}`);
console.log("-------------------------------");
}
}
// Displays top 8 matches on terminal
displayTopEightMatchedRespondents() {
console.log("\nTop 8 matches- by matching scores:");
console.log("===================================\n");
for (let i = 0; i < 8; i++) {
const curr = this.results[this.results.length - 1 - i];
console.log(i);
console.log(
`Name: ${curr.name.slice(0, 1).toUpperCase()}${curr.name.slice(
1
)}`
);
console.log(
`Distance to closest available city: ${curr.closestAvailableCity.distance}km`
);
console.log(`Matching Score: ${curr.score}`);
console.log("-------------------------------");
}
}
}
const newMatcher = new RespondentMatcher(
"./data/respondents_data_test.csv",
projectParams
);
const demo = () =>
(async () => {
await newMatcher.parseData();
newMatcher.matchRespondentsToProjectParams();
newMatcher.displayTopEightMatchedRespondents();
})();
const demo2 = () =>
(async () => {
await newMatcher.parseData();
newMatcher.matchRespondentsToProjectParams();
newMatcher.displayAllMatchedRespondents();
})();
module.exports = { RespondentMatcher, demo, demo2 };