-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData_Management.cpp
More file actions
105 lines (91 loc) · 3.12 KB
/
Data_Management.cpp
File metadata and controls
105 lines (91 loc) · 3.12 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//FINAL_PROJECT_DATA_MANAGEMENT
#include<fstream>
#include<iostream>
#include<vector>
#include<map>
class Data_Management{
private:
std::map<std::string, std::vector<int> > data;
std::map<int, std::string> movies;
void Deserialize(){
//read review data
//std::ifstream fileOne("/Users/michel/CLionProjects/Visual_Sorting_Algorithm/Data/u.data");
std::ifstream fileOne("Data/u.data");
std::string line;
//bool isOpen = fileOne.is_open();
while(!fileOne.eof() && line != " "){
std::getline(fileOne, line, '\t');
if(line != " " && line != ""){
data["userId"].push_back(std::stoi(line));
//For Debugging:
//std::cout<<"Successfully added review: " << line;
}
std::getline(fileOne, line, '\t');
if(line != " " && line != ""){
data["itemId"].push_back(std::stoi(line));
//For Debugging:
//std::cout<< " " << line;
}
std::getline(fileOne, line, '\t');
if(line != " " && line != ""){
data["rating"].push_back(std::stoi(line));
//For Debugging:
//std::cout<< " " << line;
}
std::getline(fileOne, line, '\n');
if(line != " " && line != ""){
data["time_stamp"].push_back(std::stoi(line));
//For Debugging:
//std::cout<< " " << line <<std::endl;
}
}
//std::ifstream fileTwo("/Users/michel/CLionProjects/Visual_Sorting_Algorithm/Data/u.item");
std::ifstream fileTwo("Data/u.item");
line = "";
int itemId;
while(!fileTwo.eof() && line != " "){
std::getline(fileTwo,line,'|');
if(line != " " && line != ""){
itemId = std::stoi(line);
//For Debugging:
//std::cout<<"Successfully added movie: " << " " << itemId;
}
std::getline(fileTwo,line,'|');
if(line != " " && line != ""){
movies[itemId] = line;
//For Debugging:
//std::cout<< " " << line << std::endl;
}
std::getline(fileTwo,line,'\n');
}
}
public:
Data_Management(){
Deserialize();
}
//user_id (integer), item_id(integer), rating(integer), time_stamp(integer), movie_title(string).
std::vector<int> getUserIdVec(){
auto it = data.find("userId");
return it->second;
}
std::vector<int> getItemIdVec(){
auto it = data.find("itemId");
return it->second;
}
std::vector<int> getRatingVec(){
auto it = data.find("rating");
return it->second;
}
std::vector<int> getTimeStampVec(){
auto it = data.find("time_stamp");
return it->second;
}
// need to decide what to do here, maybe change movieTitles to a vector containing just movie titles
std::vector<std::string> getMovieTitleVec(){
std::vector<std::string> result;
for(auto movies : movies){
result.push_back(movies.second);
}
return result;
}
};