Skip to content

Commit

Permalink
Merge pull request #337 from lyricnz/feature/runnable-adhoc
Browse files Browse the repository at this point in the history
Make adhoc_tools.py directly executable (shebang and +x)
  • Loading branch information
LukePrior authored Mar 24, 2024
2 parents d1cd8b2 + dac1b99 commit c3edc04
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion code/adhoc_tools.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import argparse
import csv
import glob
Expand Down Expand Up @@ -238,14 +239,31 @@ 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"):
filenames = glob.glob("results/**/*.geojson")
for n, file in enumerate(filenames):
if n % 100 == 0:
utils.print_progress_bar(n, len(filenames), prefix="Progress:", suffix="Complete", length=50)

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

def _parse_quarter(item: tuple[str, int]):
"""Parse a quarter string into a datetime object. If NA, return epoch."""
try:
return datetime.strptime(item[0], "%b %Y")
except ValueError:
return datetime.fromtimestamp(0)

# sort tallies by frequency, except 'target_eligibility_quarter' which is sorted by date
tallies = {
k: OrderedDict(sorted(v.items(), key=_parse_quarter) if k == "target_eligibility_quarter" else v.most_common())
for k, v in tallies.items()
}

# Add percentages and missing items
total_count = sum(tallies["tech"].values()) # everything has a tech+NULL
tallies["percent"] = {}
Expand Down

0 comments on commit c3edc04

Please sign in to comment.