Skip to content

Commit

Permalink
Add filter/replace substrings in direction name due changes to its sc…
Browse files Browse the repository at this point in the history
…heme
  • Loading branch information
MG-5 committed Apr 28, 2024
1 parent eb57430 commit fa2a6fb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
50 changes: 37 additions & 13 deletions main/dfi/Dfi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,9 @@ void Dfi::parseXml()
if (!isArrivalTimeInFuture(newVehicle))
continue; // reject it

bool directionIsInBlocklist = false;
for (auto &blocklistStation : blocklist)
{
if (blocklistStation == "")
break;

if (newVehicle.directionName == blocklistStation)
{
directionIsInBlocklist = true;
break;
}
}
replaceSubstringsInDirectionName(newVehicle.directionName);

if (directionIsInBlocklist)
if (isDirectionInBlacklist(newVehicle.directionName))
// tram is in blacklist, reject this
continue;

Expand Down Expand Up @@ -155,6 +144,41 @@ void Dfi::parseXml()
std::sort(vehicleArray.begin(), vehicleArray.end(), &localTransportVehicleSorter);
}

//--------------------------------------------------------------------------------------------------
bool Dfi::isDirectionInBlacklist(const std::string &directionName)
{
for (auto &blocklistStation : blocklist)
{
if (blocklistStation == "")
break;

if (directionName == blocklistStation)
{
return true;
}
}

return false;
}

//--------------------------------------------------------------------------------------------------
void Dfi::replaceSubstringsInDirectionName(std::string &directionName)
{
std::array<std::pair<std::string, std::string>, 4> substringsToReplace{
std::make_pair("Magdeburg, ", ""), //
std::make_pair(", Kroatenweg", ""), //
std::make_pair("Elbauenpark", "Elbp."), //
std::make_pair("Klinikum Olvenstedt", "Kl. Olvenstedt") //
};

for (auto &substring : substringsToReplace)
{
auto findResult = directionName.find(substring.first);
if (findResult != std::string::npos)
directionName.replace(findResult, substring.first.length(), substring.second);
}
}

//--------------------------------------------------------------------------------------------------
Time Dfi::getCurrentLocalTime()
{
Expand Down
3 changes: 3 additions & 0 deletions main/dfi/Dfi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class Dfi : public util::wrappers::TaskWithMemberFunctionBase
bool loadXmlFromBuffer();
void parseXml();

bool isDirectionInBlacklist(const std::string &directionName);
void replaceSubstringsInDirectionName(std::string &directionName);

[[nodiscard]] Time getCurrentLocalTime();
[[nodiscard]] bool isArrivalTimeInFuture(LocalTransportVehicle &vehicle);
[[nodiscard]] int calculateArrivalTime(LocalTransportVehicle &vehicle);
Expand Down
8 changes: 1 addition & 7 deletions main/led/RenderTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@ void RenderTask::renderVehicles(bool showCurrentVehicle)
// print line direction, blinking when train is at station
if (!IsTrainAtStation || showCurrentVehicle)
{
std::string directionName = "";
if (vehicle.directionName == "Klinikum Olvenstedt")
directionName = "Kl. Olvenstedt";
else
directionName = vehicle.directionName;

renderer.print({lineNumberPixelWidth, pageCounter}, directionName.data());
renderer.print({lineNumberPixelWidth, pageCounter}, vehicle.directionName.data());
}

if (!IsTrainAtStation)
Expand Down
3 changes: 1 addition & 2 deletions main/nvm/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class Settings : public TaskWithMemberFunctionBase
static constexpr auto StationNameDefault = "Ambrosiusplatz";

static constexpr auto StationBlocklistName = "stationBlcklst";
static constexpr auto StationBlocklistDefault =
"Sudenburg;Reform;Friedenshöhe;Magdeburg, Sudenburg, Braunlager Str.";
static constexpr auto StationBlocklistDefault = "Sudenburg;Reform;Friedenshöhe;Bördepark West";

static constexpr auto PwmResolution = LEDC_TIMER_10_BIT;
static constexpr auto PwmMaximumDuty = (1 << PwmResolution) - 1;
Expand Down

0 comments on commit fa2a6fb

Please sign in to comment.