refactoring

This commit is contained in:
Patrick Brosi 2018-08-01 14:25:54 +02:00
parent 04e87c1d9c
commit 64b83f569c
24 changed files with 186 additions and 310 deletions

View file

@ -21,7 +21,7 @@
#include "pfaedle/trgraph/Graph.h"
#include "util/geo/output/GeoGraphJsonOutput.h"
#include "util/geo/output/GeoJsonOutput.h"
#include "util/json/JsonWriter.h"
#include "util/json/Writer.h"
#include "util/log/Log.h"
using std::string;
@ -145,10 +145,10 @@ int main(int argc, char** argv) {
if (singleTrip->getShape()) {
auto orig = Collector::getWebMercLine(singleTrip->getShape(), -1, -1);
o.print(orig, {{"ver", "old"}});
o.print(orig, util::json::Dict{{"ver", "old"}});
}
o.print(l, {{"ver", "new"}});
o.print(l, util::json::Dict{{"ver", "new"}});
o.flush();
pstr.close();

View file

@ -107,11 +107,11 @@ double Collector::add(const Trip* t, const Shape* oldS, const Shape* newS,
FLine newLCut;
for (auto oldL : oldSegs) {
gjout.print(oldL, {{"ver", "old"}});
gjout.print(oldL, util::json::Dict{{"ver", "old"}});
oldLCut.insert(oldLCut.end(), oldL.begin(), oldL.end());
}
for (auto newL : newSegs) {
gjout.print(newL, {{"ver", "new"}});
gjout.print(newL, util::json::Dict{{"ver", "new"}});
newLCut.insert(newLCut.end(), newL.begin(), newL.end());
}

View file

@ -5,9 +5,9 @@
#ifndef PFAEDLE_NETGRAPH_EDGEPL_H_
#define PFAEDLE_NETGRAPH_EDGEPL_H_
#include <map>
#include <set>
#include <string>
#include <vector>
#include "ad/cppgtfs/gtfs/Feed.h"
#include "util/String.h"
#include "util/geo/GeoGraph.h"
@ -33,12 +33,14 @@ class EdgePL : public GeoEdgePL<float> {
}
}
const util::geo::FLine* getGeom() const { return &_l; }
void getAttrs(std::map<std::string, std::string>* obj) const {
(*obj)["num_trips"] = std::to_string(_trips.size());
(*obj)["route_short_names"] =
util::implode(_routeShortNames.begin(), _routeShortNames.end(), ", ");
(*obj)["trip_short_names"] =
util::implode(_tripShortNames.begin(), _tripShortNames.end(), ", ");
util::json::Dict getAttrs() const {
util::json::Dict obj;
obj["num_trips"] = static_cast<int>(_trips.size());
obj["route_short_names"] = util::json::Array(
_routeShortNames.begin(), _routeShortNames.end());
obj["trip_short_names"] = util::json::Array(_tripShortNames.begin(),
_tripShortNames.end());
return obj;
}
private:

View file

@ -25,8 +25,8 @@ class NodePL : public GeoNodePL<float> {
NodePL(const util::geo::FPoint& geom) { _geom = geom; } // NOLINT
const util::geo::FPoint* getGeom() const { return &_geom; }
void getAttrs(std::map<std::string, std::string>* attrs) const {
UNUSED(attrs);
util::json::Dict getAttrs() const {
return util::json::Dict();
}
private:

View file

@ -190,7 +190,7 @@ void OsmBuilder::read(const std::string& path, const OsmReadOpts& opts,
deleteOrphEdgs(g);
LOG(VDEBUG) << "Collapsing edges...";
collapseEdges(g);
// collapseEdges(g);
LOG(VDEBUG) << "Deleting orphan nodes...";
deleteOrphNds(g);
@ -212,8 +212,14 @@ void OsmBuilder::read(const std::string& path, const OsmReadOpts& opts,
LOG(VDEBUG) << "Write dummy node self-edges...";
writeSelfEdgs(g);
LOG(DEBUG) << "Graph has " << g->getNds()->size() << " nodes and " << comps
<< " connected component(s)";
size_t numEdges = 0;
for (auto* n : *g->getNds()) {
numEdges += n->getAdjListOut().size();
}
LOG(DEBUG) << "Graph has " << g->getNds()->size() << " nodes, " << numEdges
<< " edges and " << comps << " connected component(s)";
}
// _____________________________________________________________________________
@ -367,8 +373,7 @@ void OsmBuilder::readWriteWays(xml::File* i, util::xml::XmlWriter* o,
}
// _____________________________________________________________________________
NodePL OsmBuilder::plFromGtfs(const Stop* s,
const OsmReadOpts& ops) const {
NodePL OsmBuilder::plFromGtfs(const Stop* s, const OsmReadOpts& ops) const {
NodePL ret(util::geo::latLngToWebMerc<float>(s->getLat(), s->getLng()),
StatInfo(ops.statNormzer(s->getName()),
ops.trackNormzer(s->getPlatformCode()), false));
@ -1671,7 +1676,6 @@ uint32_t OsmBuilder::writeComps(Graph* g) const {
}
}
// the last comp was not used
delete comp;

View file

@ -76,24 +76,27 @@ void EdgePL::setCost(const router::EdgeCost& c) { _cost = c; }
// _____________________________________________________________________________
void EdgePL::getAttrs(std::map<std::string, std::string>* obj) const {
(*obj)["cost"] = std::to_string(_cost.getValue());
(*obj)["from_edge"] = util::toString(_startE);
(*obj)["to_edge"] = util::toString(_endE);
(*obj)["cost_m_lvl1"] = std::to_string(_cost.meterDistLvl1);
(*obj)["cost_m_lvl0"] = std::to_string(_cost.meterDist);
(*obj)["cost_m_lvl1"] = std::to_string(_cost.meterDistLvl1);
(*obj)["cost_m_lvl2"] = std::to_string(_cost.meterDistLvl2);
(*obj)["cost_m_lvl3"] = std::to_string(_cost.meterDistLvl3);
(*obj)["cost_m_lvl4"] = std::to_string(_cost.meterDistLvl4);
(*obj)["cost_m_lvl5"] = std::to_string(_cost.meterDistLvl5);
(*obj)["cost_m_lvl6"] = std::to_string(_cost.meterDistLvl6);
(*obj)["cost_m_lvl7"] = std::to_string(_cost.meterDistLvl7);
(*obj)["cost_fullturn"] = std::to_string(_cost.fullTurns);
(*obj)["cost_st_passthru"] = std::to_string(_cost.passThruStations);
(*obj)["cost_m_oneway"] = std::to_string(_cost.oneWayMeters);
(*obj)["cost_m_lineunmatch"] = std::to_string(_cost.lineUnmatchedMeters);
(*obj)["cost_reach_node_pen"] = std::to_string(_cost.reachPen);
(*obj)["cost_oneway_event"] = std::to_string(_cost.oneWayEdges);
(*obj)["dummy"] = _edges.size() ? "no" : "yes";
util::json::Dict EdgePL::getAttrs() const {
util::json::Dict obj;
obj["cost"] = std::to_string(_cost.getValue());
obj["from_edge"] = util::toString(_startE);
obj["to_edge"] = util::toString(_endE);
obj["cost_m_lvl1"] = std::to_string(_cost.meterDistLvl1);
obj["cost_m_lvl0"] = std::to_string(_cost.meterDist);
obj["cost_m_lvl1"] = std::to_string(_cost.meterDistLvl1);
obj["cost_m_lvl2"] = std::to_string(_cost.meterDistLvl2);
obj["cost_m_lvl3"] = std::to_string(_cost.meterDistLvl3);
obj["cost_m_lvl4"] = std::to_string(_cost.meterDistLvl4);
obj["cost_m_lvl5"] = std::to_string(_cost.meterDistLvl5);
obj["cost_m_lvl6"] = std::to_string(_cost.meterDistLvl6);
obj["cost_m_lvl7"] = std::to_string(_cost.meterDistLvl7);
obj["cost_fullturn"] = std::to_string(_cost.fullTurns);
obj["cost_st_passthru"] = std::to_string(_cost.passThruStations);
obj["cost_m_oneway"] = std::to_string(_cost.oneWayMeters);
obj["cost_m_lineunmatch"] = std::to_string(_cost.lineUnmatchedMeters);
obj["cost_reach_node_pen"] = std::to_string(_cost.reachPen);
obj["cost_oneway_event"] = std::to_string(_cost.oneWayEdges);
obj["dummy"] = _edges.size() ? "no" : "yes";
return obj;
}

View file

@ -19,7 +19,7 @@ class EdgePL : public GeoEdgePL<float> {
public:
EdgePL() : _cost(), _start(0), _end(0), _startE(0), _endE(0) {}
const util::geo::FLine* getGeom() const;
void getAttrs(std::map<std::string, std::string>* attrs) const;
util::json::Dict getAttrs() const;
router::EdgeList* getEdges();
const router::EdgeList& getEdges() const;
void setStartNode(const trgraph::Node* s);

View file

@ -23,8 +23,9 @@ class NodePL : public GeoNodePL<float> {
const util::geo::FPoint* getGeom() const {
return !_n ? 0 : _n->pl().getGeom();
}
void getAttrs(std::map<std::string, std::string>* attrs) const {
if (_n) _n->pl().getAttrs(attrs);
util::json::Dict getAttrs() const {
if (_n) return _n->pl().getAttrs();
return util::json::Dict();
}
private:

View file

@ -108,11 +108,12 @@ const util::geo::FLine* EdgePL::getGeom() const { return _l; }
util::geo::FLine* EdgePL::getGeom() { return _l; }
// _____________________________________________________________________________
void EdgePL::getAttrs(std::map<std::string, std::string>* obj) const {
(*obj)["m_length"] = std::to_string(_length);
(*obj)["oneway"] = std::to_string(static_cast<int>(_oneWay));
(*obj)["level"] = std::to_string(_lvl);
(*obj)["restriction"] = isRestricted() ? "yes" : "no";
util::json::Dict EdgePL::getAttrs() const {
util::json::Dict obj;
obj["m_length"] = std::to_string(_length);
obj["oneway"] = std::to_string(static_cast<int>(_oneWay));
obj["level"] = std::to_string(_lvl);
obj["restriction"] = isRestricted() ? "yes" : "no";
std::stringstream ss;
bool first = false;
@ -127,7 +128,8 @@ void EdgePL::getAttrs(std::map<std::string, std::string>* obj) const {
first = true;
}
(*obj)["lines"] = ss.str();
obj["lines"] = ss.str();
return obj;
}
// _____________________________________________________________________________

View file

@ -57,7 +57,7 @@ class EdgePL : public GeoEdgePL<float> {
void addPoint(const util::geo::FPoint& p);
// Fill obj with k/v pairs describing the parameters of this payload.
void getAttrs(std::map<std::string, std::string>* obj) const;
util::json::Dict getAttrs() const;
// Return the length in meters stored for this edge payload
double getLength() const;

View file

@ -114,18 +114,19 @@ const util::geo::FPoint* NodePL::getGeom() const { return &_geom; }
void NodePL::setGeom(const util::geo::FPoint& geom) { _geom = geom; }
// _____________________________________________________________________________
void NodePL::getAttrs(std::map<std::string, std::string>* obj) const {
(*obj)["component"] = std::to_string(reinterpret_cast<size_t>(_component));
util::json::Dict NodePL::getAttrs() const {
util::json::Dict obj;
obj["component"] = std::to_string(reinterpret_cast<size_t>(_component));
#ifdef PFAEDLE_DBG
(*obj)["dijkstra_vis"] = _vis ? "yes" : "no";
obj["dijkstra_vis"] = _vis ? "yes" : "no";
#endif
if (getSI()) {
(*obj)["station_info_ptr"] = util::toString(_si);
(*obj)["station_name"] = _si->getName();
(*obj)["station_alt_names"] = util::implode(_si->getAltNames(), ",");
(*obj)["from_osm"] = _si->isFromOsm() ? "yes" : "no";
(*obj)["station_platform"] = _si->getTrack();
(*obj)["station_group"] =
obj["station_info_ptr"] = util::toString(_si);
obj["station_name"] = _si->getName();
obj["station_alt_names"] = util::implode(_si->getAltNames(), ",");
obj["from_osm"] = _si->isFromOsm() ? "yes" : "no";
obj["station_platform"] = _si->getTrack();
obj["station_group"] =
std::to_string(reinterpret_cast<size_t>(_si->getGroup()));
std::stringstream gtfsIds;
@ -135,8 +136,9 @@ void NodePL::getAttrs(std::map<std::string, std::string>* obj) const {
}
}
(*obj)["station_group_stops"] = gtfsIds.str();
obj["station_group_stops"] = gtfsIds.str();
}
return obj;
}
// _____________________________________________________________________________

View file

@ -37,7 +37,7 @@ class NodePL : public GeoNodePL<float> {
void setGeom(const util::geo::FPoint& geom);
// Fill obj with k/v pairs describing the parameters of this payload.
void getAttrs(std::map<std::string, std::string>* attrs) const;
util::json::Dict getAttrs() const;
// Set the station info for this node
void setSI(const StatInfo& si);