Przeglądaj źródła

:recycle: added test reveal profile 45 to mock | adjusted mock tags | refactored CompleteProfile creation

tabs-content
j 3 lat temu
rodzic
commit
3ffc6684c8

+ 1
- 1
backend/db/data-generator/config.json Wyświetl plik

2
     "mockOutputPath": "./db/generated",
2
     "mockOutputPath": "./db/generated",
3
     "magic": 1000,
3
     "magic": 1000,
4
     "total": 100,
4
     "total": 100,
5
-    "ignore": [45],
5
+    "ignore": [],
6
     "batchSize": 10,
6
     "batchSize": 10,
7
     "percentageOfSeekers": 90,
7
     "percentageOfSeekers": 90,
8
     "scoreVals": [1, 2, 3, 4, 5, 6, 7],
8
     "scoreVals": [1, 2, 3, 4, 5, 6, 7],

+ 1
- 1
backend/db/data-generator/mock.js Wyświetl plik

114
             tag_association_id: 5,
114
             tag_association_id: 5,
115
             profile_id: 45,
115
             profile_id: 45,
116
             grouping_id: 2,
116
             grouping_id: 2,
117
-            tag_id: 4,
117
+            tag_id: 8,
118
             is_deleted: false,
118
             is_deleted: false,
119
         },
119
         },
