Calculates difference between zoom dicts, and returns a tuple: (add_zooms_low, add_zooms_high, add_types), for missing zoom levels and missing types altogether. Zooms are separate to preserve sorting order in elements.
(zooms1, zooms2)
| 54 | print("{}: extra {} {}".format(typ, 'high' if high else 'low', zooms_string(scales[0], scales[1] - 1))) |
| 55 | |
| 56 | def create_diff(zooms1, zooms2): |
| 57 | """Calculates difference between zoom dicts, and returns a tuple: |
| 58 | (add_zooms_low, add_zooms_high, add_types), for missing zoom levels |
| 59 | and missing types altogether. Zooms are separate to preserve sorting |
| 60 | order in elements.""" |
| 61 | add_elements_low = collections.defaultdict(list) |
| 62 | add_elements_high = collections.defaultdict(list) |
| 63 | seen = set(zooms2.keys()) |
| 64 | for typ in zooms1: |
| 65 | if typ in zooms2: |
| 66 | seen.remove(typ) |
| 67 | add_missing_zooms(add_elements_low, typ, zooms1[typ][0], zooms2[typ][0], False) |
| 68 | add_missing_zooms(add_elements_high, typ, zooms1[typ][1], zooms2[typ][1], True) |
| 69 | else: |
| 70 | print("{}: not found in the alternative style; {}".format(typ, zooms_string(zooms1[typ][0].scale, zooms1[typ][1].scale))) |
| 71 | |
| 72 | add_types = [] |
| 73 | for typ in sorted(seen): |
| 74 | print("{}: missing completely; {}".format(typ, zooms_string(zooms2[typ][0].scale, zooms2[typ][1].scale))) |
| 75 | cont = drules_struct_pb2.ClassifElementProto() |
| 76 | cont.name = typ |
| 77 | for z in range(zooms2[typ][0].scale, zooms2[typ][1].scale + 1): |
| 78 | fix = copy.deepcopy(zooms2[typ][0]) |
| 79 | fix.scale = z |
| 80 | cont.element.extend([fix]) |
| 81 | add_types.append(cont) |
| 82 | |
| 83 | return (add_elements_low, add_elements_high, add_types) |
| 84 | |
| 85 | def apply_diff(drules, diff): |
| 86 | """Applies diff tuple (from create_diff) to a drules set.""" |
no test coverage detected