forked from organicmaps/organicmaps-tmp
Make CountFailed test more verbose.
It now reports which records have special (possibly unhandled) features.
This commit is contained in:
parent
74f642283d
commit
419d6d49f7
4 changed files with 140 additions and 20 deletions
|
@ -1288,6 +1288,95 @@ BOOST_AUTO_TEST_CASE(OpenigHours_TestIsOpen)
|
|||
}
|
||||
}
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
bool HasPeriod(std::vector<T> const & v)
|
||||
{
|
||||
auto const hasPeriod = [](T const & t) { return t.HasPeriod(); };
|
||||
return std::any_of(begin(v), end(v), hasPeriod);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool HasPlus(std::vector<T> const & v)
|
||||
{
|
||||
auto const hasPlus = [](T const & t) { return t.HasPlus(); };
|
||||
return std::any_of(begin(v), end(v), hasPlus);
|
||||
}
|
||||
|
||||
bool HasEHours(osmoh::TTimespans const & spans)
|
||||
{
|
||||
auto const hasEHours = [](osmoh::Timespan const & s) -> bool {
|
||||
if (!s.HasEnd())
|
||||
return false;
|
||||
return s.GetEnd().GetMinutes() + s.GetEnd().GetHours() > 24 * std::chrono::minutes(60);
|
||||
};
|
||||
return std::any_of(begin(spans), end(spans), hasEHours);
|
||||
}
|
||||
|
||||
bool HasOffset(osmoh::TMonthdayRanges const & mr)
|
||||
{
|
||||
auto const hasOffset = [](osmoh::MonthdayRange const & md) {
|
||||
return
|
||||
md.GetStart().HasOffset() ||
|
||||
md.GetEnd().HasOffset();
|
||||
};
|
||||
return std::any_of(begin(mr), end(mr), hasOffset);
|
||||
}
|
||||
|
||||
bool HasOffset(osmoh::Weekdays const & wd)
|
||||
{
|
||||
auto const hasOffset = [](osmoh::WeekdayRange const & w) { return w.HasOffset(); };
|
||||
return std::any_of(begin(wd.GetWeekdayRanges()), end(wd.GetWeekdayRanges()), hasOffset);
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
Parsed,
|
||||
Unparsed,
|
||||
Period,
|
||||
Plus,
|
||||
Ehours,
|
||||
Offset
|
||||
};
|
||||
using TRuleFeatures = std::array<bool, 6>;
|
||||
|
||||
std::ostream & operator<<(std::ostream & ost, TRuleFeatures const & f)
|
||||
{
|
||||
ost << f[Parsed] << '\t'
|
||||
<< f[Unparsed] << '\t'
|
||||
<< f[Period] << '\t'
|
||||
<< f[Plus] << '\t'
|
||||
<< f[Ehours] << '\t'
|
||||
<< f[Offset] << '\t';
|
||||
return ost;
|
||||
}
|
||||
|
||||
TRuleFeatures DescribeRule(osmoh::TRuleSequences const & rule)
|
||||
{
|
||||
TRuleFeatures features{};
|
||||
for (auto const & r : rule)
|
||||
{
|
||||
features[Period] |= HasPeriod(r.GetTimes());
|
||||
features[Period] |= HasPeriod(r.GetMonths());
|
||||
features[Period] |= HasPeriod(r.GetYears());
|
||||
features[Period] |= HasPeriod(r.GetWeeks());
|
||||
|
||||
features[Plus] |= HasPlus(r.GetTimes());
|
||||
features[Plus] |= HasPlus(r.GetMonths());
|
||||
features[Plus] |= HasPlus(r.GetYears());
|
||||
|
||||
features[Offset] |= HasOffset(r.GetMonths());
|
||||
features[Offset] |= HasOffset(r.GetWeekdays());
|
||||
|
||||
features[Ehours] |= HasEHours(r.GetTimes());
|
||||
}
|
||||
|
||||
return features;
|
||||
}
|
||||
}
|
||||
|
||||
/// How to run:
|
||||
/// 1. copy opening-count.lst to where the binary is
|
||||
|
@ -1305,6 +1394,7 @@ BOOST_AUTO_TEST_CASE(OpeningHours_CountFailed)
|
|||
size_t num_total = 0;
|
||||
|
||||
std::map<size_t, size_t> hist;
|
||||
std::map<TRuleFeatures, size_t> featuresDistrib;
|
||||
|
||||
while (std::getline(datalist, line))
|
||||
{
|
||||
|
@ -1326,20 +1416,33 @@ BOOST_AUTO_TEST_CASE(OpeningHours_CountFailed)
|
|||
|
||||
line_num++;
|
||||
|
||||
osmoh::TRuleSequences rules;
|
||||
auto const isParsed = Parse(datastr, rules);
|
||||
if (!isParsed) {
|
||||
num_failed += count;
|
||||
hist[count]++;
|
||||
BOOST_TEST_MESSAGE("-- " << count << " :[" << datastr << "]");
|
||||
}
|
||||
else if (!CompareNormalized(datastr, rules))
|
||||
osmoh::TRuleSequences rule;
|
||||
auto const isParsed = Parse(datastr, rule);
|
||||
TRuleFeatures features{};
|
||||
|
||||
if (isParsed)
|
||||
features = DescribeRule(rule);
|
||||
features[Parsed] = true;
|
||||
features[Unparsed] = true;
|
||||
|
||||
if (!isParsed)
|
||||
{
|
||||
num_failed += count;
|
||||
hist[count]++;
|
||||
BOOST_TEST_MESSAGE("- " << count << " :[" << datastr << "]");
|
||||
BOOST_TEST_MESSAGE("+ " << count << " :[" << ToString(rules) << "]");
|
||||
++hist[count];
|
||||
features[Parsed] = false;
|
||||
features[Unparsed] = false;
|
||||
BOOST_TEST_MESSAGE("-- " << count << " :[" << datastr << "]");
|
||||
}
|
||||
else if (!CompareNormalized(datastr, rule))
|
||||
{
|
||||
num_failed += count;
|
||||
++hist[count];
|
||||
features[Unparsed] = false;
|
||||
BOOST_TEST_MESSAGE("- " << count << " :[" << datastr << "]");
|
||||
BOOST_TEST_MESSAGE("+ " << count << " :[" << ToString(rule) << "]");
|
||||
}
|
||||
|
||||
featuresDistrib[features] += count;
|
||||
num_total += count;
|
||||
}
|
||||
|
||||
|
@ -1348,9 +1451,19 @@ BOOST_AUTO_TEST_CASE(OpeningHours_CountFailed)
|
|||
" of " << num_total <<
|
||||
" (" << double(num_failed)/(double(num_total)/100) << "%)");
|
||||
|
||||
std::stringstream desc_message;
|
||||
for (auto const & e : hist)
|
||||
desc_message << "Weight: " << e.first << " Count: " << e.second << std::endl;
|
||||
{
|
||||
std::stringstream message;
|
||||
for (auto const & e : hist)
|
||||
message << "Weight: " << e.first << " Count: " << e.second << std::endl;
|
||||
|
||||
BOOST_TEST_MESSAGE(desc_message.str());
|
||||
BOOST_TEST_MESSAGE(message.str());
|
||||
}
|
||||
{
|
||||
std::stringstream message;
|
||||
message << "Parsed\tUnparsed\tPeriod\tPlus\tEhours\tOffset\tCount\n";
|
||||
for (auto const & e : featuresDistrib)
|
||||
message << e.first << '\t' << e.second << std::endl;
|
||||
|
||||
BOOST_TEST_MESSAGE(message.str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
namespace osmoh
|
||||
{
|
||||
namespace parsing
|
||||
|
@ -68,7 +69,7 @@ struct hours_ : qi::symbols<char, osmoh::Time::THours>
|
|||
hours_()
|
||||
{
|
||||
add
|
||||
// ( "0", 0)( "1", 1)( "2", 2)( "3", 3)( "4", 4)( "5", 5)( "6", 6)( "7", 7)( "8", 8)( "9", 9) /* not standard */
|
||||
( "0", 0_h)( "1", 1_h)( "2", 2_h)( "3", 3_h)( "4", 4_h)( "5", 5_h)( "6", 6_h)( "7", 7_h)( "8", 8_h)( "9", 9_h) /* not standard */
|
||||
("00", 0_h)("01", 1_h)("02", 2_h)("03", 3_h)("04", 4_h)("05", 5_h)("06", 6_h)("07", 7_h)("08", 8_h)("09", 9_h)
|
||||
("10", 10_h)("11", 11_h)("12", 12_h)("13", 13_h)("14", 14_h)("15", 15_h)("16", 16_h)("17", 17_h)("18", 18_h)("19", 19_h)
|
||||
("20", 20_h)("21", 21_h)("22", 22_h)("23", 23_h)("24", 24_h)
|
||||
|
@ -81,7 +82,7 @@ struct exthours_ : qi::symbols<char, osmoh::Time::THours>
|
|||
exthours_()
|
||||
{
|
||||
add
|
||||
// ( "0", 0)( "1", 1)( "2", 2)( "3", 3)( "4", 4)( "5", 5)( "6", 6)( "7", 7)( "8", 8)( "9", 9) /* not standard */
|
||||
( "0", 0_h)( "1", 1_h)( "2", 2_h)( "3", 3_h)( "4", 4_h)( "5", 5_h)( "6", 6_h)( "7", 7_h)( "8", 8_h)( "9", 9_h) /* not standard */
|
||||
("00", 0_h)("01", 1_h)("02", 2_h)("03", 3_h)("04", 4_h)("05", 5_h)("06", 6_h)("07", 7_h)("08", 8_h)("09", 9_h)
|
||||
("10", 10_h)("11", 11_h)("12", 12_h)("13", 13_h)("14", 14_h)("15", 15_h)("16", 16_h)("17", 17_h)("18", 18_h)("19", 19_h)
|
||||
("20", 20_h)("21", 21_h)("22", 22_h)("23", 23_h)("24", 24_h)("25", 25_h)("26", 26_h)("27", 27_h)("28", 28_h)("29", 29_h)
|
||||
|
@ -96,7 +97,7 @@ struct minutes_ : qi::symbols<char, osmoh::Time::TMinutes>
|
|||
minutes_()
|
||||
{
|
||||
add
|
||||
// ( "0", 0)( "1", 1)( "2", 2)( "3", 3)( "4", 4)( "5", 5)( "6", 6)( "7", 7)( "8", 8)( "9", 9) /* not standard */
|
||||
( "0", 0_min)( "1", 1_min)( "2", 2_min)( "3", 3_min)( "4", 4_min)( "5", 5_min)( "6", 6_min)( "7", 7_min)( "8", 8_min)( "9", 9_min) /* not standard */
|
||||
("00", 0_min)("01", 1_min)("02", 2_min)("03", 3_min)("04", 4_min)("05", 5_min)("06", 6_min)("07", 7_min)("08", 8_min)("09", 9_min)
|
||||
("10", 10_min)("11", 11_min)("12", 12_min)("13", 13_min)("14", 14_min)("15", 15_min)("16", 16_min)("17", 17_min)("18", 18_min)("19", 19_min)
|
||||
("20", 20_min)("21", 21_min)("22", 22_min)("23", 23_min)("24", 24_min)("25", 25_min)("26", 26_min)("27", 27_min)("28", 28_min)("29", 29_min)
|
||||
|
@ -112,7 +113,7 @@ struct weeknum_ : qi::symbols<char, unsigned>
|
|||
weeknum_()
|
||||
{
|
||||
add
|
||||
// ( "1", 1)( "2", 2)( "3", 3)( "4", 4)( "5", 5)( "6", 6)( "7", 7)( "8", 8)( "9", 9)
|
||||
( "1", 1)( "2", 2)( "3", 3)( "4", 4)( "5", 5)( "6", 6)( "7", 7)( "8", 8)( "9", 9)
|
||||
("01", 1)("02", 2)("03", 3)("04", 4)("05", 5)("06", 6)("07", 7)("08", 8)("09", 9)
|
||||
("10", 10)("11", 11)("12", 12)("13", 13)("14", 14)("15", 15)("16", 16)("17", 17)("18", 18)("19", 19)
|
||||
("20", 20)("21", 21)("22", 22)("23", 23)("24", 24)("25", 25)("26", 26)("27", 27)("28", 28)("29", 29)
|
||||
|
@ -128,7 +129,7 @@ struct daynum_ : qi::symbols<char, MonthDay::TDayNum>
|
|||
daynum_()
|
||||
{
|
||||
add
|
||||
// ("1", 1)("2", 2)("3", 3)("4", 4)("5", 5)("6", 6)("7", 7)("8", 8)("9", 9)
|
||||
("1", 1)("2", 2)("3", 3)("4", 4)("5", 5)("6", 6)("7", 7)("8", 8)("9", 9)
|
||||
("01", 1)("02", 2)("03", 3)("04", 4)("05", 5)("06", 6)("07", 7)("08", 8)("09", 9)
|
||||
("10", 10)("11", 11)("12", 12)("13", 13)("14", 14)("15", 15)("16", 16)("17", 17)("18", 18)("19", 19)
|
||||
("20", 20)("21", 21)("22", 22)("23", 23)("24", 24)("25", 25)("26", 26)("27", 27)("28", 28)("29", 29)
|
||||
|
|
|
@ -444,6 +444,11 @@ bool WeekdayRange::HasEnd() const
|
|||
return GetEnd() != Weekday::None;;
|
||||
}
|
||||
|
||||
bool WeekdayRange::HasOffset() const
|
||||
{
|
||||
return GetOffset() != 0;
|
||||
}
|
||||
|
||||
bool WeekdayRange::IsEmpty() const
|
||||
{
|
||||
return GetStart() == Weekday::None && GetEnd() == Weekday::None;
|
||||
|
|
|
@ -227,6 +227,7 @@ class WeekdayRange
|
|||
|
||||
bool HasStart() const;
|
||||
bool HasEnd() const;
|
||||
bool HasOffset() const;
|
||||
bool IsEmpty() const;
|
||||
|
||||
Weekday GetStart() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue