ソースを参照

:sparkles: rough draft profile generator to start matching

tags/0.0.1
j 4年前
コミット
eff754134e
1個のファイルの変更120行の追加0行の削除
  1. 120
    0
      backend/db/survey-generator.js

+ 120
- 0
backend/db/survey-generator.js ファイルの表示

@@ -0,0 +1,120 @@
1
+const not_important = '120'
2
+const somewhat_important = '140'
3
+const important = '160'
4
+const very_important = '180'
5
+const extremely_important = '200'
6
+const mandatory = '400'
7
+// -
8
+// 1440 - 2400 total range
9
+// 1440 - 1900 limited range
10
+// -
11
+// Reserved for REALLY important answers
12
+// like full-time vs part-time
13
+// and remote vs onsite only
14
+// 400 mandatory
15
+
16
+const importance = [
17
+    not_important,
18
+    somewhat_important,
19
+    important,
20
+    very_important,
21
+    extremely_important,
22
+]
23
+
24
+const langs = [
25
+    'javascript',
26
+    'python',
27
+    'ruby',
28
+    'erlang',
29
+    'haskall',
30
+    'php',
31
+    'swift',
32
+    'rust',
33
+    'objective-c',
34
+    'common lisp',
35
+    'java',
36
+    'perl',
37
+    'cobol',
38
+    'fortran',
39
+    'julia',
40
+    'c#',
41
+    'go',
42
+    'c++',
43
+]
44
+const duration = ['full', 'part']
45
+const location = ['onsite', 'remote', 'flexible']
46
+
47
+const otherWeightLookup = {
48
+    full: mandatory,
49
+    part: mandatory,
50
+    onsite: mandatory,
51
+    remote: mandatory,
52
+    flexible: mandatory,
53
+}
54
+const rand = max => {
55
+    return Math.floor(Math.random() * max) < 1
56
+        ? 1
57
+        : Math.floor(Math.random() * max)
58
+}
59
+
60
+class DummyProfile {
61
+    constructor() {
62
+        this.profileResponses = null
63
+        this.langPref = null
64
+        this.durationPref = null
65
+        this.locationPref = null
66
+
67
+        // profile is constructed of 12 answers, 2 for each dimension
68
+        this.profileResponses = this.getRandomAnswers(12, importance)
69
+        this.langPref = this.getRandomAnswers(rand(4), langs)
70
+        this.durationPref = this.getRandomAnswers(1, duration)
71
+        this.locationPref = this.getRandomAnswers(1, location)
72
+    }
73
+    getRandomAnswers(count, options) {
74
+        const answers = []
75
+        for (let i = 0; i < count; i++) {
76
+            const random = rand(options.length)
77
+            answers.push(options[random])
78
+        }
79
+        return answers
80
+    }
81
+}
82
+
83
+const generateDummyProfiles = count => {
84
+    const profiles = []
85
+    for (let i = 0; i < count; i++) {
86
+        const dummyProfile = new DummyProfile()
87
+        profiles.push(dummyProfile)
88
+    }
89
+    profiles.forEach(dummy => {
90
+        dummy.profileResponses = dummy.profileResponses.map(answer => {
91
+            const answerObj = {}
92
+            const random = rand(12)
93
+            answerObj[random] = answer
94
+            return answerObj
95
+        })
96
+    })
97
+    return profiles
98
+}
99
+
100
+const generatedSeekers = generateDummyProfiles(100)
101
+const generatedProviders = generateDummyProfiles(10)
102
+
103
+const compareProfiles = (profile, unorderedPotentialMatches) => {
104
+    const scored = unorderedPotentialMatches.map(potentialMatch => {
105
+        // score the match
106
+        const score = rand(1900)
107
+        // add the match to object keyed by score
108
+        return { score, profile: potentialMatch }
109
+    })
110
+    // create array ordered by score
111
+    const orderedPotentialMatches = scored.sort((a, b) => a.score - b.score)
112
+    return orderedPotentialMatches
113
+}
114
+
115
+generatedSeekers.forEach(seeker => {
116
+    console.log(compareProfiles(seeker, generatedProviders))
117
+})
118
+// console.log(generatedProviders)
119
+// console.log(generatedSeekers[0].profileResponses)
120
+// console.log(generatedProviders[0].profileResponses)

読み込み中…
キャンセル
保存