Skip to content

Commit 7e9c9f5

Browse files
committed
add common interests key for each recommendation for sorting later
1 parent f118729 commit 7e9c9f5

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default {
5454
MultipleFiltersDropdown,
5555
},
5656
data: () => ({
57-
loggedInUser: null,
5857
}),
5958
methods: {
6059
sort(...args) {
@@ -72,26 +71,14 @@ export default {
7271
} else if (by === 'Least popular') {
7372
this.recommendations.sort((a, b) => a.heat_score - b.heat_score);
7473
} else if (by === 'Most common interests') {
75-
this.recommendations.sort((a, b) => this.count_similarities(a.tags, this.loggedInUser.tags) - this.count_similarities(b.tags, this.loggedInUser.tags));
74+
this.recommendations.sort((a, b) => b.common_interests - a.common_interests);
7675
} else if (by === 'Least common interests') {
77-
this.recommendations.sort((a, b) => this.count_similarities(b.tags, this.loggedInUser.tags) - this.count_similarities(a.tags, this.loggedInUser.tags));
76+
this.recommendations.sort((a, b) => a.common_interests - b.common_interests);
7877
}
7978
},
80-
count_similarities(arrayA, arrayB) {
81-
let matches = 0;
82-
for (let i = 0 ; i < arrayA.length; i++) {
83-
if (arrayB.indexOf(arrayA[i].name) != -1) {
84-
matches++;
85-
}
86-
}
87-
return matches;
88-
},
8979
filter() {
9080
console.log('filter');
9181
},
9282
},
93-
mounted() {
94-
this.loggedInUser = this.$store.getters.getLoggedInUser;
95-
}
9683
};
9784
</script>

frontend/src/views/app/Browse.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ export default {
4242
},
4343
recommendationsAnalysisDone: false,
4444
}),
45+
methods: {
46+
interestsIdsOfUser(user) {
47+
const interestsIds = [];
48+
const interestObjects = user.tags;
49+
for (let i = 0; i < interestObjects.length; i += 1) {
50+
interestsIds.push(interestObjects[i].id);
51+
}
52+
return interestsIds;
53+
},
54+
},
4555
async created() {
4656
if (this.recommendationsFromSettingUp) {
4757
this.recommendations = this.recommendationsFromSettingUp;
@@ -70,10 +80,15 @@ export default {
7080
this.recommendationsAnalysis.popularity.max = this.recommendations[i].heat_score;
7181
}
7282
const interests = this.recommendations[i].tags;
83+
const interestsIdsOfLoggedInUser = this.interestsIdsOfUser(this.$store.getters.getLoggedInUser);
84+
this.recommendations[i].common_interests = 0;
7385
for (let j = 0; j < interests.length; j += 1) {
7486
if (this.recommendationsAnalysis.uniqueInterests.indexOf(interests[j].name) === -1) {
7587
this.recommendationsAnalysis.uniqueInterests.push(interests[j].name);
7688
}
89+
if (interestsIdsOfLoggedInUser.indexOf(interests[j].id) !== -1) {
90+
this.recommendations[i].common_interests += 1;
91+
}
7792
}
7893
}
7994
this.recommendationsAnalysisDone = true;

0 commit comments

Comments
 (0)