[generator] Reduced mwm size by ~0.5%: do not store zeroes after dot in metadata.

This commit is contained in:
Alex Zolotarev 2016-03-15 20:40:37 +03:00 committed by Sergey Yershov
parent ba208ffb6c
commit d4e6ca053f
3 changed files with 42 additions and 60 deletions

View file

@ -107,38 +107,6 @@ UNIT_TEST(Metadata_ValidateAndFormat_operator)
md.Drop(Metadata::FMD_OPERATOR);
}
UNIT_TEST(Metadata_ValidateAndFormat_ele)
{
classificator::Load();
Classificator const & c = classif();
uint32_t const type_peak = c.GetTypeByPath({ "natural", "peak" });
FeatureParams params;
MetadataTagProcessor p(params);
Metadata & md = params.GetMetadata();
// Ignore tag 'operator' if feature have inappropriate type.
p("ele", "123");
TEST(md.Empty(), ());
params.SetType(type_peak);
p("ele", "0");
TEST(md.Empty(), ());
params.SetType(type_peak);
p("ele", "0,0000");
TEST(md.Empty(), ());
params.SetType(type_peak);
p("ele", "0.0");
TEST(md.Empty(), ());
params.SetType(type_peak);
p("ele", "123");
TEST_EQUAL(md.Get(Metadata::FMD_ELE), "123", ());
md.Drop(Metadata::FMD_ELE);
}
UNIT_TEST(Metadata_ValidateAndFormat_height)
{
FeatureParams params;
@ -155,7 +123,7 @@ UNIT_TEST(Metadata_ValidateAndFormat_height)
TEST(md.Empty(), ());
p("height", "123");
TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "123.0", ());
TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "123", ());
md.Drop(Metadata::FMD_HEIGHT);
p("height", "123.2");
@ -163,11 +131,11 @@ UNIT_TEST(Metadata_ValidateAndFormat_height)
md.Drop(Metadata::FMD_HEIGHT);
p("height", "2 m");
TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "2.0", ());
TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "2", ());
md.Drop(Metadata::FMD_HEIGHT);
p("height", "3-6");
TEST(md.Empty(), ());
TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "6", ());
}
UNIT_TEST(Metadata_ValidateAndFormat_building_levels)
@ -186,7 +154,7 @@ UNIT_TEST(Metadata_ValidateAndFormat_building_levels)
TEST(md.Empty(), ());
p("building:levels", "1");
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1.0", ());
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1", ());
md.Drop(Metadata::FMD_BUILDING_LEVELS);
p("building:levels", "3.2");
@ -194,18 +162,18 @@ UNIT_TEST(Metadata_ValidateAndFormat_building_levels)
md.Drop(Metadata::FMD_BUILDING_LEVELS);
p("building:levels", "1.0");
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1.0", ());
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1", ());
md.Drop(Metadata::FMD_BUILDING_LEVELS);
p("building:levels", "1.0");
p("height", "4.0");
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1.0", ());
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1", ());
md.Drop(Metadata::FMD_BUILDING_LEVELS);
p("height", "4.0");
p("building:levels", "1.0");
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1.0", ());
p("building:levels", "1");
TEST_EQUAL(md.Get(Metadata::FMD_BUILDING_LEVELS), "1", ());
md.Drop(Metadata::FMD_BUILDING_LEVELS);
md.Drop(Metadata::FMD_HEIGHT);

View file

@ -14,3 +14,29 @@ UNIT_TEST(ValidateAndFormat_cuisine_test)
TEST_EQUAL(tagProc.ValidateAndFormat_cuisine(" ; , "), "", ());
TEST_EQUAL(tagProc.ValidateAndFormat_cuisine(" Korean bbq;barbeque;grill,bbq; "), "korean_bbq;barbecue;grill", ());
}
UNIT_TEST(ValidateAndFormat_ele)
{
FeatureParams params;
MetadataTagProcessorImpl tagProc(params);
TEST_EQUAL(tagProc.ValidateAndFormat_ele(""), "", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("not a number"), "", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("0"), "0", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("0.0"), "0", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("0.0000000"), "0", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("22.5"), "22.5", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("-100.3"), "-100.3", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("99.0000000"), "99", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("8900.000023"), "8900", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("-300.9999"), "-301", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("-300.9"), "-300.9", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("15 m"), "15", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("15.9 m"), "15.9", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("15.9m"), "15.9", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("3000 ft"), "914.4", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("3000ft"), "914.4", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("100 feet"), "30.48", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("100feet"), "30.48", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("11'"), "3.35", ());
TEST_EQUAL(tagProc.ValidateAndFormat_ele("11'4\""), "3.45", ());
}

View file

@ -1,5 +1,7 @@
#include "generator/osm2meta.hpp"
#include "platform/measurement_utils.hpp"
#include "coding/url_encode.hpp"
#include "base/logging.hpp"
@ -109,13 +111,7 @@ string MetadataTagProcessorImpl::ValidateAndFormat_opening_hours(string const &
string MetadataTagProcessorImpl::ValidateAndFormat_ele(string const & v) const
{
auto const & isPeak = ftypes::IsPeakChecker::Instance();
if (!isPeak(m_params.m_Types))
return string();
double val = 0;
if(!strings::to_double(v, val) || val == 0)
return string();
return v;
return MeasurementUtils::OSMDistanceToMetersString(v);
}
string MetadataTagProcessorImpl::ValidateAndFormat_turn_lanes(string const & v) const
@ -159,23 +155,15 @@ string MetadataTagProcessorImpl::ValidateAndFormat_internet(string v) const
string MetadataTagProcessorImpl::ValidateAndFormat_height(string const & v) const
{
double val = 0;
string corrected(v, 0, v.find(" "));
if(!strings::to_double(corrected, val) || val == 0)
return string();
ostringstream ss;
ss << fixed << setprecision(1) << val;
return ss.str();
return MeasurementUtils::OSMDistanceToMetersString(v, false /*supportZeroAndNegativeValues*/, 1);
}
string MetadataTagProcessorImpl::ValidateAndFormat_building_levels(string const & v) const
{
double val = 0;
if(!strings::to_double(v, val) || val == 0)
return string();
ostringstream ss;
ss << fixed << setprecision(1) << val;
return ss.str();
double d;
if (!strings::to_double(v, d) || d == 0)
return {};
return strings::to_string_dac(d, 1);
}
string MetadataTagProcessorImpl::ValidateAndFormat_denomination(string const & v) const