diff --git a/tools/python/mwm/mwm_feature_compare.py b/tools/python/mwm/mwm_feature_compare.py new file mode 100755 index 0000000000..82787bdadf --- /dev/null +++ b/tools/python/mwm/mwm_feature_compare.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from __future__ import print_function +from mwm import MWM + +import argparse +import os +import multiprocessing + + +OMIM_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..') + + +def count_feature(mwm_path, feature_name): + mwm = MWM(open(mwm_path, 'rb')) + mwm.read_header() + mwm.read_types(os.path.join(OMIM_ROOT, 'data', 'types.txt')) + counter = 0 + for feature in mwm.iter_features(): + if feature_name in feature['header']['types']: + counter += 1 + return counter + + +def compare_feature_num(args_tuple): + old_mwm, new_mwm, feature_name, threshold = args_tuple + old_feature_count = count_feature(old_mwm, feature_name) + new_feature_count = count_feature(new_mwm, feature_name) + delta = new_feature_count - old_feature_count + + if delta < 0: + p_change = float(abs(delta)) / old_feature_count * 100 + + if p_change > threshold: + print('In \'{0}\' number of \'{1}\' decreased by {2:.0f}% ({3} → {4})'.format( + os.path.basename(new_mwm), feature_name, round(p_change), old_feature_count, new_feature_count)) + return False + return True + + +def compare_mwm(old_mwm_path, new_mwm_path, feature_name, threshold): + def valid_mwm(mwm_name): + return mwm_name.endswith('.mwm') and not mwm_name.startswith('World') + + def generate_names_dict(path): + return dict((file_name, os.path.abspath(os.path.join(path, file_name))) + for file_name in os.listdir(path) if valid_mwm(file_name)) + + old_mwm_list = generate_names_dict(old_mwm_path) + new_mwm_list = generate_names_dict(new_mwm_path) + + same_mwm_names = set(new_mwm_list).intersection(set(old_mwm_list)) + args = ((old_mwm_list[mwm], new_mwm_list[mwm], feature_name, threshold) for mwm in same_mwm_names) + + pool = multiprocessing.Pool() + return all(pool.imap(compare_feature_num, args)) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Script to compare feature count in \'.mwm\' files') + parser.add_argument('-n', '--new', help='New mwm files path', type=str, required=True) + parser.add_argument('-o', '--old', help='Old mwm files path', type=str, required=True) + parser.add_argument('-f', '--feature', help='Feature name to count', type=str, required=True) + parser.add_argument('-t', '--threshold', help='Threshold in percent to warn', type=int, default=20) + + args = parser.parse_args() + if not compare_mwm(args.old, args.new, args.feature, args.threshold): + print('Warning: some .mwm files lost more than {}% booking hotels'.format(args.threshold)) diff --git a/tools/unix/test_planet.sh b/tools/unix/test_planet.sh index 8e8150f24e..b9db599aa9 100755 --- a/tools/unix/test_planet.sh +++ b/tools/unix/test_planet.sh @@ -19,6 +19,7 @@ TARGET="$(cd "${TARGET:-$1}"; pwd)" LOG_PATH="${LOG_PATH:-$TARGET/logs}" PLANET_LOG="$LOG_PATH/generate_planet.log" DELTA_WITH= +BOOKING_THRESHOLD=20 [ $# -gt 1 -a -d "${2-}" ] && DELTA_WITH="$2" source "$SCRIPT_PATH/find_generator_tool.sh" @@ -39,7 +40,7 @@ for log in "$LOG_PATH"/*.log; do fi done -# Step 2: test if mwms and routing were made +# Step 2.1: test if mwms and routing were made echo echo '### MISSING FILES' # Missing MWM files can be derived only from intermediate borders @@ -50,7 +51,7 @@ if [ -d "$TARGET/borders" ]; then done fi -# Step 2.5: compare new files sizes with old +# Step 2.2: compare new files sizes with old if [ -n "$DELTA_WITH" ]; then echo echo "### SIZE DIFFERENCE WITH $DELTA_WITH" @@ -69,7 +70,7 @@ for file in "$TARGET"/*.mwm*; do ln -s "$TARGET/$BASENAME" "$FTARGET/$BASENAME" done -# Step 3: run calc_statistics and check for sections +# Step 3.1: run calc_statistics and check for sections echo echo '### MISSING MWM SECTIONS' FOUND_COASTS= @@ -83,7 +84,7 @@ done [ -z "$FOUND_COASTS" ] && echo && echo 'WARNING: Did not find any coastlines in MWM files' -# Step 3.5: run type_statistics for old and new files to compare +# Step 3.2: run type_statistics for old and new files to compare if [ -n "$DELTA_WITH" ]; then echo echo '### FEATURE DIFFERENCE' @@ -104,7 +105,14 @@ if [ -n "$DELTA_WITH" ]; then rm "$TMPBASE"_* fi -# Step 4: run intergation tests +# Step 3.3: check booking hotels count in new .mwm files +if [ -n "$DELTA_WITH" ]; then + echo + echo '### BOOKING HOTELS COUNT DIFFERENCE' + python "$OMIM_PATH/tools/python/mwm/mwm_feature_compare.py" -n "$TARGET" -o "$DELTA_WITH" -f "sponsored-booking" -t $BOOKING_THRESHOLD +fi + +# Step 4: run integration tests echo echo '### INTEGRATION TESTS' "$(dirname "$GENERATOR_TOOL")/routing_integration_tests" "--data_path=$FTARGET/../" "--user_resource_path=$OMIM_PATH/data/" "--suppress=online_cross_tests.*" 2>&1