Patrick Brosi vor 5 Jahren
Ursprung
Commit
43bb68ca3a

+ 57 - 12
src/osmfixer/index/StatIdx.cpp

@@ -26,16 +26,27 @@ void StatIdx::readFromFile(const std::string& path) {
26 26
     if (line.size() == 0) break;
27 27
 
28 28
     std::stringstream rec(line);
29
-    size_t osmid, group;
29
+    size_t osmid, origGroup, group;
30 30
     double lat, lng;
31 31
     OsmAttrs attrs;
32 32
 
33 33
     rec >> osmid;
34 34
     rec >> lat;
35 35
     rec >> lng;
36
+    rec >> origGroup;
36 37
     rec >> group;
37 38
 
38
-    addStation(osmid, lat, lng, group, attrs);
39
+    std::string temp;
40
+    std::getline(rec, temp, '\t');
41
+    while (std::getline(rec, temp, '\t')) {
42
+      std::string key, val;
43
+      key = temp;
44
+      std::getline(rec, temp, '\t');
45
+      val = temp;
46
+      attrs[key].push_back(val);
47
+    }
48
+
49
+    addStation(osmid, lat, lng, origGroup, group, attrs);
39 50
   }
40 51
 
41 52
   // second, parse groups
@@ -52,17 +63,44 @@ void StatIdx::readFromFile(const std::string& path) {
52 63
     addGroup(osmid, attrs);
53 64
   }
54 65
 
66
+  // third, parse attr errs
67
+  while (std::getline(f, line)) {
68
+    // empty line is separator between blocks
69
+    if (line.size() == 0) break;
70
+
71
+    std::stringstream rec(line);
72
+    size_t id;
73
+    std::string attr, otherAttr;
74
+    double conf;
75
+    size_t otherId;
76
+
77
+    rec >> id;
78
+
79
+    std::getline(rec, attr, '\t');
80
+    std::getline(rec, attr, '\t');
81
+    std::getline(rec, otherAttr, '\t');
82
+
83
+    rec >> conf;
84
+    rec >> otherId;
85
+
86
+    std::cout << id << " " << attr << " " << otherAttr << " " << conf << " "
87
+              << otherId << std::endl;
88
+
89
+    _stations[id].attrErrs.push_back({attr, otherAttr, conf, otherId});
90
+  }
91
+
55 92
   initGroups();
56 93
   initIndex();
57 94
 }
58 95
 
59 96
 // _____________________________________________________________________________
60
-void StatIdx::addStation(size_t osmid, double lat, double lng, size_t group,
61
-                         const OsmAttrs& attrs) {
97
+void StatIdx::addStation(size_t osmid, double lat, double lng, size_t origGroup,
98
+                         size_t group, const OsmAttrs& attrs) {
62 99
   std::cout << "Record: " << osmid << " " << lat << " " << lng << std::endl;
63 100
   auto point = util::geo::latLngToWebMerc<double>(lat, lng);
64 101
 
65
-  _stations.emplace_back(Station{_stations.size(), osmid, group, point, attrs});
102
+  _stations.emplace_back(
103
+      Station{_stations.size(), osmid, origGroup, group, point, attrs});
66 104
 
67 105
   // extend bounding box
68 106
   _bbox = util::geo::extendBox(point, _bbox);
@@ -72,7 +110,7 @@ void StatIdx::addStation(size_t osmid, double lat, double lng, size_t group,
72 110
 void StatIdx::addGroup(size_t osmid, const OsmAttrs& attrs) {
73 111
   std::cout << osmid << std::endl;
74 112
   Group g;
75
-	g.id = _groups.size();
113
+  g.id = _groups.size();
76 114
   g.osmid = osmid;
77 115
   g.attrs = attrs;
78 116
   _groups.emplace_back(g);
@@ -82,8 +120,16 @@ void StatIdx::addGroup(size_t osmid, const OsmAttrs& attrs) {
82 120
 void StatIdx::initGroups() {
83 121
   for (size_t i = 0; i < _stations.size(); i++) {
84 122
     // this should be ensured by the input file
123
+    assert(_stations[i].origGroup < _groups.size());
124
+    _groups[_stations[i].origGroup].stations.push_back(i);
125
+
85 126
     assert(_stations[i].group < _groups.size());
86
-    _groups[_stations[i].group].stations.push_back(i);
127
+    if (_stations[i].group != _stations[i].origGroup &&
128
+        _groups[_stations[i].group].osmid == 1) {
129
+			std::cout << "MURR" << std::endl;
130
+      // only add non-orig groups to polygons of new (non-osm) groups
131
+      _groups[_stations[i].group].stations.push_back(i);
132
+    }
87 133
   }
88 134
 
89 135
   for (size_t i = 0; i < _groups.size(); i++) {
@@ -158,13 +204,12 @@ std::vector<const Station*> StatIdx::getStations(
158 204
 
159 205
 // _____________________________________________________________________________
160 206
 const Station* StatIdx::getStation(size_t id) const {
161
-	if (id >= _stations.size()) return 0;
162
-	return &_stations[id];
207
+  if (id >= _stations.size()) return 0;
208
+  return &_stations[id];
163 209
 }
164 210
 
165
-
166 211
 // _____________________________________________________________________________
167 212
 const Group* StatIdx::getGroup(size_t id) const {
168
-	if (id >= _groups.size()) return 0;
169
-	return &_groups[id];
213
+  if (id >= _groups.size()) return 0;
214
+  return &_groups[id];
170 215
 }

+ 11 - 3
src/osmfixer/index/StatIdx.h

@@ -15,12 +15,20 @@ namespace osmfixer {
15 15
 
16 16
 typedef std::map<std::string, std::vector<std::string>> OsmAttrs;
17 17
 
18
+struct AttrErr {
19
+  std::string attr;
20
+  std::string otherAttr;
21
+  double conf;
22
+  size_t otherId;
23
+};
24
+
18 25
 struct Station {
19 26
   size_t id;
20 27
   size_t osmid;
21
-  size_t group;
28
+  size_t origGroup, group;
22 29
   util::geo::DPoint pos;
23 30
   OsmAttrs attrs;
31
+  std::vector<AttrErr> attrErrs;
24 32
 };
25 33
 
26 34
 struct Group {
@@ -44,8 +52,8 @@ class StatIdx {
44 52
   const Group* getGroup(size_t id) const;
45 53
 
46 54
  private:
47
-  void addStation(size_t id, double lat, double lng, size_t group,
48
-                  const OsmAttrs& attrs);
55
+  void addStation(size_t id, double lat, double lng, size_t origGroup,
56
+                  size_t group, const OsmAttrs& attrs);
49 57
   void addGroup(size_t id, const OsmAttrs& attrs);
50 58
 
51 59
   void initIndex();

+ 76 - 8
src/osmfixer/server/StatServer.cpp

@@ -86,6 +86,7 @@ util::http::Answer StatServer::handleMapReq(const Params& pars) const {
86 86
   auto gret = _idx->getGroups(bbox);
87 87
   sep = ' ';
88 88
   for (auto group : gret) {
89
+    if (group->stations.size() < 2) continue;
89 90
     json << sep;
90 91
     sep = ',';
91 92
     printGroup(group, &json);
@@ -102,11 +103,18 @@ util::http::Answer StatServer::handleMapReq(const Params& pars) const {
102 103
 }
103 104
 
104 105
 // _____________________________________________________________________________
105
-void StatServer::printStation(const Station* stat, std::ostream* out) {
106
+void StatServer::printStation(const Station* stat, std::ostream* out) const {
106 107
   auto latLng =
107 108
       util::geo::webMercToLatLng<double>(stat->pos.getX(), stat->pos.getY());
108
-  (*out) << "{\"id\":" << stat->id << ",\"lat\":"
109
-         << latLng.getY() << ",\"lon\":" << latLng.getX() << "}";
109
+  (*out) << "{\"id\":" << stat->id << ",\"lat\":" << latLng.getY()
110
+         << ",\"lon\":" << latLng.getX();
111
+
112
+  if (stat->origGroup != stat->group || _idx->getGroup(stat->group)->osmid == 1)
113
+    (*out) << ",\"suggestion\":1";
114
+
115
+  if (stat->attrErrs.size())
116
+    (*out) << ",\"attrerrs\":" << stat->attrErrs.size();
117
+  (*out) << "}";
110 118
 }
111 119
 
112 120
 // _____________________________________________________________________________
@@ -122,7 +130,9 @@ void StatServer::printGroup(const Group* group, std::ostream* out) {
122 130
     (*out) << sep << "[" << p.getY() << "," << p.getX() << "]";
123 131
     sep = ',';
124 132
   }
125
-  (*out) << "]}";
133
+  (*out) << "]";
134
+  if (group->osmid == 1) (*out) << ",\"new\":1";
135
+  (*out) << "}";
126 136
 }
127 137
 
128 138
 // _____________________________________________________________________________
@@ -168,8 +178,8 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
168 178
 
169 179
   if (cb.size()) json << cb << "(";
170 180
   json << "{\"id\":" << sid << ","
171
-    << "\"osmid\":" << stat->osmid << ","
172
-    << "\"attrs\":{";
181
+       << "\"osmid\":" << stat->osmid << ","
182
+       << "\"attrs\":{";
173 183
 
174 184
   char sep = ' ';
175 185
 
@@ -182,12 +192,70 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
182 192
     for (const auto& val : par.second) {
183 193
       json << sep2;
184 194
       sep2 = ',';
185
-      json << util::jsonStringEscape(val);
195
+      json << "\"" << util::jsonStringEscape(val) << "\"";
186 196
     }
187 197
     json << "]";
188 198
   }
189 199
 
190
-  json << "}}";
200
+  json << "},\"attrerrs\":[";
201
+
202
+  sep = ' ';
203
+  for (const auto& err : stat->attrErrs) {
204
+    json << sep;
205
+    sep = ',';
206
+    const auto otherStat = _idx->getStation(err.otherId);
207
+    json << "{";
208
+    json << "\"attr\":[\"" << err.attr << "\",\"" << stat->attrs.at(err.attr)[0]
209
+         << "\"]";
210
+    json << ",\"other_attr\":[\"" << err.otherAttr << "\",\""
211
+         << otherStat->attrs.at(err.otherAttr)[0] << "\"]";
212
+    json << ",\"conf\":" << err.conf;
213
+    json << ",\"other\":" << err.otherId;
214
+    json << ",\"other_osmid\":" << otherStat->osmid;
215
+    json << "}";
216
+  }
217
+
218
+  json << "]";
219
+
220
+  json << ",\"suggestions\":[";
221
+
222
+  // suggestions
223
+  if (stat->group != stat->origGroup || _idx->getGroup(stat->group)->osmid == 1) {
224
+    if (_idx->getGroup(stat->origGroup)->osmid < 2) {
225
+      if (_idx->getGroup(stat->group)->osmid == 1) {
226
+        json << "{\"type\": 1, \"target_gid\":" << stat->group << "}";
227
+      } else if (_idx->getGroup(stat->group)->osmid > 1) {
228
+        json << "{\"type\": 2, \"target_gid\":" << stat->group
229
+             << ",\"target_osm_rel_id\":" << _idx->getGroup(stat->group)->osmid
230
+             << "}";
231
+      }
232
+    } else {
233
+      if (_idx->getGroup(stat->group)->osmid == 1) {
234
+        json << "{\"type\": 3,\"orig_gid\":" << stat->origGroup
235
+             << ",\"orig_osm_rel_id\":"
236
+             << _idx->getGroup(stat->origGroup)->osmid
237
+             << ",\"target_gid\":" << stat->group << "}";
238
+      } else if (_idx->getGroup(stat->group)->osmid > 1) {
239
+        json << "{\"type\": 4,\"orig_gid\":" << stat->origGroup
240
+             << ",\"orig_osm_rel_id\":"
241
+             << _idx->getGroup(stat->origGroup)->osmid
242
+             << ",\"target_gid\":" << stat->group
243
+             << ",\"target_osm_rel_id\":" << _idx->getGroup(stat->group)->osmid
244
+             << "}";
245
+      } else {
246
+        json << "{\"type\": 5,\"orig_gid\":" << stat->origGroup
247
+             << ",\"orig_osm_rel_id\":"
248
+             << _idx->getGroup(stat->origGroup)->osmid
249
+             << ",\"target_gid\":" << stat->group
250
+             << ",\"target_osm_rel_id\":" << _idx->getGroup(stat->group)->osmid
251
+             << "}";
252
+      }
253
+    }
254
+  }
255
+
256
+  json << "]";
257
+
258
+  json << "}";
191 259
 
192 260
   if (cb.size()) json << ")";
193 261
 

+ 1 - 1
src/osmfixer/server/StatServer.h

@@ -27,7 +27,7 @@ class StatServer : public util::http::Handler {
27 27
   util::http::Answer handleMapReq(const Params& pars) const;
28 28
   util::http::Answer handleStatReq(const Params& pars) const;
29 29
 
30
-  static void printStation(const Station* stat, std::ostream* out);
30
+  void printStation(const Station* stat, std::ostream* out) const;
31 31
   static void printGroup(const Group* stat, std::ostream* out);
32 32
 
33 33
   const osmfixer::StatIdx* _idx;