from .s32_region_util import calculate_boundary, inflate_boundary from .s35_vd_cal import * from .s35_vd import get_all_virtual_district_ids from .batch_exe import execute_batch_command def generate_virtual_district(name: str, centers: list[str]) -> ChangeSet: cs = ChangeSet() for id in get_all_virtual_district_ids(name): cs.delete({'type': 'virtual_district', 'id': id}) vds = calculate_virtual_district(name, centers)['virtual_districts'] for vd in vds: center = vd['center'] nodes = vd['nodes'] boundary = calculate_boundary(name, nodes) boundary = inflate_boundary(name, boundary) cs.add({ 'type': 'virtual_district', 'id': f"VD_{center}", 'boundary': boundary, 'center': center, 'nodes': nodes }) return execute_batch_command(name, cs)