120
         {
120
         {

+ 28
- 23
backend/lib/services/profile/index.js Wyświetl plik

4
 const profiler = require('./profiler')
4
 const profiler = require('./profiler')
5
 const scoring = require('./scorer')
5
 const scoring = require('./scorer')
6
 const zipcoder = require('./zipcoder')
6
 const zipcoder = require('./zipcoder')
7
-const tagger = require('./tagger')
8
 
7
 
9
 module.exports = class ProfileService extends Schmervice.Service {
8
 module.exports = class ProfileService extends Schmervice.Service {
10
     constructor(...args) {
9
     constructor(...args) {
24
         }
23
         }
25
     }
24
     }
26
     async _setTagLookup() {
25
     async _setTagLookup() {
27
-        if (!Object.keys(this.tagLookup).length) {
28
-            const { Tag } = this.server.models()
29
-            const allTagDescriptions = await Tag.query()
30
-            allTagDescriptions.forEach(desc => {
31
-                if (desc.is_active) {
32
-                    this.tagLookup[desc.tag_id] = desc
33
-                }
34
-            })
35
-        }
26
+        /** Grab tag descriptions if they do NOT exist: Needed once per app load */
27
+        if (Object.keys(this.tagLookup).length) return
28
+        const { Tag } = this.server.models()
29
+        const allTagDescriptions = await Tag.query()
30
+        allTagDescriptions.forEach(desc => {
31
+            if (!desc.is_active) return
32
+            this.tagLookup[desc.tag_id] = desc
33
+        })
36
     }
34
     }
37
     /**
35
     /**
38
      * Internal method to get list of profile_ids for this user
36
      * Internal method to get list of profile_ids for this user
55
     async getProfile(profileId) {
53
     async getProfile(profileId) {
56
         const { Profile } = this.server.models()
54
         const { Profile } = this.server.models()
57
         await this._setTagLookup()
55
         await this._setTagLookup()
58
-
59
         const matchingProfile = await Profile.query()
56
         const matchingProfile = await Profile.query()
60
             .where('profile_id', profileId)
57
             .where('profile_id', profileId)
61
             .first()
58
             .first()
62
             .withGraphFetched('tags')
59
             .withGraphFetched('tags')
63
             .withGraphFetched('responses')
60
             .withGraphFetched('responses')
64
             .withGraphFetched('user')
61
             .withGraphFetched('user')
65
-        tagger.setProfileTags(matchingProfile, matchingProfile, this.tagLookup)
62
+        matchingProfile.tags = matchingProfile.tags.map(
63
+            tag => this.tagLookup[tag.tag_id],
64
+        )
66
         const complete = new profiler.CompleteProfile(matchingProfile, true)
65
         const complete = new profiler.CompleteProfile(matchingProfile, true)
67
         return this.setDefaults(complete)
66
         return this.setDefaults(complete)
68
     }
67
     }
81
             // so without this, we get undefined user_name
80
             // so without this, we get undefined user_name
82
             .withGraphFetched('user')
81
             .withGraphFetched('user')
83
 
82
 
84
-        return profiler.makeCompleteProfilesFromProfile(
83
+        return profiler.makeCompleteFromProfileEntries(
85
             profilesEntries,
84
             profilesEntries,
86
             type,
85
             type,
87
             this.tagLookup,
86
             this.tagLookup,
103
         // taking the info from profilesEntries
102
         // taking the info from profilesEntries
104
         // to repack into completeProfiles
103
         // to repack into completeProfiles
105
         // in same order as profileIdArray
104
         // in same order as profileIdArray
106
-        return profiler.makeCompleteProfiles(
105
+        return profiler.makeOrderedCompleteProfiles(
107
             profileIdArray,
106
             profileIdArray,
108
             profilesEntries,
107
             profilesEntries,
109
             type,
108
             type,
231
      * @param {object} complete
230
      * @param {object} complete
232
      * @returns {object} updated profile
231
      * @returns {object} updated profile
233
      */
232
      */
234
-    setDefaults(complete){
233
+    setDefaults(complete) {
235
         let defaultValues = {
234
         let defaultValues = {
236
             user_email: 'hidden@email.com',
235
             user_email: 'hidden@email.com',
237
-            user_name: 'Hidden Name'
236
+            user_name: 'Hidden Name',
238
         }
237
         }
239
 
238
 
240
         let defaultProfile = {
239
         let defaultProfile = {
242
             user_email: defaultValues.user_email,
241
             user_email: defaultValues.user_email,
243
             user_name: defaultValues.user_name,
242
             user_name: defaultValues.user_name,
244
         }
243
         }
245
-        console.log('defaultProfile: ', defaultProfile)
246
-        if(!complete.reveal.length) return defaultProfile // nothing to reveal 
244
+        console.log('---')
245
+        console.log('defaultProfile: ', defaultProfile.user_email)
246
+        if (!complete.reveal.length) return defaultProfile // nothing to reveal
247
 
247
 
248
         // swap out values of keys that are not found as complete.reveal.tag.tag_description values
248
         // swap out values of keys that are not found as complete.reveal.tag.tag_description values
249
-        for(let [attribute, defaultVal] of Object.entries(defaultValues)){
250
-            if(typeof complete.reveal.find(tag => tag.tag_description == attribute) == 'undefined') complete[attribute] = defaultVal 
249
+        for (let [attribute, defaultVal] of Object.entries(defaultValues)) {
250
+            if (
251
+                typeof complete.reveal.find(
252
+                    tag => tag.tag_description == attribute,
253
+                ) == 'undefined'
254
+            )
255
+                complete[attribute] = defaultVal
251
         }
256
         }
252
-        console.log('complete: ', complete)
257
+        console.log('complete: ', complete.user_email)
253
 
258
 
254
         return complete
259
         return complete
255
     }
260
     }
384
         await this._setTagLookup()
389
         await this._setTagLookup()
385
         let associations = groupingId
390
         let associations = groupingId
386
             ? await TagAssociation.query()
391
             ? await TagAssociation.query()
387
-                .where('grouping_id', groupingId)
388
-                .andWhere('profile_id', profileId)
392
+                  .where('grouping_id', groupingId)
393
+                  .andWhere('profile_id', profileId)
389
             : await TagAssociation.query().andWhere('profile_id', profileId)
394
             : await TagAssociation.query().andWhere('profile_id', profileId)
390
         return associations
395
         return associations
391
             .map(assoc => ({
396
             .map(assoc => ({

+ 26
- 31
backend/lib/services/profile/profiler.js Wyświetl plik

1
 const config = require('../../../db/data-generator/config.json')
1
 const config = require('../../../db/data-generator/config.json')
2
-const tagger = require('./tagger')
3
 
2
 
4
 /**
3
 /**
5
  * Class to hold our retrieved profile information
4
  * Class to hold our retrieved profile information
27
         // TODO: Use reveal tags to rebuild profile based on group/membership
26
         // TODO: Use reveal tags to rebuild profile based on group/membership
28
         // TODO: and include for certain profiles
27
         // TODO: and include for certain profiles
29
 
28
 
30
-        this.reveal = profile.tags.filter(t => t.category == 'reveal')
29
+        this.reveal = profile.tags.filter(t => t.tag_category == 'reveal')
31
         // TODO: filter these correctly
30
         // TODO: filter these correctly
32
         if (profile?.responses?.length && includeResponses) {
31
         if (profile?.responses?.length && includeResponses) {
33
             // [] of all "profile" responses
32
             // [] of all "profile" responses
44
             ]
43
             ]
45
             const prefsKeys = config.prefKeys
44
             const prefsKeys = config.prefKeys
46
             prefs.forEach((pref, i) => {
45
             prefs.forEach((pref, i) => {
47
-                this.profile_prefs[pref] = this.responses.filter(
46
+                this.profile_prefs[pref] = this.responses.find(
48
                     r => r.response_key_id === prefsKeys[i],
47
                     r => r.response_key_id === prefsKeys[i],
49
-                )[0]
48
+                )
50
             })
49
             })
51
-            this.profile_description = this.responses
52
-                .filter(r => r.response_key_id === config.blurbKey)
53
-                .map(r => r.val)[0]
50
+            this.profile_description = this.responses.find(
51
+                r => r.response_key_id === config.blurbKey,
52
+            ).val
54
             this.profile_media = this.responses
53
             this.profile_media = this.responses
55
                 .filter(r => r.response_key_id === config.mediaKey)
54
                 .filter(r => r.response_key_id === config.mediaKey)
56
                 .map(r => r.val)
55
                 .map(r => r.val)
60
         }
59
         }
61
     }
60
     }
62
 }
61
 }
62
+const _makeCompleteProfile = (
63
+    profileEntry,
64
+    type,
65
+    tagLookup,
66
+    includeResponses,
67
+) => {
68
+    profileEntry.tags = profileEntry.tags.map(tag => tagLookup[tag.tag_id])
69
+    return new CompleteProfile(profileEntry, includeResponses, type)
70
+}
63
 
71
 
64
-const makeCompleteProfiles = (
65
-    profileIdArray,
72
+const makeOrderedCompleteProfiles = (
73
+    orderedProfileIds,
66
     profilesEntries,
74
     profilesEntries,
67
     type,
75
     type,
68
     includeResponses,
76
     includeResponses,
69
     tagLookup,
77
     tagLookup,
70
 ) => {
78
 ) => {
71
     const completeProfiles = []
79
     const completeProfiles = []
72
-    profileIdArray.forEach(pid => {
80
+    orderedProfileIds.forEach(pid => {
73
         profilesEntries.forEach(entry => {
81
         profilesEntries.forEach(entry => {
74
-            if (entry.profile_id == pid) {
75
-                const complete = new CompleteProfile(
76
-                    entry,
77
-                    type,
78
-                    includeResponses,
79
-                )
80
-                tagger.setProfileTags(entry, complete, tagLookup)
81
-                completeProfiles.push(complete)
82
-            }
82
+            if (entry.profile_id != pid) return
83
+            completeProfiles.push(
84
+                _makeCompleteProfile(entry, type, tagLookup, includeResponses),
85
+            )
83
         })
86
         })
84
     })
87
     })
85
     return completeProfiles
88
     return completeProfiles
86
 }
89
 }
87
-const makeCompleteProfilesFromProfile = (profilesEntries, type, tagLookup) => {
88
-    profilesEntries.forEach(profile => {
89
-        tagger.setProfileTags(profile, profile, tagLookup)
90
-    })
91
-
92
-    //** Get responses asociated with each profile_id */
93
-    return profilesEntries.map(profile => {
94
-        return new CompleteProfile(profile, type)
95
-    })
96
-}
90
+const makeCompleteFromProfileEntries = (profilesEntries, type, tagLookup) =>
91
+    profilesEntries.map(entry => _makeCompleteProfile(entry, type, tagLookup))
97
 
92
 
98
 module.exports = {
93
 module.exports = {
99
     CompleteProfile,
94
     CompleteProfile,
100
-    makeCompleteProfiles,
101
-    makeCompleteProfilesFromProfile,
95
+    makeOrderedCompleteProfiles,
96
+    makeCompleteFromProfileEntries,
102
 }
97
 }

+ 0
- 7
backend/lib/services/profile/tagger.js Wyświetl plik

1
-const setProfileTags = (inProfile, outProfile, tagLookup) => {
2
-    outProfile.tags = inProfile.tags.map(tag => tagLookup[tag.tag_id])
3
-}
4
-
5
-module.exports = {
6
-    setProfileTags,
7
-}

Ładowanie…
Anuluj
Zapisz