|
|
@@ -1,8 +1,9 @@
|
|
1
|
1
|
const fs = require('fs')
|
|
|
2
|
+const cosineSimilarity = require('compute-cosine-similarity')
|
|
2
|
3
|
const mockOutputPath = './db/_generated.js'
|
|
3
|
4
|
|
|
4
|
5
|
// Insert here how many users you would like to generate:
|
|
5
|
|
-const total = 100
|
|
|
6
|
+const total = 10
|
|
6
|
7
|
let extraProfilesToGenerate = 0
|
|
7
|
8
|
|
|
8
|
9
|
// Amount of responses for a complete survey
|
|
|
@@ -161,10 +162,70 @@ profiles.forEach((profile, i) => {
|
|
161
|
162
|
}
|
|
162
|
163
|
})
|
|
163
|
164
|
|
|
|
165
|
+/**
|
|
|
166
|
+ * Score all the profiles!
|
|
|
167
|
+ */
|
|
|
168
|
+const scoreResponses = (seeker, potentialMatch) => {
|
|
|
169
|
+ const seekerResponses = responses
|
|
|
170
|
+ .filter(response => response.profile_id == seeker.profile_id)
|
|
|
171
|
+ .filter(response => response.val.length < 4)
|
|
|
172
|
+
|
|
|
173
|
+ const potentialMatchResponses = responses
|
|
|
174
|
+ .filter(response => response.profile_id == potentialMatch.profile_id)
|
|
|
175
|
+ .filter(response => response.val.length < 4)
|
|
|
176
|
+
|
|
|
177
|
+ const checkValCb = res => {
|
|
|
178
|
+ const val = parseInt(res.val)
|
|
|
179
|
+ return isNaN(val) ? 0 : val
|
|
|
180
|
+ }
|
|
|
181
|
+ return Math.floor(
|
|
|
182
|
+ cosineSimilarity(
|
|
|
183
|
+ seekerResponses.map(checkValCb),
|
|
|
184
|
+ potentialMatchResponses.map(checkValCb),
|
|
|
185
|
+ ) * 1000,
|
|
|
186
|
+ )
|
|
|
187
|
+}
|
|
|
188
|
+const scoreProfile = (profile, potentialMatchList) => {
|
|
|
189
|
+ const scored = potentialMatchList.map(profileToCompare => {
|
|
|
190
|
+ return {
|
|
|
191
|
+ match_queue_id: null,
|
|
|
192
|
+ profile_id: profile.profile_id,
|
|
|
193
|
+ target_id: profileToCompare.profile_id,
|
|
|
194
|
+ is_deleted: false,
|
|
|
195
|
+ score: scoreResponses(profile, profileToCompare),
|
|
|
196
|
+ }
|
|
|
197
|
+ })
|
|
|
198
|
+ return scored.sort((a, b) => a.score - b.score)
|
|
|
199
|
+}
|
|
|
200
|
+const scoreAll = () => {
|
|
|
201
|
+ let scores = []
|
|
|
202
|
+ const posterProfiles = profiles.filter(profile =>
|
|
|
203
|
+ jobPosterIds.includes(profile.user_id),
|
|
|
204
|
+ )
|
|
|
205
|
+ const seekerProfiles = profiles.filter(
|
|
|
206
|
+ profile => !jobPosterIds.includes(profile.user_id),
|
|
|
207
|
+ )
|
|
|
208
|
+ seekerProfiles.forEach(seeker => {
|
|
|
209
|
+ const scored = scoreProfile(seeker, posterProfiles)
|
|
|
210
|
+ scores = [...scored, ...scores]
|
|
|
211
|
+ })
|
|
|
212
|
+ posterProfiles.forEach(poster => {
|
|
|
213
|
+ const scored = scoreProfile(poster, seekerProfiles)
|
|
|
214
|
+ scores = [...scored, ...scores]
|
|
|
215
|
+ })
|
|
|
216
|
+ return scores.reverse()
|
|
|
217
|
+}
|
|
|
218
|
+const match_queues = scoreAll().map((score, i) => {
|
|
|
219
|
+ score.match_queue_id = i + 1
|
|
|
220
|
+ // Comment out to see the score
|
|
|
221
|
+ delete score.score
|
|
|
222
|
+ return score
|
|
|
223
|
+})
|
|
|
224
|
+
|
|
164
|
225
|
/**
|
|
165
|
226
|
* Our output format
|
|
166
|
227
|
*/
|
|
167
|
|
-const outputDataObject = { users, profiles, responses }
|
|
|
228
|
+const outputDataObject = { users, profiles, responses, match_queues }
|
|
168
|
229
|
|
|
169
|
230
|
const jobPostings = profiles.filter(profile =>
|
|
170
|
231
|
jobPosterIds.includes(profile.user_id),
|