diff --git a/libevnav/charger.cpp b/libevnav/charger.cpp index 7bb39ac..51e3c54 100644 --- a/libevnav/charger.cpp +++ b/libevnav/charger.cpp @@ -10,12 +10,14 @@ Charger::Charger() void Charger::read(const QJsonObject &json) { m_name = json["ParkName"].toString(); - m_level = json["Level"].toInt(); - m_network_id = json["NetworkId"].toInt(); - - QJsonObject loc = json["LatLng"].toObject(); - double lat = loc["Lat"].toDouble(); - double lng = loc["Lng"].toDouble(); + QJsonObject tmp = json["Ports"].toArray().at(0).toObject(); + m_level = tmp["Level"].toInt(); + double lat = json["Latitude"].toDouble(); + double lng = json["Longitude"].toDouble(); m_loc = util::Coordinate{util::FloatLongitude{lng}, util::FloatLatitude{lat}}; } +bool Charger::isValid() +{ + return (!m_name.isEmpty() && m_level != 0 && m_loc.IsValid()); +} diff --git a/libevnav/charger.h b/libevnav/charger.h index 0aa4fb2..5071c7c 100644 --- a/libevnav/charger.h +++ b/libevnav/charger.h @@ -41,16 +41,15 @@ class Charger QString name() { return m_name; } VertexId id() { return m_id; } osrm::util::Coordinate loc() { return m_loc; } - int network_id() { return m_network_id; } int level() { return m_level; } void read(const QJsonObject &json); + bool isValid(); private: VertexId m_id; QString m_name; osrm::util::Coordinate m_loc; int m_level; - int m_network_id; static QAtomicInt m_count; }; diff --git a/libevnav/chargerprovider.cpp b/libevnav/chargerprovider.cpp index 4bf9ff5..b1f062a 100644 --- a/libevnav/chargerprovider.cpp +++ b/libevnav/chargerprovider.cpp @@ -19,7 +19,9 @@ void ChargerProvider::read(const QJsonArray &json) QJsonObject obj = json[i].toObject(); Charger c; c.read(obj); - m_chargers[c.id()] = c; + if (c.isValid()) { + m_chargers[c.id()] = c; + } } } @@ -29,7 +31,8 @@ void ChargerProvider::loadJson(QString path) if (file.open(QIODevice::ReadOnly)) { QByteArray data = file.readAll(); QJsonDocument doc(QJsonDocument::fromJson(data)); - read(doc.array()); + QJsonObject root = doc.object(); + read(root["list"].toArray()); } } diff --git a/tests/graph/tst_graphtest.cpp b/tests/graph/tst_graphtest.cpp index fafc023..6a659d3 100644 --- a/tests/graph/tst_graphtest.cpp +++ b/tests/graph/tst_graphtest.cpp @@ -5,6 +5,7 @@ #include "graph.h" #include "shortestpath.h" #include "evnavrequest.h" +#include "chargerprovider.h" class GraphTest : public QObject { @@ -18,6 +19,7 @@ private Q_SLOTS: void testCase2(); void testCase3(); void testCase4(); + void testLoadCharger(); }; GraphTest::GraphTest() @@ -94,6 +96,16 @@ void GraphTest::testCase4() QVERIFY(QString{"0:16"}.compare(time.toString("h:m")) == 0); } +void GraphTest::testLoadCharger() +{ + ChargerProvider provider; + QString path(TOPSRCDIR "/res/result_circuit_electrique_20161016170731.json"); + provider.loadJson(path); + QVERIFY2(provider.size() > 0, "failed to load the charger list"); + ChargerProvider dcfc = provider.filter(provider.fastChargerFilter()); + QVERIFY2(dcfc.size() > 0, "failed to filter chargers"); +} + QTEST_APPLESS_MAIN(GraphTest) #include "tst_graphtest.moc"