-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
109 lines (92 loc) · 3.82 KB
/
Copy pathmenu.py
File metadata and controls
109 lines (92 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""Interactive analyzer menu."""
from __future__ import annotations
import csv
from csv_load import load_categorized_file
from metrics import run_all_reports
from mock_data import generate_mock_transactions
from output import (
print_anomalies,
print_day_breakdown,
print_full_analysis,
print_monthly_trends,
print_top_frequency,
print_top_spend,
)
from schemas import CategorizedRecord
def menu(initial_payday: int = 15) -> None:
"""Interactive menu for the analyzer."""
valid_choices = {"1", "2", "3", "4", "5", "6"}
current_records: list[CategorizedRecord] = []
payday_date = initial_payday
duplicate_records: list[CategorizedRecord] = []
while True:
print()
print("Financial Pattern Detector")
print("1. Run all reports")
print("2. Run individual report")
print("3. Generate mock data")
print("4. Load categorized CSV file")
print("5. Set payday date")
print("6. Quit")
choice = input("Choose an option: ").strip()
if choice not in valid_choices:
print("Please choose one of the listed options.")
continue
if choice == "1":
if not current_records:
current_records = generate_mock_transactions()
print("No data was loaded yet, so I used built-in mock data.")
report = run_all_reports(current_records, payday_date=payday_date)
print_full_analysis(report, duplicate_count=len(duplicate_records))
elif choice == "2":
if not current_records:
current_records = generate_mock_transactions()
print("No data was loaded yet, so I used built-in mock data.")
report = run_all_reports(current_records, payday_date=payday_date)
print("a. Top 10 by frequency")
print("b. Top 10 by total spend")
print("c. Day-of-week")
print("d. Monthly trends")
print("e. Anomalies")
inner = input("Pick a report: ").strip().lower()
if inner == "a":
print_top_frequency(report["top_by_frequency"])
elif inner == "b":
print_top_spend(report["top_by_spend"])
elif inner == "c":
print_day_breakdown(report["day_of_week"])
elif inner == "d":
print_monthly_trends(report["monthly_trends"])
elif inner == "e":
print_anomalies(report["anomaly_report"])
else:
print("That report key was not recognized.")
elif choice == "3":
current_records = generate_mock_transactions()
duplicate_records = []
print(f"Generated {len(current_records)} mock transactions spanning six months.")
elif choice == "4":
file_path = input("Categorized CSV path: ").strip()
try:
current_records, warnings, duplicate_records = load_categorized_file(file_path)
for warning in warnings:
print(warning)
print(f"Loaded {len(current_records)} transactions.")
except (OSError, ValueError, csv.Error) as error:
print(f"Could not load file: {error}")
elif choice == "5":
new_value = input("Payday date (1-28): ").strip()
if new_value.isdigit() and 1 <= int(new_value) <= 28:
payday_date = int(new_value)
print(f"Payday date set to {payday_date}.")
else:
print("Please enter a number from 1 to 28.")
elif choice == "6":
print("Exiting analyzer.")
break
def main() -> None:
from config import load_merged_config
cfg = load_merged_config(explicit=None)
menu(initial_payday=cfg.payday)
if __name__ == "__main__":
main()