Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

scorer.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const config = require('../../../db/data-generator/config.json')
  2. const makeScoreLookup = (aspects, labels) => {
  3. const labelLookup = {}
  4. labels.forEach(label => (labelLookup[label.aspect_id] = label))
  5. const scoreLookup = {}
  6. aspects.forEach(aspect => {
  7. const key = labelLookup[aspect.aspect_id]
  8. scoreLookup[`${key.a}:${key.b}`] = {}
  9. Object.keys(aspect).forEach(aspect_id => {
  10. if (!labelLookup[aspect_id]) return
  11. const comp = labelLookup[aspect_id]
  12. const score = aspect[aspect_id]
  13. scoreLookup[`${key.a}:${key.b}`][`${comp.a}:${comp.b}`] = score
  14. })
  15. })
  16. return scoreLookup
  17. }
  18. const _isScorableResponse = res_key_id =>
  19. config.scoreKeys.includes(res_key_id) ? true : false
  20. const scoreResponses = (seeker, potentialMatch, prescoreLookup) => {
  21. if (seeker.responses.length != potentialMatch.responses.length)
  22. return {
  23. error: `complete responses for profile: ${seeker.profile_id} unqeual to profile: ${potentialMatch.profile_id} | ${seeker.responses.length}:${potentialMatch.responses.length}`,
  24. }
  25. const aRes = seeker.responses.filter(res =>
  26. _isScorableResponse(res.response_key_id),
  27. )
  28. const bRes = potentialMatch.responses.filter(res =>
  29. _isScorableResponse(res.response_key_id),
  30. )
  31. const composite = []
  32. while (aRes.length + bRes.length > 0) {
  33. const mKey = resList => {
  34. let el = resList.shift()
  35. let pair = el.val
  36. el = resList.shift()
  37. return `${pair}:${el.val}`
  38. }
  39. composite.push(prescoreLookup[mKey(aRes)][mKey(bRes)])
  40. }
  41. const scoreAvg = composite.reduce((a, b) => a + b) / composite.length
  42. return {
  43. total: Math.round(scoreAvg),
  44. aspects: composite,
  45. }
  46. }
  47. const scoreAll = (profileList, userProfile, prescoreLookup) => {
  48. return profileList.map(profile => {
  49. return {
  50. // Uncomment to return the whole profile
  51. // ...profile,
  52. profile_id: profile.profile_id,
  53. score: scoreResponses(userProfile, profile, prescoreLookup),
  54. distance: profile.distance,
  55. }
  56. })
  57. }
  58. module.exports = {
  59. _isScorableResponse,
  60. scoreResponses,
  61. makeScoreLookup,
  62. scoreAll,
  63. }