Skip to content

Commit

Permalink
Ensure Deterministic Ordering of Local Self Government and Ward Data (#…
Browse files Browse the repository at this point in the history
…1665)

* Make ordering of lsg and ward deterministic

* fix dump data

* Fix lsg and ward
  • Loading branch information
Ashesh3 authored Dec 5, 2023
1 parent 8bdbb42 commit 033d085
Show file tree
Hide file tree
Showing 3 changed files with 3,135 additions and 3,099 deletions.
8 changes: 7 additions & 1 deletion care/users/management/commands/load_lsg_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def create_local_bodies(local_body_list):
type of the local body will be match based on this.
if not found, it will be matched against the last item in the choices - "Others"
"""
local_body_list.sort(
key=lambda lb: (
lb["name"],
lb.get("localbody_code", ""),
)
)
local_body_objs = []
for lb in local_body_list:
dist_obj = get_district_obj(lb["district"], lb["state"])
Expand All @@ -87,7 +93,7 @@ def create_local_bodies(local_body_list):
# Hence, those records can be ignored using the `ignore_conflicts` flag
LocalBody.objects.bulk_create(local_body_objs, ignore_conflicts=True)

for f in glob.glob(f"{folder}/*.json"):
for f in sorted(glob.glob(f"{folder}/*.json")):
counter += 1
with open(f"{f}", "r") as data_f:
data = json.load(data_f)
Expand Down
3 changes: 2 additions & 1 deletion care/users/management/commands/load_ward_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_local_body(lb):
),
).first()

for f in glob.glob(f"{folder}/*.json"):
for f in sorted(glob.glob(f"{folder}/*.json")):
with open(f"{f}", "r") as data_f:
data = json.load(data_f)
wards = data.pop("wards", None)
Expand All @@ -69,6 +69,7 @@ def get_local_body(lb):
local_body = get_local_body(data)
if not local_body:
continue
wards.sort(key=lambda x: get_ward_name(x) + str(get_ward_number(x)))
for ward in wards:
counter += 1
try:
Expand Down
Loading

0 comments on commit 033d085

Please sign in to comment.