您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

match-maker.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const similarity = require('compute-cosine-similarity')
  2. const magic = 1000
  3. const ScoreKeeper = {
  4. score: (seeker, potentialMatch) => {
  5. const seekerResponseValues = seeker.profileResponses.map(res =>
  6. parseInt(Object.values(res)),
  7. )
  8. console.log(seeker)
  9. const potentialMatchResponseValues =
  10. potentialMatch.profileResponses.map(res =>
  11. parseInt(Object.values(res)),
  12. )
  13. return Math.floor(
  14. similarity(seekerResponseValues, potentialMatchResponseValues) *
  15. magic,
  16. )
  17. },
  18. }
  19. module.exports = class MatchMaker {
  20. constructor(settings) {
  21. this.proposer = settings.proposer
  22. // Score main profile
  23. this.keeper = ScoreKeeper
  24. }
  25. runPrematch(settings) {
  26. // grab all profiles form the db
  27. // grab all responses
  28. // grab all response keys
  29. // create a full response object
  30. // create a full profile of responses
  31. const unscreenedProfiles = []
  32. const screenedProfiles = []
  33. for (const profile in unscreenedProfiles) {
  34. // Do something here
  35. if (!settings) {
  36. return
  37. }
  38. screenedProfiles.push(profile)
  39. }
  40. return screenedProfiles
  41. }
  42. matchFor(proposer, profiles, settings) {
  43. // Do something here
  44. return this.runPrematch(profiles, settings)
  45. }
  46. scoreProfiles(profiles) {
  47. const matchScores = []
  48. for (const profile in profiles) {
  49. const scored = this.keeper.score(profile)
  50. matchScores.push(scored)
  51. }
  52. return matchScores
  53. }
  54. }