Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dsm/dsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static constexpr uint8_t DSM_VERSION_MAJOR = 2;
static constexpr uint8_t DSM_VERSION_MINOR = 5;
static constexpr uint8_t DSM_VERSION_PATCH = 2;
static constexpr uint8_t DSM_VERSION_PATCH = 3;

static auto const DSM_VERSION =
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);
Expand Down
6 changes: 6 additions & 0 deletions src/dsm/headers/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@

#include <utility>

#include "../utility/Typedef.hpp"

namespace dsm {
/// @brief The Counter class contains two counters to count input and output.
class Counter {
protected:
Id m_code;
std::pair<int, int> m_counters = {0, 0}; // First = in, Second = out
public:
void setCode(Id const code);
/// @brief Increase the input counter by one
void increaseInputCounter();
/// @brief Increase the output counter by one
void increaseOutputCounter();

Id code() const;
/// @brief Get the number of input counts registered
/// @param reset If true, the counter is reset to 0. Default is true
int inputCounts(bool reset = true);
Expand Down
43 changes: 35 additions & 8 deletions src/dsm/sources/RoadNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
newStreetId, *street, dynamic_cast<StochasticStreet&>(*street).flowRate());
} else if (street->isSpire()) {
addEdge<SpireStreet>(newStreetId, *street);
dynamic_cast<SpireStreet&>(*m_edges.at(newStreetId))
.setCode(dynamic_cast<SpireStreet&>(*street).code());
} else {
addEdge<Street>(newStreetId, *street);
}
Expand Down Expand Up @@ -263,7 +265,7 @@
// Check if the first line is nodeId;lat;lon
std::string line;
std::getline(ifs, line);
if (line != "id;lon;lat") {
if (line != "id;lon;lat;type") {
throw std::invalid_argument(
Logger::buildExceptionMessage("Invalid file format."));
}
Expand All @@ -274,15 +276,21 @@
continue;
}
std::istringstream iss{line};
std::string nodeId, lat, lon;
std::string nodeId, lat, lon, type;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
std::getline(iss, nodeId, ';');
std::getline(iss, lon, ';');
std::getline(iss, lat, '\n');
std::getline(iss, lat, ';');
std::getline(iss, type, '\n');
dLon = lon == "Nan" ? 0. : std::stod(lon);
dLat = lat == "Nan" ? 0. : std::stod(lat);
auto const& it{m_nodes.find(std::stoul(nodeId))};
if (it != m_nodes.cend()) {
it->second->setCoords(std::make_pair(dLat, dLon));
if (type == "traffic_light" && !it->second->isTrafficLight()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
makeTrafficLight(it->first, 60);

Check warning on line 290 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L290

Added line #L290 was not covered by tests

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
} else if (type == "roundabout" && !it->second->isRoundabout()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
makeRoundabout(it->first);

Check warning on line 292 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L292

Added line #L292 was not covered by tests

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.7 rule Note

MISRA 15.7 rule
} else {
Logger::warning(
std::format("Node with id {} not found. Skipping coordinates ({}, {}).",
Expand Down Expand Up @@ -365,16 +373,18 @@
continue;
}
std::istringstream iss{line};
std::string sourceId, targetId, length, lanes, highway, maxspeed, name, geometry;
// u;v;length;highway;maxspeed;name;geometry
std::string sourceId, targetId, length, lanes, highway, maxspeed, name, geometry,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
coilcode;
// u;v;length;highway;maxspeed;name;geometry;coilcode
std::getline(iss, sourceId, ';');
std::getline(iss, targetId, ';');
std::getline(iss, length, ';');
std::getline(iss, lanes, ';');
std::getline(iss, highway, ';');
std::getline(iss, maxspeed, ';');
std::getline(iss, name, ';');
std::getline(iss, geometry, '\n');
std::getline(iss, geometry, ';');
std::getline(iss, coilcode, '\n');
if (maxspeed.empty()) {
maxspeed = "30"; // Default to 30 km/h if no maxspeed is provided
} else {
Expand Down Expand Up @@ -460,6 +470,11 @@
std::stoul(lanes),
name,
coords);
if (!coilcode.empty()) {
makeSpireStreet(streetId);
auto& coil = edge<SpireStreet>(streetId);
coil.setCode(static_cast<Id>(std::stoul(coilcode)));

Check warning on line 476 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L474-L476

Added lines #L474 - L476 were not covered by tests
}
}
} else {
throw std::invalid_argument(
Expand All @@ -474,14 +489,21 @@
path.substr(path.find_last_of(".")) == ".csv"));
std::ofstream file{path};
// Column names
file << "id;lon;lat\n";
file << "id;lon;lat;type\n";
for (auto const& [nodeId, pNode] : m_nodes) {
file << nodeId << ';';
if (pNode->coords().has_value()) {
file << pNode->coords().value().second << ';' << pNode->coords().value().first;
} else {
file << "Nan;Nan";
}
if (pNode->isTrafficLight()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
file << ";traffic_light";

Check warning on line 501 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L501

Added line #L501 was not covered by tests
} else if (pNode->isRoundabout()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
file << ";roundabout";

Check warning on line 503 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L503

Added line #L503 was not covered by tests
} else {
file << ";intersection";
}
file << '\n';
}
file.close();
Expand All @@ -492,10 +514,15 @@
path.substr(path.find_last_of(".")) == ".csv"));
std::ofstream file{path};
// Column names
file << "id;source_id;target_id;name;geometry\n";
file << "id;source_id;target_id;name;coil_code;geometry\n";
for (auto const& [streetId, pStreet] : m_edges) {
file << streetId << ';' << pStreet->source() << ';' << pStreet->target() << ';'
<< pStreet->name() << ';';
if (pStreet->isSpire()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
file << dynamic_cast<SpireStreet&>(*pStreet).code() << ';';

Check warning on line 522 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L522

Added line #L522 was not covered by tests
} else {
file << ';';
}
if (!pStreet->geometry().empty()) {
file << "LINESTRING(";
for (size_t i{0}; i < pStreet->geometry().size(); ++i) {
Expand Down
2 changes: 2 additions & 0 deletions src/dsm/sources/Sensors.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "../headers/Sensors.hpp"

namespace dsm {
void Counter::setCode(Id const code) { m_code = code; }
void Counter::increaseInputCounter() { m_counters.first++; }
void Counter::increaseOutputCounter() { m_counters.second++; }

Id Counter::code() const { return m_code; }
int Counter::inputCounts(bool reset) {
if (reset) {
int count{0};
Expand Down
2 changes: 1 addition & 1 deletion src/dsm/utility/Typedef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ namespace dsm {
FRECCIAROSSA = 6, // Frecciarossa
ES = 7, // Eurostar
};
enum log_level_t : uint8_t { DEBUG = 0, INFO = 1, WARNING = 2, ERROR = 3 };
enum log_level_t : uint8_t { DEBUG = 0, WARNING = 1, INFO = 2, ERROR = 3 };

}; // namespace dsm
10 changes: 5 additions & 5 deletions test/data/edges.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
id;source_id;target_id;name;geometry
8;2;2;;LINESTRING(0 2,0 2)
6;2;0;;LINESTRING(0 2,0 0)
3;1;0;;LINESTRING(0 1,0 0)
1;0;1;;LINESTRING(0 0,0 1)
id;source_id;target_id;name;coil_code;geometry
8;2;2;;;LINESTRING(0 2,0 2)
6;2;0;;;LINESTRING(0 2,0 0)
3;1;0;;;LINESTRING(0 1,0 0)
1;0;1;;;LINESTRING(0 0,0 1)
8 changes: 4 additions & 4 deletions test/data/nodes.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id;lon;lat
1;0;1
0;0;0
2;0;2
id;lon;lat;type
1;0;1;intersection
0;0;0;intersection
2;0;2;intersection
Loading