This repository was archived by the owner on Jul 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecommendationEngine.cpp
More file actions
49 lines (40 loc) · 1.52 KB
/
Copy pathrecommendationEngine.cpp
File metadata and controls
49 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "recommendationEngine.hpp"
// using namespace RecommendationEngine;
// Data structures
unordered_map<string, unordered_set<string>> videoRecommendationsMap; // videoID -> set of
mutex dataMutex; // Mutex for thread-safe access to data structures
int RecommendationEngine::criticalMass() {
return log(usersCount);
}
RecommendationEngine::RecommendationEngine() {
}
RecommendationEngine::~RecommendationEngine() {
}
vector<string> RecommendationEngine::getRecommendations(const vector<string>& userWatchHistory, const string& videoId) {
cout << "A logged-in user watched a video" << endl;
unordered_map<string, unordered_set<string>> mapCopy = videoRecommendationsMap;
vector<string> recommendations;
for (auto i : mapCopy[videoId]) {
if (find(userWatchHistory.begin(), userWatchHistory.end(), i) == userWatchHistory.end() && i != videoId) {
recommendations.push_back(i);
}
}
return recommendations;
}
// union
void RecommendationEngine::loadUser(const vector<string>& userWatchHistory, const string& userId) {
cout << "loading user" << endl;
thread([userWatchHistory, userId]() {
lock_guard<mutex> lock(dataMutex);
for (const auto& i : userWatchHistory) {
for (const auto& j : userWatchHistory) {
videoRecommendationsMap[i].insert(j);
}
}
}).detach();
}
// make
void RecommendationEngine::loadVideo(const string& videoId, int views) {
cout << "A video being viewed" << endl;
// todo currently unused
}