Quellcode durchsuchen

:recycle: tweaking generator | importing generated files correctly | moving avatar to profile

tags/0.0.1
j vor 4 Jahren
Ursprung
Commit
4018adb43a

+ 1
- 1
backend/db/data-generator/classes.js Datei anzeigen

@@ -3,7 +3,6 @@ class User {
3 3
         this.user_id = id
4 4
         this.user_name = ''
5 5
         this.user_email = ''
6
-        this.user_media = ''
7 6
         this.is_admin = false
8 7
         this.is_poster = false
9 8
     }
@@ -12,6 +11,7 @@ class Profile {
12 11
     constructor(id, override) {
13 12
         this.user_id = override?.user_id ? override.user_id : id
14 13
         this.profile_id = override?.profile_id ? override.profile_id + id : id
14
+        this.user_media = ''
15 15
     }
16 16
 }
17 17
 class Response {

+ 4
- 4
backend/db/data-generator/config.js Datei anzeigen

@@ -1,12 +1,12 @@
1
-const mockOutputPath = './db/generated/_batch'
1
+const mockOutputPath = './db/generated'
2 2
 const magic = 1000
3 3
 
4 4
 // Insert here how many users you would like to generate:
5
-const total = 100
6
-const batchSize = 20
5
+const total = 30
6
+const batchSize = 10
7 7
 
8 8
 // Amount of responses for a complete survey
9
-const questions = 13
9
+const questions = 7
10 10
 
11 11
 // Seekers per 100 profiles
12 12
 const percentageOfSeekers = 90

+ 37
- 86
backend/db/data-generator/index.js Datei anzeigen

@@ -5,7 +5,7 @@ const classes = require('./classes')
5 5
 const score = require('./score')
6 6
 
7 7
 let batchCount = 1 // Counter to track how many things we've generated
8
-let extraProfilesToGenerate = 0
8
+let extraProfilesToGenerate = 1
9 9
 let extraProfileCount = 0 // Counter to track how many EXTRA profiles we've generated
10 10
 let generatedResponseCount = 0 // Counter to track every response generated
11 11
 
@@ -27,10 +27,13 @@ for (let i = 0; i < Object.keys(possibleResponses).length; i++) {
27 27
  * Our initial file setup
28 28
  */
29 29
 const write = async (batchNum, outputDataObject) => {
30
-    await fs.writeFile(`${config.mockOutputPath}_${batchNum}.js`, '', () => {})
30
+    const filename = `_batch_${batchNum}.js`
31
+    await fs.writeFile(`${config.mockOutputPath}/${filename}`, '', () => {})
31 32
     fs.appendFile(
32
-        `${config.mockOutputPath}_${batchNum}.js`,
33
-        config.header + 'export default ' + JSON.stringify(outputDataObject),
33
+        `${config.mockOutputPath}/${filename}`,
34
+        config.header +
35
+            'module.exports = ' +
36
+            JSON.stringify(outputDataObject, null, '  '),
34 37
         err => {
35 38
             if (err) {
36 39
                 console.error(err)
@@ -67,12 +70,6 @@ const generateUsers = () => {
67 70
         }
68 71
         user.user_name = random.name() + ' ' + random.name()
69 72
         user.user_email = random.email()
70
-
71
-        var mediaArray = []
72
-        for (let i=0; i < 3; i++) {
73
-            mediaArray.push(random.media())
74
-        }
75
-        user.user_media = mediaArray
76 73
     })
77 74
     console.log('COMPLETED: Generated Users...')
78 75
     return users
@@ -86,6 +83,13 @@ const generateProfiles = jobPosterIds => {
86 83
         starting: config.batchSize * batchCount,
87 84
         profile_id: extraProfileCount,
88 85
     })
86
+    profiles.forEach(profile => {
87
+        var mediaArray = []
88
+        for (let i = 0; i < 3; i++) {
89
+            mediaArray.push(random.media())
90
+        }
91
+        profile.user_media = mediaArray
92
+    })
89 93
     // Generate extra job posting profiles
90 94
     // attributed to random user.is_poster === true
91 95
     // TODO: Clean this up. Hard to read...
@@ -103,6 +107,11 @@ const generateProfiles = jobPosterIds => {
103 107
             extras = [...extras, ...generatedExtraProfiles]
104 108
         }
105 109
         extras.forEach(profile => {
110
+            var mediaArray = []
111
+            for (let i = 0; i < 3; i++) {
112
+                mediaArray.push(random.media())
113
+            }
114
+            profile.user_media = mediaArray
106 115
             profiles.push(profile)
107 116
             extraProfileCount++
108 117
         })
@@ -141,6 +150,11 @@ const generateResponses = profiles => {
141 150
 /**
142 151
  * Our main generator loop
143 152
  */
153
+const writeBarrel = async () => {
154
+    await fs.writeFile(`${config.mockOutputPath}/index.js`, '', () => {})
155
+}
156
+// writeBarrel()
157
+
144 158
 for (
145 159
     let batch = config.batchSize;
146 160
     batch <= config.total;
@@ -163,83 +177,20 @@ for (
163 177
     const responses = generateResponses(profiles)
164 178
 
165 179
     write(config.batchSize * batchCount, { users, profiles, responses })
180
+
181
+    /**
182
+     * Write barrel export
183
+     */
184
+    // const filename = `_batch_${config.batchSize * batchCount}.js`
185
+    // fs.appendFile(
186
+    //     `${config.mockOutputPath}/index.js`,
187
+    //     `export * from './${filename}'\n`,
188
+    //     err => {
189
+    //         if (err) console.error(err)
190
+    //     },
191
+    // )
192
+
166 193
     batchCount++
167 194
 }
168 195
 
169
-/**
170
- * Score all the profiles!
171
- */
172
-// const compareProfileResponses = (seeker, potentialMatch) => {
173
-//     const checkValCb = res => {
174
-//         const val = parseInt(res.val)
175
-//         return isNaN(val) ? 0 : val
176
-//     }
177
-//     const filterBy = idToCheckFor => {
178
-//         return responses
179
-//             .filter(
180
-//                 response =>
181
-//                     response.profile_id == idToCheckFor &&
182
-//                     response.val.length < 4,
183
-//             )
184
-//             .map(checkValCb)
185
-//     }
186
-//     const seekerResponses = filterBy(seeker.profile_id)
187
-//     const potentialMatchResponses = filterBy(potentialMatch.profile_id)
188
-//     const cachedScores = []
189
-//     seekerResponses.forEach(seekerResponse => {
190
-//         potentialMatchResponses.forEach(potentialResponse => {
191
-//             cachedScores.push(
192
-//                 preComputedScores[seekerResponse][potentialResponse],
193
-//             )
194
-//         })
195
-//     })
196
-//     return Math.round(
197
-//         cachedScores.reduce((a, b) => a + b) / cachedScores.length,
198
-//     )
199
-// }
200
-// const scoreProfile = (profile, potentialMatchList) => {
201
-//     return potentialMatchList
202
-//         .map(profileToCompare => {
203
-//             return {
204
-//                 match_queue_id: null,
205
-//                 profile_id: profile.profile_id,
206
-//                 target_id: profileToCompare.profile_id,
207
-//                 is_deleted: false,
208
-//                 score: compareProfileResponses(profile, profileToCompare),
209
-//             }
210
-//         })
211
-//         .sort((a, b) => a.score - b.score)
212
-// }
213
-
214
-// const scoreAll = () => {
215
-//     process.stdout.write('\nScoring Profiles')
216
-//     let scores = []
217
-//     const posterProfiles = profiles.filter(profile =>
218
-//         jobPosterIds.includes(profile.user_id),
219
-//     )
220
-//     const seekerProfiles = profiles.filter(
221
-//         profile => !jobPosterIds.includes(profile.user_id),
222
-//     )
223
-//     process.stdout.write('.')
224
-//     for (let i = 0; i < seekerProfiles.length; i++) {
225
-//         const scored = scoreProfile(seekerProfiles[i], posterProfiles)
226
-//         scores.push(...scored)
227
-//     }
228
-//     process.stdout.write('.')
229
-//     for (let j = 0; j < posterProfiles.length; j++) {
230
-//         const scored = scoreProfile(posterProfiles[j], seekerProfiles)
231
-//         scores.push(...scored)
232
-//     }
233
-//     process.stdout.write('.')
234
-//     console.log('\n\nCOMPLETED: Scoring Profiles...')
235
-//     return scores.reverse()
236
-// }
237
-
238
-// const match_queues = scoreAll().map((score, i) => {
239
-//     score.match_queue_id = i + 1
240
-//     // Comment out  next line to see the scores
241
-//     delete score.score
242
-//     return score
243
-// })
244
-
245 196
 console.log('---\nFINISHED...\n===\n')

+ 43
- 41
backend/db/data-generator/score.js Datei anzeigen

@@ -4,52 +4,52 @@ const config = require('./config')
4 4
 
5 5
 const preComputedScores = {
6 6
     100: {
7
-        100: 0,
8
-        140: 0,
9
-        180: 0,
10
-        220: 0,
11
-        260: 0,
12
-        400: 0,
7
+        100: 1000,
8
+        140: 872,
9
+        180: 675,
10
+        220: 518,
11
+        260: 406,
12
+        400: 215,
13 13
     },
14 14
     140: {
15
-        100: 0,
16
-        140: 0,
17
-        180: 0,
18
-        220: 0,
19
-        260: 0,
20
-        400: 0,
15
+        100: 872,
16
+        140: 1000,
17
+        180: 938,
18
+        220: 828,
19
+        260: 723,
20
+        400: 486,
21 21
     },
22 22
     180: {
23
-        100: 0,
24
-        140: 0,
25
-        180: 0,
26
-        220: 0,
27
-        260: 0,
28
-        400: 0,
23
+        100: 675,
24
+        140: 938,
25
+        180: 1000,
26
+        220: 968,
27
+        260: 906,
28
+        400: 706,
29 29
     },
30 30
     220: {
31
-        100: 0,
32
-        140: 0,
33
-        180: 0,
34
-        220: 0,
35
-        260: 0,
36
-        400: 0,
31
+        100: 518,
32
+        140: 828,
33
+        180: 968,
34
+        220: 1000,
35
+        260: 982,
36
+        400: 847,
37 37
     },
38 38
     260: {
39
-        100: 0,
40
-        140: 0,
41
-        180: 0,
42
-        220: 0,
43
-        260: 0,
44
-        400: 0,
39
+        100: 406,
40
+        140: 723,
41
+        180: 906,
42
+        220: 982,
43
+        260: 1000,
44
+        400: 928,
45 45
     },
46 46
     400: {
47
-        100: 0,
48
-        140: 0,
49
-        180: 0,
50
-        220: 0,
51
-        260: 0,
52
-        400: 0,
47
+        100: 215,
48
+        140: 486,
49
+        180: 706,
50
+        220: 847,
51
+        260: 928,
52
+        400: 1000,
53 53
     },
54 54
 }
55 55
 const score2d = (a, b) => {
@@ -62,11 +62,13 @@ const score2d = (a, b) => {
62 62
             config.magic,
63 63
     )
64 64
 }
65
-config.scoreVals.forEach(val => {
66
-    config.scoreVals.forEach(v => {
67
-        preComputedScores[val][v] = score2d(val, v)
68
-    })
69
-})
65
+
66
+// Uncomment to rerun precompute
67
+// config.scoreVals.forEach(val => {
68
+//     config.scoreVals.forEach(v => {
69
+//         preComputedScores[val][v] = score2d(val, v)
70
+//     })
71
+// })
70 72
 
71 73
 module.exports = {
72 74
     precomputed: preComputedScores,

+ 0
- 1446
backend/db/mock.js
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 9
- 7
backend/db/survey-generator.js Datei anzeigen

@@ -1,13 +1,15 @@
1 1
 const fs = require('fs')
2 2
 const similarity = require('compute-cosine-similarity')
3
-const magic = 1000 // Multiply cosine similary by this
3
+const config = require('./data-generator/config.js')
4 4
 
5
-const not_important = '120'
6
-const somewhat_important = '140'
7
-const important = '160'
8
-const very_important = '180'
9
-const extremely_important = '200'
10
-const mandatory = '400'
5
+const magic = config.magic // Multiply cosine similary by this
6
+
7
+const not_important = config.scoreVals[0]
8
+const somewhat_important = config.scoreVals[1]
9
+const important = config.scoreVals[2]
10
+const very_important = config.scoreVals[3]
11
+const extremely_important = config.scoreVals[4]
12
+const mandatory = config.scoreVals[5]
11 13
 
12 14
 // -
13 15
 // 1440 - 2400 total range

+ 5496
- 8
frontend/package-lock.json
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 1
- 0
frontend/package.json Datei anzeigen

@@ -30,6 +30,7 @@
30 30
         "pug-plain-loader": "^1.1.0",
31 31
         "sugarss": "^3.0.3",
32 32
         "vite": "^2.2.3",
33
+        "vite-fs": "^0.0.2",
33 34
         "watch": "^1.0.2"
34 35
     }
35 36
 }

+ 0
- 6
frontend/src/App.vue Datei anzeigen

@@ -1,15 +1,10 @@
1 1
 <template lang="pug">
2
-
3
-
4 2
 router-view
5
-
6 3
 </template>
7 4
 
8 5
 <script>
9 6
 import * as sss from '@/sss/import.css'
10 7
 
11
-
12
-
13 8
 export default {
14 9
     name: 'app',
15 10
 }
@@ -38,5 +33,4 @@ html
38 33
             height: 100%
39 34
             width: 100%
40 35
             flex-direction: column
41
-
42 36
 </style>

+ 16
- 31
frontend/src/components/ProfileCardList.vue Datei anzeigen

@@ -3,18 +3,20 @@ section.profile_card_list.w-full
3 3
     .profile_card_list_container.w-full
4 4
         .swipe(
5 5
             :config='config'
6
-            :key='profile.profile_id'
6
+            :key='profile.uid'
7 7
             @throwout='swipped(profile)'
8 8
             v-for='profile in profiles'
9
-            :style='{ "left": `vh` }'
10 9
         )
11 10
             .card.b-solid.rounded.p-0.bg-cover(
12
-                :style='{ "background-image": `url(${profile.user.user_media})` }'
13
-                
11
+                :style='{ "background-image": `url(${profile.avatar})` }'
14 12
             )
15 13
                 .card__content
16
-                    h3.p-1.mv-0.b-solid.rounded {{ profile.user.user_name }}
14
+                    h3.p-1.mv-0.b-solid.rounded {{ profile.name }}
17 15
 
16
+        nav.swipe_icons.w-full.f-row.between
17
+            h2 A
18
+            h2 H
19
+            h2 P
18 20
 </template>
19 21
 
20 22
 <script>
@@ -34,7 +36,7 @@ export default {
34 36
         },
35 37
         uid: {
36 38
             type: Number,
37
-            default: 1,
39
+            default: 9999,
38 40
         },
39 41
     },
40 42
     data: () => ({
@@ -52,7 +54,7 @@ export default {
52 54
         },
53 55
     },
54 56
     created() {
55
-        this.getProfile()
57
+        this.getUser()
56 58
     },
57 59
     methods: {
58 60
         logOut() {},
@@ -65,7 +67,7 @@ export default {
65 67
             profile.id = Date.now() + (Math.random() * 100000).toFixed()
66 68
             this.profiles.unshift({ ...profile })
67 69
         },
68
-        getProfile() {
70
+        getUser() {
69 71
             return
70 72
         },
71 73
         onRequest() {
@@ -76,32 +78,13 @@ export default {
76 78
 }
77 79
 </script>
78 80
 <style lang="postcss">
79
-@import '../sss/card.scss'
80
-
81
-.profile_card_list
81
+.profile_card_list_container
82 82
     display: flex
83 83
     justify-content: center
84 84
     margin: 5vh 0 0 0
85
-    position: relative
86
-
87
-
88
-.profile_card_list_container
89
-    margin: 0 auto
90
-    width: 30%
91
-    position: relative
92
-    .swipe
93
-        list-style: none
94
-        background: #fff
95
-        box-shadow: 0 0 2px rgba(0,0,0,.2), 1px 1px 1px rgba(0,0,0,.2)
96
-        position: absolute
97
-        line-height: 300px
98
-        text-align: center
99
-        border: 1px solid #ECECEC
100
-        border-radius: 8px
101
-        
102 85
 
103 86
 .swipe
104
-    
87
+    position: absolute
105 88
 
106 89
 .card
107 90
     position: relative
@@ -110,13 +93,15 @@ export default {
110 93
     max-width: 85vw
111 94
     height: 50vh
112 95
     background-position: center
113
-    border: 1px solid #fff
114 96
     &_content
115 97
         width: 100%
116 98
         height: 100%
117 99
     h3
118 100
         position: absolute
119 101
         bottom: 0
120
-        color: #fff
121 102
 
103
+.swipe_icons
104
+    position: fixed
105
+    bottom: 5vh
106
+    width: 250px
122 107
 </style>

+ 1
- 1
frontend/src/router/index.js Datei anzeigen

@@ -11,7 +11,7 @@ const routes = [
11 11
     {
12 12
         path: '/',
13 13
         component: home,
14
-        name: 'home',
14
+        name: 'HomeView',
15 15
         meta: { requiresAuth: true, requiresProfile: true },
16 16
     },
17 17
     {

+ 41
- 47
frontend/src/views/home.vue Datei anzeigen

@@ -2,8 +2,8 @@
2 2
 sidebar
3 3
 main.f-col.start.w-full
4 4
     article#home
5
-        h1(v-if="user") {{ user.user_name }}
6
-        profile-card-list(:uid='mypid' :profiles='swipables')
5
+        h1(v-if='user') {{ user.user_name }}
6
+        profile-card-list(:profiles='swipables' :uid='mypid')
7 7
     main-nav
8 8
 </template>
9 9
 
@@ -11,68 +11,62 @@ main.f-col.start.w-full
11 11
 import sidebar from '../components/Sidebar.vue'
12 12
 import mainNav from '../components/MainNav.vue'
13 13
 import profileCardList from '../components/ProfileCardList.vue'
14
-import batch20 from '../../../backend/db/generated/_batch_20.js'
14
+
15
+import batch_10 from '../../../backend/db/generated/_batch_10.js.ref'
16
+import batch_20 from '../../../backend/db/generated/_batch_20.js.ref'
17
+import batch_30 from '../../../backend/db/generated/_batch_30.js.ref'
15 18
 
16 19
 export default {
17 20
     name: 'HomeView',
18 21
     components: { profileCardList, sidebar, mainNav },
19 22
     data: () => ({
20
-        swipables: [   
21
-            // { 
22
-            //     user_id: 1, 
23
-            //     user: {
24
-            //         user_id: 20,
25
-            //         user_name: 'wravu pdjak',
26
-            //         user_email: '3vypx3qyj@aol.com',
27
-            //         is_admin: false,
28
-            //         is_poster: 1,
29
-            //     }, 
30
-            //     profile_id: 1 
31
-            // },
32
-        ],
23
+        swipables: [],
33 24
         user: null,
34 25
         mypid: null,
35 26
     }),
36 27
     created() {
37 28
         // this.mypid = auth.currentUser?.mypid || "99999";
38 29
         this.mypid = 21
39
-        this.getBatch()
40
-        const myProfile = this.getProfilesfor(this.mypid)
41
-        this.user = this.getUserfromProfile(myProfile)
42
-        console.log('this.user', this.user)
30
+        this.processProfiles()
43 31
     },
44 32
     methods: {
45
-        getBatch() {
46
-            const profiles = batch20.profiles
47
-            // .map is more readable
48
-            this.swipables = profiles.map((profile) => {
49
-                profile.user = this.getUserfromProfile(profile)
50
-                return profile
33
+        parseBatch(allBatches) {
34
+            const finished = { profiles: [], users: [], responses: [] }
35
+            allBatches.forEach(batch => {
36
+                const split = batch.value.split('\n')
37
+                split.splice(0, 5)
38
+                split.unshift('{')
39
+                const p = JSON.parse(split.join(''))
40
+                finished.profiles = [...p.profiles, ...finished.profiles]
41
+                finished.users = [...p.users, ...finished.users]
42
+                finished.responses = [...p.responses, ...finished.responses]
51 43
             })
52
-            // for loop is faster
53
-            // const myList = []
54
-            // for (let profile in profiles) {
55
-            //     profile.user = this.getUserfromProfile(profile)
56
-            //     myList.push(profile)
57
-            // }
58
-            // this.swipables = myList
59
-            // before you store in 31, save user info per profile
44
+            return finished
60 45
         },
61
-        getProfilesfor(pid) {
62
-            const profilesfromBatch = batch20.profiles
63
-            const profiles = profilesfromBatch.filter((profile) => {
64
-                return profile.profile_id === pid
46
+        processProfiles() {
47
+            const parsed = this.parseBatch([batch_10, batch_20, batch_30])
48
+            const findUser = profile => {
49
+                return parsed.users.filter(u => u.user_id == profile.user_id)[0]
50
+            }
51
+            parsed.profiles.forEach(p => {
52
+                // console.log(parsed)
53
+                const user = findUser(p)
54
+                p.uid = p.profile_id
55
+                p.name = user.user_name
56
+                p.email = user.user_email
57
+                p.avatar = p.user_media[0]
58
+                p.responses = parsed.responses.filter(
59
+                    r => r.profile_id == p.profile_id,
60
+                )
61
+                p.responses.forEach(r => {
62
+                    if (r.response_key_id == 7) {
63
+                        p.zipcode = r.val
64
+                    }
65
+                })
66
+                this.swipables.push(p)
65 67
             })
66
-            return profiles[0]
68
+            console.log(this.swipables)
67 69
         },
68
-        getUserfromProfile(profile) {
69
-            const users = batch20.users
70
-            const usersProfile = users.filter((user) => {
71
-                return user.user_id === profile.user_id
72
-            })
73
-            return usersProfile[0]
74
-        }
75
-
76 70
     },
77 71
 }
78 72
 </script>

+ 2
- 2
frontend/vite.config.js Datei anzeigen

@@ -1,9 +1,9 @@
1 1
 import { defineConfig } from 'vite'
2 2
 import vue from '@vitejs/plugin-vue'
3
-
3
+import ViteFS from 'vite-fs'
4 4
 // https://vitejs.dev/config/
5 5
 export default defineConfig({
6
-    plugins: [vue()],
6
+    plugins: [vue(), ViteFS()],
7 7
     resolve: {
8 8
         alias: {
9 9
             '@': require('path').resolve(__dirname, 'src'),

Laden…
Abbrechen
Speichern