# Barons Tax Bylaw Validation.
# Ugly code warning.

import csv, sys
import json


with open("data.json", "r") as f:
    dataset = json.load(f, )

wd = dataset["2021"]

vd = {
    "expenditure": wd["expenditure"],
    "revenue":     wd["revenue"],
    "reqs":        {},
    "assessment":  wd["assessment"],
    "levies":      {},
    "rates":       {},
    "minimum_tax": wd["minimum_tax"]
    }

# Balance Calc
vd |= {"balance": round(wd["expenditure"] - wd["revenue"],2)} # Expenditures - Revenue

# Assessment Value Calcs

# Linear
if not wd["assessment"]["linear"] and wd["reqs"]["dip"]:
    vd["assessment"]["linear"] = round(wd["levies"]["dip"] / wd["rates"]["dip"] * 1000,0)
    vd["assessment"]["nonres"] -= vd["assessment"]["linear"]

# Total. we can cheat a little here as the r/nr mill rates are always the same in the dataset
vd["assessment"]["total"] = round(wd["levies"]["general"] / wd["rates"]["res"] * 1000, 0)



print(vd)


#print(_)



