From e1fa093447a1e153071751647de603f5fe5069e2 Mon Sep 17 00:00:00 2001 From: Simon Roberts Date: Wed, 8 Nov 2023 12:07:22 +1100 Subject: [PATCH] Tally NBN info into a file (#299) * Tally NBN info into a file * [MegaLinter] Apply linters fixes * Add percent section, and "None" value where the property was not found * Slightly simplify code * Remove unnecessary f-string * Remove progress message --- code/adhoc_tools.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/adhoc_tools.py b/code/adhoc_tools.py index 7e59e7f787..ce43d988d7 100644 --- a/code/adhoc_tools.py +++ b/code/adhoc_tools.py @@ -264,6 +264,30 @@ def update_historical_tech_and_upgrade_breakdown(): print(tabulate(rows, headers="keys", tablefmt="github")) +def generate_all_suburbs_nbn_tallies(): + """Create a file containing a tally of all suburbs by property (tech, upgrade, etc)""" + exclude_properties = {"name", "locID", "gnaf_pid"} + tallies = {} # property-name -> Counter() + for file in glob.glob("results/**/*.geojson"): + for feature in utils.read_json_file(file)["features"]: + for prop, value in feature["properties"].items(): + if prop not in exclude_properties: + if prop not in tallies: + tallies[prop] = Counter() + tallies[prop][value] += 1 + + # Add percentages and missing items + total_count = sum(tallies["tech"].values()) # everything has a tech+NULL + tallies["percent"] = {} + for prop, kvs in tallies.items(): + if prop in {"tech", "upgrade", "percent"}: + continue + kvs["None"] = total_count - sum(kvs.values()) + tallies["percent"][prop] = {k: f"{100 * v / total_count:.2f}%" for k, v in kvs.items()} + + utils.write_json_file("results/all-suburbs-nbn-tallies.json", tallies, indent=1) + + if __name__ == "__main__": LOGLEVEL = os.environ.get("LOGLEVEL", "INFO").upper() logging.basicConfig(level=LOGLEVEL, format="%(asctime)s %(levelname)s %(threadName)s %(message)s")