Skip to content

Commit d2d2557

Browse files
committed
analyse recommendations to get filter starting values
1 parent 1f35f11 commit d2d2557

File tree

4 files changed

+79
-24
lines changed

4 files changed

+79
-24
lines changed

frontend/src/components/app/recommendations/RecommendationCard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
<div class="flex items-end my-2">
2323
<h1 class="text-4xl font-bold leading-none">{{this.recommendation.first_name}}</h1>
24-
<h1 class="text-2xl ml-2 leading-none mb-1">24</h1>
24+
<h1 class="text-2xl ml-2 leading-none mb-1">{{this.recommendation.age}}</h1>
2525
</div>
2626
<h1 class="text-lg">{{getDistance()}}km away</h1>
2727
</div>
@@ -37,6 +37,7 @@ export default {
3737
getPrimaryImage() {
3838
const userImages = this.recommendation.images;
3939
let imageForShowcase;
40+
// console.log(this.recommendation);
4041
for (let i = 0; i < userImages.length; i += 1) {
4142
if (userImages[i].is_primary) {
4243
imageForShowcase = userImages[i].link;

frontend/src/components/app/recommendations/Recommendations.vue

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@
77
v-bind:position="'left'"
88
v-bind:options="['Youngest', 'Oldest', 'Closest', 'Furthest', 'Most popular', 'Least popular', 'Most common interests', 'Least common interests']"
99
v-on:sort="sort"></Sort>
10-
<FilterSlider v-bind:name="'age'" v-on:filter="filter"></FilterSlider>
11-
<FilterSlider v-bind:unit="'km'" v-bind:name="'distance'" v-on:filter="filter"></FilterSlider>
12-
<FilterSlider v-bind:unit="'pts'" v-bind:name="'fame'" v-on:filter="filter"></FilterSlider>
10+
<FilterSlider
11+
v-bind:min="recommendationsAnalysis.age.min"
12+
v-bind:max="recommendationsAnalysis.age.max"
13+
v-bind:name="'age'"
14+
v-on:filter="filter"></FilterSlider>
15+
<FilterSlider
16+
v-bind:min="recommendationsAnalysis.distance.min"
17+
v-bind:max="recommendationsAnalysis.distance.max"
18+
v-bind:unit="'km'"
19+
v-bind:name="'distance'"
20+
v-on:filter="filter"></FilterSlider>
21+
<FilterSlider
22+
v-bind:min="recommendationsAnalysis.popularity.min"
23+
v-bind:max="recommendationsAnalysis.popularity.max"
24+
v-bind:unit="'pts'"
25+
v-bind:name="'fame'"
26+
v-on:filter="filter"></FilterSlider>
1327
<MultipleFiltersDropdown
1428
v-bind:position="'right'"
15-
v-bind:options="[
16-
'swimming', 'wine', 'reading', 'foodie', 'netflix', 'music', 'yoga', 'golf',
17-
'photography', 'baking', 'shopping', 'outdoors', 'art', 'travel', 'hiking',
18-
'running', 'volunteering', 'cycling', 'climbing', 'tea', 'fishing', 'soccer',
19-
'museum', 'dancing', 'surfing', 'karaoke', 'parties', 'diy',
20-
'walking', 'cat lover', 'movies', 'gardening', 'trivia', 'working out',
21-
'cooking', 'gamer', 'brunch', 'blogging', 'picknicking', 'athlete',
22-
'dog lover', 'politics', 'environmentalism', 'instagram', 'spirituality',
23-
'language exchange', 'sports', 'comedy', 'fashion', 'disney', 'vlogging',
24-
'astrology', 'board games', 'craft beer', 'coffee', 'writer',
25-
]"
29+
v-bind:options="recommendationsAnalysis.uniqueInterests"
2630
v-bind:name="'interests'"
2731
v-on:filter="filter"></MultipleFiltersDropdown>
2832
</div>
29-
<!-- <div class="flex flex-wrap items-center justify-start">-->
3033
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
3134
<RecommendationCard
3235
v-for="(recommendation, index) in recommendations" :key="index"
@@ -43,6 +46,7 @@ import RecommendationCard from '@/components/app/recommendations/RecommendationC
4346
import MultipleFiltersDropdown from '@/components/shared/MultipleFiltersDropdown.vue';
4447
4548
export default {
49+
props: ['title', 'recommendations', 'recommendationsAnalysis'],
4650
components: {
4751
Sort,
4852
RecommendationCard,
@@ -57,6 +61,5 @@ export default {
5761
console.log('filter');
5862
},
5963
},
60-
props: ['title', 'recommendations'],
6164
};
6265
</script>

frontend/src/components/shared/FilterSlider.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import noUiSlider from 'nouislider';
1818
import 'nouislider/distribute/nouislider.css';
1919
2020
export default {
21-
props: ['options', 'name', 'unit'],
21+
props: ['options', 'name', 'unit', 'min', 'max'],
2222
data: () => ({
2323
closed: true,
2424
slider: {
25-
startMin: 25,
26-
startMax: 75,
27-
min: 0,
28-
max: 100,
29-
start: 40,
25+
startMin: null,
26+
startMax: null,
27+
min: null,
28+
max: null,
29+
start: null,
3030
step: 1,
3131
},
3232
}),
@@ -52,6 +52,11 @@ export default {
5252
},
5353
},
5454
mounted() {
55+
this.slider.startMin = this.min;
56+
this.slider.startMax = this.max;
57+
this.slider.min = this.min;
58+
this.slider.max = this.max;
59+
this.slider.start = this.min;
5560
noUiSlider.create(this.$refs.slider, {
5661
start: [this.slider.startMin, this.slider.startMax],
5762
step: this.slider.step,

frontend/src/views/app/Browse.vue

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
<NavBar v-bind:currentRoute="'Browse'"></NavBar>
55
<section class="mx-auto">
66
<Recommendations
7+
v-if="recommendationsAnalysisDone"
78
v-bind:title="'Potential matches'"
8-
v-bind:recommendations="recommendations"></Recommendations>
9+
v-bind:recommendations="recommendations"
10+
v-bind:recommendationsAnalysis="recommendationsAnalysis"></Recommendations>
911
</section>
1012
</div>
1113
</template>
1214

1315
<script>
16+
/* eslint-disable max-len */
1417
import NavBar from '@/components/shared/NavBar.vue';
1518
import Recommendations from '@/components/app/recommendations/Recommendations.vue';
1619
@@ -22,6 +25,22 @@ export default {
2225
},
2326
data: () => ({
2427
recommendations: [],
28+
recommendationsAnalysis: {
29+
age: {
30+
min: null,
31+
max: null,
32+
},
33+
distance: {
34+
min: null,
35+
max: null,
36+
},
37+
popularity: {
38+
min: null,
39+
max: null,
40+
},
41+
uniqueInterests: [],
42+
},
43+
recommendationsAnalysisDone: false,
2544
}),
2645
async created() {
2746
if (this.recommendationsFromSettingUp) {
@@ -30,6 +49,33 @@ export default {
3049
const recommendationsRequest = await this.$http.get('/recommendations');
3150
this.recommendations = recommendationsRequest.data.recommendations;
3251
}
52+
for (let i = 0; i < this.recommendations.length; i += 1) {
53+
if (this.recommendationsAnalysis.age.min === null || this.recommendations[i].age < this.recommendationsAnalysis.age.min) {
54+
this.recommendationsAnalysis.age.min = this.recommendations[i].age;
55+
}
56+
if (this.recommendationsAnalysis.age.max === null || this.recommendations[i].age > this.recommendationsAnalysis.age.max) {
57+
this.recommendationsAnalysis.age.max = this.recommendations[i].age;
58+
}
59+
if (this.recommendationsAnalysis.distance.min === null || Math.floor(this.recommendations[i].distance) < this.recommendationsAnalysis.distance.min) {
60+
this.recommendationsAnalysis.distance.min = Math.floor(this.recommendations[i].distance);
61+
}
62+
if (this.recommendationsAnalysis.distance.max === null || Math.floor(this.recommendations[i].distance) > this.recommendationsAnalysis.distance.max) {
63+
this.recommendationsAnalysis.distance.max = Math.floor(this.recommendations[i].distance);
64+
}
65+
if (this.recommendationsAnalysis.popularity.min === null || this.recommendations[i].heat_score < this.recommendationsAnalysis.popularity.min) {
66+
this.recommendationsAnalysis.popularity.min = this.recommendations[i].heat_score;
67+
}
68+
if (this.recommendationsAnalysis.popularity.max === null || this.recommendations[i].heat_score > this.recommendationsAnalysis.popularity.max) {
69+
this.recommendationsAnalysis.popularity.max = this.recommendations[i].heat_score;
70+
}
71+
const interests = this.recommendations[i].tags;
72+
for (let j = 0; j < interests.length; j += 1) {
73+
if (this.recommendationsAnalysis.uniqueInterests.indexOf(interests[j].name) === -1) {
74+
this.recommendationsAnalysis.uniqueInterests.push(interests[j].name);
75+
}
76+
}
77+
}
78+
this.recommendationsAnalysisDone = true;
3379
},
3480
};
3581

0 commit comments

Comments
 (0)