-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_parser.cpp
More file actions
127 lines (105 loc) · 3.05 KB
/
data_parser.cpp
File metadata and controls
127 lines (105 loc) · 3.05 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
const string DATA_PATH = "/home/kadyrbek/Desktop/WiFiLocalization/parsed_data/lg";
const string PURE_DATA_PATH = "/home/kadyrbek/Desktop/WiFiLocalization/pure_data/lg_40_routers_16_classes.txt";
class MACinfo{
public:
int point_id;
int class_id;
int signal;
MACinfo(int class_id, int point_id, int signal) {
this->class_id = class_id;
this->point_id = point_id;
this->signal = signal;
}
};
map <string, vector <MACinfo> > H; //
bool parse_data (string file_path, int class_id, int point_id) {
ifstream file(file_path);
if (file.fail()) {
cout << "Can't find the file " << file_path << "\n";
return false;
}
string line;
while (getline(file, line)) {
string mac_address = "";
string signal_str = "";
bool is_mac = true;
for (size_t i = 0 ; i < line.length() ; ++i) {
if (line[i] == ',') {
is_mac = false;
continue;
}
if (is_mac) {
mac_address += line[i];
} else {
signal_str += line[i];
}
}
int signal = stoi(signal_str);
H[mac_address].push_back(MACinfo(class_id, point_id, signal));
}
}
void analyze() {
int counter = 0;
ofstream fi;
fi.open(PURE_DATA_PATH);
if(!fi.is_open()) {
cout << "Can't open the file\n";
}
const static int POINT_NUMBER = 160;
std::vector<int> signals[POINT_NUMBER + 2];
for (pair<string, vector<MACinfo> > info : H) {
if (info.second.size() <= 140)
continue;
cout << info.first << " " << info.second.size() << "\n";
for (int point = 1 ; point <= POINT_NUMBER ; point ++) {
MACinfo found(0,0,0);
bool is_found = false;
for (MACinfo i : info.second) {
// cout << (i.class_id - 1) * 16 + i.point_id << " -- " << i.class_id << ", " << i.point_id << "\n";
if (point == (i.class_id - 1) * 10 + i.point_id) {
found = i;
is_found = true;
break;
}
}
if (is_found)
signals[point].push_back(found.signal);
else
signals[point].push_back(0);
}
counter ++;
}
for (int point = 1 ; point <= POINT_NUMBER ; point ++) {
for (int sig : signals[point]) {
fi << sig << ",";
}
fi << (point - 1) / 10 + 1 << endl;
}
// 382 different
cout << "Count = " << counter << "\n";
}
void parseForClass(string class_file_name, int class_id) {
static const int num_files = 10;
for (int point_id = 1 ; point_id <= num_files ; ++point_id) {
string file_name = class_file_name + "." + to_string(point_id);
parse_data(file_name, class_id, point_id);
}
}
void startParsingData(int num_classes, string data_folder) {
for (int class_id = 1 ; class_id <= num_classes; ++class_id) {
string file_class_name = data_folder + "/" + to_string(class_id);
parseForClass(file_class_name, class_id);
}
}
int main() {
const string preffix = "lg";
const int num_classes = 16;
startParsingData(num_classes, DATA_PATH);
analyze();
return 0;
}