Quellcode durchsuchen

:bug: fixed zipcode scoring | limited to profiles with zipcode response | including user in profile for queue

tags/0.0.1
J vor 4 Jahren
Ursprung
Commit
da3d60797c

+ 3
- 1
backend/lib/routes/profile/queue.js Datei anzeigen

@@ -18,7 +18,9 @@ const responseSchemas = {
18 18
                 profile_id: Joi.number(),
19 19
                 user_id: Joi.number(),
20 20
                 responses: Joi.array().items(),
21
+                profile_image: Joi.string(),
21 22
                 user_type: Joi.any(),
23
+                user: Joi.object()
22 24
             }),
23 25
         )
24 26
     ),
@@ -56,7 +58,7 @@ module.exports = {
56 58
             if(include_profile) {
57 59
                 res.data = await profileService.getProfilesFor(queueIds)
58 60
             }
59
-            console.log(res.data)
61
+            // console.log(res.data)
60 62
             try {
61 63
                 return h.response(res).code(200)
62 64
             } catch (err) {

+ 2
- 2
backend/lib/routes/user/current.js Datei anzeigen

@@ -30,8 +30,8 @@ module.exports = {
30 30
         tags: ['api'],
31 31
         auth: 'default_jwt',
32 32
         handler: async function (request, h) {
33
-            console.log('current')
34
-            console.log(request)
33
+            // console.log('current')
34
+            // console.log(request)
35 35
             try {
36 36
                 const auth = {
37 37
                     credentials: request.auth.credentials,

+ 23
- 8
backend/lib/services/profile.js Datei anzeigen

@@ -1,7 +1,7 @@
1 1
 const Schmervice = require('@hapipal/schmervice')
2 2
 const cosineSimilarity = require('compute-cosine-similarity')
3 3
 const haversine = require('haversine')
4
-
4
+const zipcodeKey = 7
5 5
 const magic = 1000
6 6
 const scoreResponses = (seeker, potentialMatch) => {
7 7
     if (seeker.responses.length != potentialMatch.responses.length)
@@ -44,14 +44,16 @@ const scoreAll = (profileList, userProfile) => {
44 44
  */
45 45
 const getZipCodeFromProfile = profile => {
46 46
     // There should only be one zip code entry per profile
47
-    let zip = profile.responses.filter(
48
-        response => response.response_key_id == 16,
47
+    let zipRes = profile.responses.filter(
48
+        // Whatever the zipcode questions
49
+        response => response.response_key_id == zipcodeKey,
49 50
     )[0]
50
-    const responseIndexForZip = profile.responses.indexOf(zip)
51
+    const responseIndexForZip = profile.responses.indexOf(zipRes)
51 52
     if (responseIndexForZip >= 0) {
52 53
         profile.responses.splice(responseIndexForZip, 1)
53 54
     }
54
-    return zip.val
55
+    // console.log(zipRes)
56
+    return zipRes.val
55 57
 }
56 58
 
57 59
 /**
@@ -63,8 +65,11 @@ class CompleteProfile {
63 65
     constructor(profile, type) {
64 66
         this.user_id = profile.user_id // int user_id
65 67
         this.profile_id = profile.profile_id // int profile_id
68
+        this.profile_image = profile.user_media // int profile_id
66 69
         this.responses = profile.responses // [] of all responses
67 70
         this.user_type = type
71
+        
72
+        this.user = profile.user
68 73
     }
69 74
 }
70 75
 
@@ -112,6 +117,7 @@ module.exports = class ProfileService extends Schmervice.Service {
112 117
         const profilesEntries = await Profile.query()
113 118
             .whereIn('profile_id', profileIdArray)
114 119
             .withGraphFetched('responses')
120
+            .withGraphFetched('user')
115 121
 
116 122
         return profilesEntries.map(profile => {
117 123
             return new CompleteProfile(profile, type)
@@ -232,16 +238,25 @@ module.exports = class ProfileService extends Schmervice.Service {
232 238
         let profileIdsOfOppositeType = await Profile.query()
233 239
             .withGraphFetched('responses')
234 240
             .withGraphFetched('user')
235
-
241
+        
236 242
         // TODO: Let Objection optimize this
237 243
         const isPosterOpposite = userProfile.user.is_poster == 1 ? 0 : 1
238 244
         profileIdsOfOppositeType = profileIdsOfOppositeType.filter(
239 245
             profile => profile.user.is_poster == isPosterOpposite,
240 246
         )
241 247
 
248
+        // Only include profiles that included zipcode response
249
+        profileIdsOfOppositeType = profileIdsOfOppositeType.filter(profile => {
250
+            const zipcodeResponses = profile.responses.filter(response => response.response_key_id == zipcodeKey)
251
+            return zipcodeResponses.length > 0
252
+        })
253
+
242 254
         const profilePlusDistance = await Promise.all(
243 255
             profileIdsOfOppositeType.map(async profile => {
244 256
                 const targetZip = getZipCodeFromProfile(profile)
257
+                
258
+                if(!userZip || !targetZip) return { ...profile, distance: [9999, distanceUnit] }
259
+
245 260
                 const distance = await this._compareDistance(
246 261
                     userZip,
247 262
                     targetZip,
@@ -281,7 +296,7 @@ module.exports = class ProfileService extends Schmervice.Service {
281 296
             parseInt(zipCode),
282 297
         )
283 298
         if (!zipInfo) {
284
-            console.log(zipCode)
299
+            console.log('zip:', zipCode)
285 300
         }
286 301
 
287 302
         return {
@@ -297,7 +312,7 @@ module.exports = class ProfileService extends Schmervice.Service {
297 312
      * @param {number} distance in miles
298 313
      */
299 314
     async _compareDistance(start_zip, end_zip, distanceUnit) {
300
-        if (!start_zip || !end_zip) return
315
+        if (!start_zip || !end_zip || isNaN(start_zip) || isNaN(end_zip)) return
301 316
 
302 317
         const start = await this._latLonForZip(start_zip)
303 318
         const end = await this._latLonForZip(end_zip)

Laden…
Abbrechen
Speichern