|
@@ -89,40 +89,45 @@ util::http::Answer StatServer::handleHeatMapReq(const Params& pars) const {
|
89
|
89
|
if (cb.size()) json << cb << "(";
|
90
|
90
|
json << "{\"ok\":[";
|
91
|
91
|
|
92
|
|
- auto hgOk = _idx->getHeatGridOk(bbox, z);
|
93
|
92
|
char sep = ' ';
|
94
|
|
- for (auto cluster : hgOk) {
|
95
|
|
- json << sep;
|
96
|
|
- sep = ',';
|
|
93
|
+ for (const auto& idx : _idxs) {
|
|
94
|
+ auto hgOk = idx.getHeatGridOk(bbox, z);
|
|
95
|
+ for (auto cluster : hgOk) {
|
|
96
|
+ json << sep;
|
|
97
|
+ sep = ',';
|
97
|
98
|
|
98
|
|
- json << "[" << cluster.latLng.getY() << "," << cluster.latLng.getX() << ","
|
99
|
|
- << cluster.size << "]";
|
|
99
|
+ json << "[" << cluster.latLng.getY() << "," << cluster.latLng.getX() << ","
|
|
100
|
+ << cluster.size << "]";
|
|
101
|
+ }
|
100
|
102
|
}
|
101
|
103
|
|
102
|
104
|
json << "],\"sugg\":[";
|
103
|
105
|
|
104
|
|
- auto hgSugg = _idx->getHeatGridSugg(bbox, z);
|
105
|
|
-
|
106
|
106
|
sep = ' ';
|
107
|
|
- for (auto cluster : hgSugg) {
|
108
|
|
- json << sep;
|
109
|
|
- sep = ',';
|
|
107
|
+ for (const auto& idx : _idxs) {
|
|
108
|
+ auto hgSugg = idx.getHeatGridSugg(bbox, z);
|
110
|
109
|
|
111
|
|
- json << "[" << cluster.latLng.getY() << "," << cluster.latLng.getX() << ","
|
112
|
|
- << cluster.size << "]";
|
|
110
|
+ for (auto cluster : hgSugg) {
|
|
111
|
+ json << sep;
|
|
112
|
+ sep = ',';
|
|
113
|
+
|
|
114
|
+ json << "[" << cluster.latLng.getY() << "," << cluster.latLng.getX() << ","
|
|
115
|
+ << cluster.size << "]";
|
|
116
|
+ }
|
113
|
117
|
}
|
114
|
118
|
|
115
|
119
|
json << "],\"err\":[";
|
116
|
120
|
|
117
|
|
- auto hgErr = _idx->getHeatGridErr(bbox, z);
|
118
|
|
-
|
119
|
121
|
sep = ' ';
|
120
|
|
- for (auto cluster : hgErr) {
|
121
|
|
- json << sep;
|
122
|
|
- sep = ',';
|
|
122
|
+ for (const auto& idx : _idxs) {
|
|
123
|
+ auto hgErr = idx.getHeatGridErr(bbox, z);
|
|
124
|
+ for (auto cluster : hgErr) {
|
|
125
|
+ json << sep;
|
|
126
|
+ sep = ',';
|
123
|
127
|
|
124
|
|
- json << "[" << cluster.latLng.getY() << "," << cluster.latLng.getX() << ","
|
125
|
|
- << cluster.size << "]";
|
|
128
|
+ json << "[" << cluster.latLng.getY() << "," << cluster.latLng.getX() << ","
|
|
129
|
+ << cluster.size << "]";
|
|
130
|
+ }
|
126
|
131
|
}
|
127
|
132
|
|
128
|
133
|
json << "]}";
|
|
@@ -143,6 +148,9 @@ util::http::Answer StatServer::handleMapReq(const Params& pars) const {
|
143
|
148
|
if (pars.count("cb")) cb = pars.find("cb")->second.c_str();
|
144
|
149
|
auto box = util::split(pars.find("bbox")->second, ',');
|
145
|
150
|
|
|
151
|
+ // TODO!
|
|
152
|
+ size_t did = 0;
|
|
153
|
+
|
146
|
154
|
if (box.size() != 4) throw std::invalid_argument("Invalid request.");
|
147
|
155
|
|
148
|
156
|
double lat1 = atof(box[0].c_str());
|
|
@@ -160,31 +168,37 @@ util::http::Answer StatServer::handleMapReq(const Params& pars) const {
|
160
|
168
|
if (cb.size()) json << cb << "(";
|
161
|
169
|
json << "{\"stats\":[";
|
162
|
170
|
|
163
|
|
- auto ret = _idx->getStations(bbox);
|
164
|
171
|
char sep = ' ';
|
165
|
|
- for (auto stat : ret) {
|
166
|
|
- json << sep;
|
167
|
|
- sep = ',';
|
168
|
|
- printStation(stat, &json);
|
|
172
|
+ for (const auto& idx : _idxs) {
|
|
173
|
+ auto ret = idx.getStations(bbox);
|
|
174
|
+ for (auto stat : ret) {
|
|
175
|
+ json << sep;
|
|
176
|
+ sep = ',';
|
|
177
|
+ printStation(stat, did, &json);
|
|
178
|
+ }
|
169
|
179
|
}
|
170
|
180
|
|
171
|
181
|
json << "], \"groups\":[";
|
172
|
|
- auto gret = _idx->getGroups(bbox);
|
173
|
182
|
sep = ' ';
|
174
|
|
- for (auto group : gret) {
|
175
|
|
- if (group->polyStations.size() == 1 && group->osmid < 2) continue;
|
176
|
|
- json << sep;
|
177
|
|
- sep = ',';
|
178
|
|
- printGroup(group, &json);
|
|
183
|
+ for (const auto& idx : _idxs) {
|
|
184
|
+ auto gret = idx.getGroups(bbox);
|
|
185
|
+ for (auto group : gret) {
|
|
186
|
+ if (group->polyStations.size() == 1 && group->osmid < 2) continue;
|
|
187
|
+ json << sep;
|
|
188
|
+ sep = ',';
|
|
189
|
+ printGroup(group, &json);
|
|
190
|
+ }
|
179
|
191
|
}
|
180
|
192
|
|
181
|
193
|
json << "], \"su\":[";
|
182
|
|
- auto suggs = _idx->getSuggestions(bbox);
|
183
|
194
|
sep = ' ';
|
184
|
|
- for (auto sugg : suggs) {
|
185
|
|
- json << sep;
|
186
|
|
- sep = ',';
|
187
|
|
- printSugg(sugg, &json);
|
|
195
|
+ for (const auto& idx : _idxs) {
|
|
196
|
+ auto suggs = idx.getSuggestions(bbox);
|
|
197
|
+ for (auto sugg : suggs) {
|
|
198
|
+ json << sep;
|
|
199
|
+ sep = ',';
|
|
200
|
+ printSugg(sugg, &json);
|
|
201
|
+ }
|
188
|
202
|
}
|
189
|
203
|
|
190
|
204
|
json << "]}";
|
|
@@ -198,13 +212,13 @@ util::http::Answer StatServer::handleMapReq(const Params& pars) const {
|
198
|
212
|
}
|
199
|
213
|
|
200
|
214
|
// _____________________________________________________________________________
|
201
|
|
-void StatServer::printStation(const Station* stat, std::ostream* out) const {
|
|
215
|
+void StatServer::printStation(const Station* stat, size_t did, std::ostream* out) const {
|
202
|
216
|
auto latLng =
|
203
|
217
|
util::geo::webMercToLatLng<double>(stat->pos.getX(), stat->pos.getY());
|
204
|
218
|
(*out) << "{\"id\":" << stat->id << ",\"lat\":" << latLng.getY()
|
205
|
219
|
<< ",\"lon\":" << latLng.getX();
|
206
|
220
|
|
207
|
|
- if (stat->origGroup != stat->group || _idx->getGroup(stat->group)->osmid == 1)
|
|
221
|
+ if (stat->origGroup != stat->group || _idxs[did].getGroup(stat->group)->osmid == 1)
|
208
|
222
|
(*out) << ",\"su\":1";
|
209
|
223
|
|
210
|
224
|
if (stat->attrErrs.size())
|
|
@@ -283,7 +297,11 @@ util::http::Answer StatServer::handleGroupReq(const Params& pars) const {
|
283
|
297
|
if (pars.count("cb")) cb = pars.find("cb")->second.c_str();
|
284
|
298
|
|
285
|
299
|
size_t gid = atol(pars.find("id")->second.c_str());
|
286
|
|
- auto group = _idx->getGroup(gid);
|
|
300
|
+
|
|
301
|
+ // TODO!
|
|
302
|
+ size_t did=0;
|
|
303
|
+
|
|
304
|
+ auto group = _idxs[did].getGroup(gid);
|
287
|
305
|
|
288
|
306
|
if (!group) return util::http::Answer("404 Not Found", "Group not found.");
|
289
|
307
|
|
|
@@ -318,7 +336,7 @@ util::http::Answer StatServer::handleGroupReq(const Params& pars) const {
|
318
|
336
|
for (const auto& sid : group->stations) {
|
319
|
337
|
json << sep;
|
320
|
338
|
sep = ',';
|
321
|
|
- const auto stat = _idx->getStation(sid);
|
|
339
|
+ const auto stat = _idxs[did].getStation(sid);
|
322
|
340
|
json << "{\"id\":" << sid << ","
|
323
|
341
|
<< "\"osmid\":" << stat->osmid << ","
|
324
|
342
|
<< "\"group\":" << stat->group << ","
|
|
@@ -363,7 +381,10 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
|
363
|
381
|
if (pars.count("cb")) cb = pars.find("cb")->second.c_str();
|
364
|
382
|
|
365
|
383
|
size_t sid = atol(pars.find("id")->second.c_str());
|
366
|
|
- auto stat = _idx->getStation(sid);
|
|
384
|
+ // TODO!
|
|
385
|
+ size_t did=0;
|
|
386
|
+
|
|
387
|
+ auto stat = _idxs[did].getStation(sid);
|
367
|
388
|
|
368
|
389
|
if (!stat) return util::http::Answer("404 Not Found", "Station not found.");
|
369
|
390
|
|
|
@@ -400,7 +421,7 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
|
400
|
421
|
for (const auto& err : stat->attrErrs) {
|
401
|
422
|
json << sep;
|
402
|
423
|
sep = ',';
|
403
|
|
- const auto otherStat = _idx->getStation(err.otherId);
|
|
424
|
+ const auto otherStat = _idxs[did].getStation(err.otherId);
|
404
|
425
|
json << "{";
|
405
|
426
|
json << "\"attr\":[\"" << err.attr << "\",\"" << stat->attrs.at(err.attr)[0]
|
406
|
427
|
<< "\"]";
|
|
@@ -420,39 +441,39 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
|
420
|
441
|
|
421
|
442
|
// suggestions
|
422
|
443
|
if (stat->group != stat->origGroup ||
|
423
|
|
- _idx->getGroup(stat->group)->osmid == 1) {
|
424
|
|
- if (_idx->getGroup(stat->origGroup)->osmid < 2) {
|
425
|
|
- if (_idx->getGroup(stat->group)->osmid == 1) {
|
|
444
|
+ _idxs[did].getGroup(stat->group)->osmid == 1) {
|
|
445
|
+ if (_idxs[did].getGroup(stat->origGroup)->osmid < 2) {
|
|
446
|
+ if (_idxs[did].getGroup(stat->group)->osmid == 1) {
|
426
|
447
|
json << "{\"type\": 1, \"target_gid\":" << stat->group << "}";
|
427
|
448
|
seper = ',';
|
428
|
|
- } else if (_idx->getGroup(stat->group)->osmid > 1) {
|
|
449
|
+ } else if (_idxs[did].getGroup(stat->group)->osmid > 1) {
|
429
|
450
|
json << "{\"type\": 2, \"target_gid\":" << stat->group
|
430
|
|
- << ",\"target_osm_rel_id\":" << _idx->getGroup(stat->group)->osmid
|
|
451
|
+ << ",\"target_osm_rel_id\":" << _idxs[did].getGroup(stat->group)->osmid
|
431
|
452
|
<< "}";
|
432
|
453
|
seper = ',';
|
433
|
454
|
}
|
434
|
455
|
} else {
|
435
|
|
- if (_idx->getGroup(stat->group)->osmid == 1 &&
|
436
|
|
- _idx->getGroup(stat->group)->stations.size() > 1) {
|
|
456
|
+ if (_idxs[did].getGroup(stat->group)->osmid == 1 &&
|
|
457
|
+ _idxs[did].getGroup(stat->group)->stations.size() > 1) {
|
437
|
458
|
json << "{\"type\": 3,\"orig_gid\":" << stat->origGroup
|
438
|
459
|
<< ",\"orig_osm_rel_id\":"
|
439
|
|
- << _idx->getGroup(stat->origGroup)->osmid
|
|
460
|
+ << _idxs[did].getGroup(stat->origGroup)->osmid
|
440
|
461
|
<< ",\"target_gid\":" << stat->group << "}";
|
441
|
462
|
seper = ',';
|
442
|
|
- } else if (_idx->getGroup(stat->group)->osmid > 1) {
|
|
463
|
+ } else if (_idxs[did].getGroup(stat->group)->osmid > 1) {
|
443
|
464
|
json << "{\"type\": 4,\"orig_gid\":" << stat->origGroup
|
444
|
465
|
<< ",\"orig_osm_rel_id\":"
|
445
|
|
- << _idx->getGroup(stat->origGroup)->osmid
|
|
466
|
+ << _idxs[did].getGroup(stat->origGroup)->osmid
|
446
|
467
|
<< ",\"target_gid\":" << stat->group
|
447
|
|
- << ",\"target_osm_rel_id\":" << _idx->getGroup(stat->group)->osmid
|
|
468
|
+ << ",\"target_osm_rel_id\":" << _idxs[did].getGroup(stat->group)->osmid
|
448
|
469
|
<< "}";
|
449
|
470
|
seper = ',';
|
450
|
471
|
} else {
|
451
|
472
|
json << "{\"type\": 5,\"orig_gid\":" << stat->origGroup
|
452
|
473
|
<< ",\"orig_osm_rel_id\":"
|
453
|
|
- << _idx->getGroup(stat->origGroup)->osmid
|
|
474
|
+ << _idxs[did].getGroup(stat->origGroup)->osmid
|
454
|
475
|
<< ",\"target_gid\":" << stat->group
|
455
|
|
- << ",\"target_osm_rel_id\":" << _idx->getGroup(stat->group)->osmid
|
|
476
|
+ << ",\"target_osm_rel_id\":" << _idxs[did].getGroup(stat->group)->osmid
|
456
|
477
|
<< "}";
|
457
|
478
|
seper = ',';
|
458
|
479
|
}
|
|
@@ -460,7 +481,7 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
|
460
|
481
|
}
|
461
|
482
|
|
462
|
483
|
for (auto attrErr : stat->attrErrs) {
|
463
|
|
- const auto otherStat = _idx->getStation(attrErr.otherId);
|
|
484
|
+ const auto otherStat = _idxs[did].getStation(attrErr.otherId);
|
464
|
485
|
if (otherStat->osmid == stat->osmid) {
|
465
|
486
|
// fix attributes
|
466
|
487
|
json << seper << "{\"type\": 6,\"attr\":\"" << attrErr.attr << "\""
|