Repository navigation
Expand file tree
/
Copy pathreporting.py
More file actions
34 lines (30 loc) · 1.43 KB
/
Copy pathreporting.py
File metadata and controls
34 lines (30 loc) · 1.43 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
from operations import load_data
def generate_report():
data = load_data()
total_customers = len(data)
total_deposits = 0.0
total_withdrawals = 0.0
total_balance = 0.0
top_accounts = []
for acc, info in data.items():
bal = float(info.get("balance",0))
total_balance += bal
deposits = sum(t.get("amount",0) for t in info.get("history",[]) if t.get("type")=="deposit")
withdrawals = sum(t.get("amount",0) for t in info.get("history",[]) if t.get("type")=="withdrawal")
total_deposits += deposits
total_withdrawals += withdrawals
top_accounts.append((acc, bal))
top_accounts.sort(key=lambda x: x[1], reverse=True)
avg_balance = total_balance / total_customers if total_customers else 0.0
report_lines = []
report_lines.append("===== TITAN ATM SYSTEM REPORT =====")
report_lines.append(f"Total Customers: {total_customers}")
report_lines.append(f"Total Deposited: ${total_deposits:.2f}")
report_lines.append(f"Total Withdrawn: ${total_withdrawals:.2f}")
report_lines.append(f"Total Balance in System: ${total_balance:.2f}")
report_lines.append(f"Average Balance per Customer: ${avg_balance:.2f}")
report_lines.append("\nTop 3 Accounts by Balance:")
for acc, bal in top_accounts[:3]:
report_lines.append(f"Account {acc}: ${bal:.2f}")
report_lines.append("====================================")
return "\n".join(report_lines)