Yeah baby
This commit is contained in:
127
compare_snapshots.py
Normal file
127
compare_snapshots.py
Normal file
@@ -0,0 +1,127 @@
|
||||
# compare_snapshots.py
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
#########################################################
|
||||
# Utility
|
||||
#########################################################
|
||||
|
||||
def load_json(path):
|
||||
return json.loads(Path(path).read_text())
|
||||
|
||||
def clean_money(val):
|
||||
return float(val.replace("$","").replace(",",""))
|
||||
|
||||
def clean_percent(val):
|
||||
return float(val.replace("%",""))
|
||||
|
||||
#########################################################
|
||||
# Extract Scorecard
|
||||
#########################################################
|
||||
|
||||
def extract_scorecard(snapshot_dir):
|
||||
|
||||
table0 = Path(snapshot_dir)/"tables"/"table_00.json"
|
||||
table1 = Path(snapshot_dir)/"tables"/"table_01.json"
|
||||
|
||||
t0 = load_json(table0)["rows"]
|
||||
t1 = load_json(table1)["rows"]
|
||||
|
||||
metrics = {}
|
||||
|
||||
for row in t0:
|
||||
|
||||
name = row[0]
|
||||
|
||||
projected = row[2]
|
||||
|
||||
if "Earnings Per Share" in name:
|
||||
metrics["EPS"] = clean_money(projected)
|
||||
|
||||
if "Return On Equity" in name:
|
||||
metrics["ROE"] = clean_percent(projected)
|
||||
|
||||
if "Credit Rating" in name:
|
||||
metrics["Credit"] = projected
|
||||
|
||||
if "Image Rating" in name:
|
||||
metrics["Image"] = int(projected)
|
||||
|
||||
|
||||
for row in t1:
|
||||
|
||||
name = row[0]
|
||||
|
||||
projected = row[1]
|
||||
|
||||
if "Net Profit" in name:
|
||||
metrics["Profit"] = int(projected.replace(",",""))
|
||||
|
||||
if "Ending Cash" in name:
|
||||
metrics["Cash"] = int(projected.replace(",",""))
|
||||
|
||||
return metrics
|
||||
|
||||
|
||||
#########################################################
|
||||
# Rank Decisions
|
||||
#########################################################
|
||||
|
||||
def score(m):
|
||||
|
||||
s = 0
|
||||
|
||||
s += m["EPS"] * 100
|
||||
s += m["ROE"] * 5
|
||||
s += m["Image"] * 2
|
||||
s += m["Cash"] / 1000
|
||||
|
||||
return s
|
||||
|
||||
|
||||
#########################################################
|
||||
# Main
|
||||
#########################################################
|
||||
|
||||
base = Path("captures/Y11 / Round1")
|
||||
|
||||
snapshots = sorted(base.glob("snapshot_*"))
|
||||
|
||||
results = []
|
||||
|
||||
for snap in snapshots:
|
||||
|
||||
try:
|
||||
|
||||
m = extract_scorecard(snap)
|
||||
|
||||
s = score(m)
|
||||
|
||||
results.append((s,snap.name,m))
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Skipping",snap.name,e)
|
||||
|
||||
|
||||
|
||||
results.sort(reverse=True)
|
||||
|
||||
|
||||
print("\n=== Snapshot Rankings ===\n")
|
||||
|
||||
|
||||
for s,name,m in results:
|
||||
|
||||
print(name)
|
||||
|
||||
print(" Score:",round(s,2))
|
||||
|
||||
print(" EPS:",m["EPS"])
|
||||
print(" ROE:",m["ROE"])
|
||||
print(" Image:",m["Image"])
|
||||
print(" Cash:",m["Cash"])
|
||||
print(" Credit:",m["Credit"])
|
||||
|
||||
print()
|
||||
Reference in New Issue
Block a user