Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[transit] GTFS converter. #12946

Merged
merged 3 commits into from May 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3party/opening_hours/opening_hours.hpp
Expand Up @@ -696,6 +696,7 @@ std::ostream & operator<<(std::ostream & ost, TRuleSequences const & sequences);
class OpeningHours
{
public:
OpeningHours() = default;
OpeningHours(std::string const & rule);
OpeningHours(TRuleSequences const & rule);

Expand All @@ -719,6 +720,6 @@ class OpeningHours

private:
TRuleSequences m_rule;
bool m_valid;
bool m_valid = false;
};
} // namespace osmoh
9 changes: 4 additions & 5 deletions drape_frontend/color_constants.cpp
Expand Up @@ -14,7 +14,6 @@
#include "3party/jansson/myjansson.hpp"

#include <fstream>
#include <map>

using namespace std;

Expand Down Expand Up @@ -83,6 +82,8 @@ class TransitColorsHolder
}
}

map<string, dp::Color> const & GetClearColors() const { return m_clearColors; }

private:
dp::Color ParseColor(string const & colorStr)
{
Expand All @@ -106,10 +107,6 @@ TransitColorsHolder & TransitColors()

namespace df
{
string const kTransitColorPrefix = "transit_";
string const kTransitTextPrefix = "text_";
string const kTransitLinePrefix = "line_";

ColorConstant GetTransitColorName(ColorConstant const & localName)
{
return kTransitColorPrefix + kTransitLinePrefix + localName;
Expand All @@ -133,6 +130,8 @@ dp::Color GetColorConstant(ColorConstant const & constant)
return ToDrapeColor(color);
}

map<string, dp::Color> const & GetTransitClearColors() { return TransitColors().GetClearColors(); }

void LoadTransitColors()
{
TransitColors().Load();
Expand Down
7 changes: 6 additions & 1 deletion drape_frontend/color_constants.hpp
Expand Up @@ -2,14 +2,19 @@

#include "drape/color.hpp"

#include <map>
mesozoic-drones marked this conversation as resolved.
Show resolved Hide resolved
#include <string>

namespace df
{
using ColorConstant = std::string;

dp::Color GetColorConstant(ColorConstant const & constant);
inline std::string const kTransitColorPrefix = "transit_";
inline std::string const kTransitTextPrefix = "text_";
inline std::string const kTransitLinePrefix = "line_";

dp::Color GetColorConstant(ColorConstant const & constant);
std::map<std::string, dp::Color> const & GetTransitClearColors();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай сделаем общий порядок методов и ф-ций в hpp и cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделала.

void LoadTransitColors();

ColorConstant GetTransitColorName(ColorConstant const & localName);
Expand Down
1 change: 1 addition & 0 deletions transit/CMakeLists.txt
Expand Up @@ -17,3 +17,4 @@ set(

omim_add_library(${PROJECT_NAME} ${SRC})
omim_add_test_subdirectory(transit_tests)
add_subdirectory(world_feed)
73 changes: 73 additions & 0 deletions transit/world_feed/CMakeLists.txt
@@ -0,0 +1,73 @@
project(world_feed)

set(SRC
color_picker.cpp
color_picker.hpp
date_time_helpers.cpp
date_time_helpers.hpp
feed_helpers.cpp
feed_helpers.hpp
world_feed.cpp
world_feed.hpp
)

omim_add_library(${PROJECT_NAME} ${SRC})

omim_link_libraries(
${PROJECT_NAME}
drape_frontend
shaders
routing
mwm_diff
bsdiff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И от поиска и storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже убрала.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверно mwm_diff и bsdiff тоже не нужны?

tracking
traffic
routing_common
transit
descriptions
ugc
drape
partners_api
web_api
local_ads
kml
editor
indexer
metrics
platform
geometry
coding
base
freetype
expat
icu
agg
jansson
protobuf
stats_client
minizip
succinct
pugixml
oauthcpp
opening_hours
stb_image
sdf_image
vulkan_wrapper
${Qt5Widgets_LIBRARIES}
${Qt5Network_LIBRARIES}
${LIBZ}
)

if (PLATFORM_LINUX)
omim_link_libraries(
${PROJECT_NAME}
dl
)
endif()

link_opengl(${PROJECT_NAME})
link_qt5_core(${PROJECT_NAME})
link_qt5_network(${PROJECT_NAME})

omim_add_test_subdirectory(world_feed_tests)
add_subdirectory(gtfs_converter)
69 changes: 69 additions & 0 deletions transit/world_feed/color_picker.cpp
@@ -0,0 +1,69 @@
#include "transit/world_feed/color_picker.hpp"

#include "drape_frontend/apply_feature_functors.hpp"
#include "drape_frontend/color_constants.hpp"

#include "drape/color.hpp"

#include "base/string_utils.hpp"

#include <limits>
#include <tuple>

namespace
{
std::tuple<double, double, double> GetColors(dp::Color const & color)
{
return {color.GetRedF(), color.GetGreenF(), color.GetBlueF()};
}

double GetSquareDistance(dp::Color const & color1, dp::Color const & color2)
{
auto [r1, g1, b1] = GetColors(color1);
auto [r2, g2, b2] = GetColors(color2);
return (r1 - r2) * (r1 - r2) + (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2);
}
} // namespace

namespace transit
{
ColorPicker::ColorPicker() { df::LoadTransitColors(); }

std::string ColorPicker::GetNearestColor(std::string const & rgb)
{
static std::string const kDefaultColor = "default";
if (rgb.empty())
return kDefaultColor;

auto [it, inserted] = m_colorsToNames.emplace(rgb, kDefaultColor);
if (!inserted)
return it->second;

std::string nearestColor = kDefaultColor;

unsigned int intColor;
// We do not need to add to the cache invalid color, so we just return.
if (!strings::to_uint(rgb, intColor, 16))
return nearestColor;

dp::Color const color = df::ToDrapeColor(static_cast<uint32_t>(intColor));
double minDist = std::numeric_limits<double>::max();

for (auto const & [name, transitColor] : df::GetTransitClearColors())
{
if (double const dist = GetSquareDistance(color, transitColor); dist < minDist)
{
minDist = dist;
nearestColor = name;
}
}
if (nearestColor.find(df::kTransitColorPrefix + df::kTransitLinePrefix) == 0)
{
nearestColor =
nearestColor.substr(df::kTransitColorPrefix.size() + df::kTransitLinePrefix.size());
bykoianko marked this conversation as resolved.
Show resolved Hide resolved
}

it->second = nearestColor;
return nearestColor;
}
} // namespace transit
17 changes: 17 additions & 0 deletions transit/world_feed/color_picker.hpp
@@ -0,0 +1,17 @@
#pragma once

#include <string>
#include <unordered_map>

namespace transit
{
class ColorPicker
{
public:
ColorPicker();
std::string GetNearestColor(std::string const & rgb);

private:
std::unordered_map<std::string, std::string> m_colorsToNames;
};
} // namespace transit