-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
212 lines (192 loc) · 6.13 KB
/
Copy pathutils.cpp
File metadata and controls
212 lines (192 loc) · 6.13 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
// Created by 86173 on 2022/1/27.
//
#include <iomanip>
#include "utils.h"
path str2path(const string &s) {
vector<pair<double, double>> path;
for (char i : s) {
path.emplace_back(i, i);
}
return path;
}
void file2paths(const string &filename, const string& target, int bound = -1) {
ifstream ifs(filename);
ofstream ofs(target);
string s;
map<string, vector<pair<int, pair<double, double>>>> tmp_data;
string tmp;
int driverCount = 0, trajectoryCount = 0;
while (!ifs.eof()) {
if (bound > 0 && trajectoryCount >= bound) break;
getline(ifs, s);
auto strs = split(s, ",");
if(tmp != strs[0]) {
for (auto id: tmp_data) {
sort(id.second.begin(), id.second.end());
ofs << id.second.size() << endl;
for (auto item: id.second) {
ofs << item.first << " " << setiosflags(ios::fixed) << setprecision(5) << item.second.first << " " << item.second.second << endl;
}
trajectoryCount ++;
}
driverCount ++;
tmp = strs[0];
tmp_data.clear();
cout << tmp << endl;
}
double latitude, longitude;
long t_index;
string t = strs[2] + " " + strs[3] + " " + strs[4];
istringstream istr1(t);
istr1 >> t_index >> longitude >> latitude;
pair<int, pair<double, double>> tt = {t_index, {latitude, longitude}};
tmp_data[strs[1]].push_back(tt);
}
ifs.close();
ofs.close();
cout << trajectoryCount << endl;
}
vector<string> split(string str, string pattern) {
string::size_type pos;
vector<string> result;
str += pattern;
int size = str.size();
for (int i = 0; i < size; i++) {
pos = str.find(pattern, i);
if (pos < size) {
std::string s = str.substr(i, pos - i);
result.push_back(s);
i = pos + pattern.size() - 1;
}
}
return result;
}
vector<path> readfile(const string &filename) {
int point_num;
vector<path> paths;
ifstream ifs(filename);
while (!ifs.eof()) {
int time_index;
double lat, lon;
path p;
ifs >> point_num;
for (int i = 0; i < point_num; ++i) {
ifs >> time_index >> lat >> lon;
p.emplace_back(lat, lon);
}
paths.push_back(p);
}
return paths;
}
void paths2file(const string &filename, vector<path> paths) {
ofstream ofs(filename);
for (const auto &item : paths) {
ofs << item.size() << endl;
for (int i = 0; i < item.size(); ++i) {
ofs << setiosflags(ios::fixed) << setprecision(5) << item[i].first << " " << item[i].second << endl;
}
}
ofs.close();
}
void ids2file(const string &filename, const map<int, pair<vector<double>, subResult>>& paths, int queryID) {
ofstream ofs(filename, ios::app);
for (const auto &item : paths) {
ofs << queryID << "," << item.first << "," << item.second.second.first.first << "," << item.second.second.first.second << "," << item.second.second.second << endl;
}
ofs.close();
}
void dataAnalize(const string& filename) {
int count = 0;
double avg_length = 0;
double avg_lat = 0;
double avg_lon = 0;
double max_lat = -10000;
double min_lat = 10000;
double max_lon = -10000;
double min_lon = 10000;
int point_num;
ifstream ifs(filename);
while (!ifs.eof()) {
int time_index;
double lat, lon;
ifs >> point_num;
for (int i = 0; i < point_num; ++i) {
ifs >> time_index >> lat >> lon;
}
avg_length = (count * avg_length + point_num) / (count + 1);
avg_lat = (count * avg_lat + lat) / (count + 1);
avg_lon = (count * avg_lon + lon) / (count + 1);
count += 1;
max_lat = max(max_lat, lat);
min_lat = min(min_lat, lat);
max_lon = max(max_lon, lon);
min_lon = min(min_lon, lon);
}
cout << "avgLen:" << avg_length << endl;
cout << "count:" << count << endl;
cout << "max_lat:" << max_lat << endl;
cout << "min_lat:" << min_lat << endl;
cout << "avg_lat:" << avg_lat << endl;
cout << "max_lon:" << max_lon << endl;
cout << "min_lon:" << min_lon << endl;
cout << "avg_lon:" << avg_lon << endl;
}
void dataFilter(const string &filename) {
int point_num;
int count = 0;
ifstream ifs(filename);
ofstream ofs(filename + "Tmp");
while (!ifs.eof()) {
int time_index;
bool flag = true;
double lat, lon;
path p;
ifs >> point_num;
for (int i = 0; i < point_num; ++i) {
ifs >> time_index >> lat >> lon;
if (range[dataType].first[0] > lat || lat > range[dataType].first[1]){
flag = false;
}
if (range[dataType].second[0] > lon || lon > range[dataType].second[1]){
flag = false;
}
p.emplace_back(lat, lon);
}
if (!flag) continue;
count ++;
ofs << p.size() << endl;
for (auto & i : p) {
ofs << setiosflags(ios::fixed) << setprecision(5) << time_index << " " << i.first << " " << i.second << endl;
}
}
cout << count << endl;
ifs.close();
ofs.close();
}
void dataLengthFilter(const string &filename, int minLen, int maxLen, int num) {
int point_num;
int count = 0;
ifstream ifs(filename);
ofstream ofs(filename + "_" + to_string(minLen) + "_" + to_string(maxLen));
while (!ifs.eof()) {
int time_index;
bool flag = true;
double lat, lon;
path p;
ifs >> point_num;
for (int i = 0; i < point_num; ++i) {
ifs >> time_index >> lat >> lon;
p.emplace_back(lat, lon);
}
if (point_num > maxLen || point_num < minLen || count >= num) continue;
count ++;
ofs << p.size() << endl;
for (auto & i : p) {
ofs << setiosflags(ios::fixed) << setprecision(5) << time_index << " " << i.first << " " << i.second << endl;
}
}
cout << count << endl;
ifs.close();
ofs.close();
}