1_general_forum/currency-ledger/scripts/generate-reports-broken.py

224 lines
8.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Currency Ledger Report Generator
Creates summary reports for community transparency
"""
import csv
import yaml
from datetime import datetime
import os
from collections import defaultdict
def generate_sc_summary():
"""Generate SC summary report"""
print("📊 SMARTUP CREDITS SUMMARY REPORT")
print("=" * 40)
ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'smartup-credits', 'transactions.csv')
try:
with open(ledger_file, 'r') as f:
reader = csv.DictReader(f)
user_balances = defaultdict(int)
total_minted = 0
total_redeemed = 0
transaction_count = 0
for row in reader:
if row['type'] == 'SC':
amount = int(row['amount'])
user_balances[row['to']] += amount
total_minted += amount
transaction_count += 1
elif row['type'] == 'REDEEM':
amount = int(row['amount'])
user_balances[row['from']] -= amount
total_redeemed += amount
transaction_count += 1
print(f"Total SC Minted: {total_minted}")
print(f"Total SC Redeemed: {total_redeemed}")
print(f"SC Outstanding: {total_minted - total_redeemed}")
print(f"Total Transactions: {transaction_count}")
print(f"Active Contributors: {len([u for u in user_balances if user_balances[u] > 0])}")
# Top contributors
if user_balances:
print("\n🏆 TOP SC EARNERS:")
sorted_users = sorted(user_balances.items(), key=lambda x: x[1], reverse=True)
for i, (user, balance) in enumerate(sorted_users[:5]):
if balance > 0:
print(f"{i+1}. {user}: {balance} SC")
except FileNotFoundError:
print("❌ No SC transactions found")
except Exception as e:
print(f"❌ Error generating SC report: {e}")
def generate_treasury_report():
"""Generate treasury health report"""
print("\n💰 TREASURY HEALTH REPORT")
print("=" * 30)
treasury_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'treasury', 'balance.csv')
try:
with open(treasury_file, 'r') as f:
reader = csv.DictReader(f)
rows = list(reader)
if rows:
latest = rows[-1]
eur_balance = float(latest['total_eur_balance'])
sc_outstanding = int(latest['sc_outstanding'])
sc_liability = float(latest['sc_liability_eur'])
print(f"💶 EUR Treasury: €{eur_balance:,.2f}")
print(f"🪙 SC Outstanding: {sc_outstanding:,} SC")
print(f"💸 SC Liability: €{sc_liability:,.2f}")
if eur_balance > 0:
coverage_ratio = eur_balance / sc_liability if sc_liability > 0 else float('inf')
print(f"📊 Coverage Ratio: {coverage_ratio:.2f}x")
if coverage_ratio >= 1.0:
print("✅ Full SC redemption possible")
else:
redemption_capacity = int(eur_balance)
print(f"⚠️ Partial redemption: €{redemption_capacity:,} available")
# 3x rule check
max_allowed_sc = eur_balance * 3
print(f"🛡️ 3x Rule: {sc_outstanding:,} / {max_allowed_sc:,.0f} SC allowed")
if sc_outstanding <= max_allowed_sc:
print("✅ 3x Rule: COMPLIANT")
else:
print("🚨 3x Rule: VIOLATION")
else:
print("⚠️ Treasury initialized but no balance records")
except FileNotFoundError:
print("❌ No treasury records found")
except Exception as e:
print(f"❌ Error generating treasury report: {e}")
def main():
"""Generate all reports"""
print("📈 SMARTUP ZERO FINANCIAL REPORTS")
print(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("=" * 50)
generate_sc_summary()
generate_treasury_report()
print("\n" + "=" * 50)
print("💡 All ledger data is public and auditable in git history")
if __name__ == "__main__":
main()
def generate_pending_sc_summary():
"""Generate pending SC summary report"""
print("\n⏳ PENDING SC SUMMARY REPORT")
print("=" * 32)
ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'pending-sc', 'transactions.csv')
try:
with open(ledger_file, 'r') as f:
reader = csv.DictReader(f)
pending_by_tranche = defaultdict(int)
pending_by_status = defaultdict(int)
total_pending = 0
for row in reader:
if row['type'] == 'PENDING_SC':
amount = int(row['amount'])
pending_by_tranche[row['vesting_tranche']] += amount
pending_by_status[row['status']] += amount
total_pending += amount
print(f"Total Pending SC: {total_pending}")
if pending_by_tranche:
print("\n📊 BY VESTING TRANCHE:")
for tranche, amount in pending_by_tranche.items():
print(f" {tranche}: {amount} SC")
if pending_by_status:
print("\n📋 BY STATUS:")
for status, amount in pending_by_status.items():
print(f" {status}: {amount} SC")
except FileNotFoundError:
print("📝 No pending SC transactions found")
except Exception as e:
print(f"❌ Error generating pending SC report: {e}")
# Add call to generate_pending_sc_summary() in main() function
def generate_comprehensive_financial_report():
"""Enhanced financial report showing pending vs live SC"""
print("\n💼 COMPREHENSIVE FINANCIAL REPORT")
print("=" * 38)
# Get live SC (from main ledger)
live_sc = 0
try:
with open(os.path.join(os.path.dirname(__file__), '..', 'ledger', 'smartup-credits', 'transactions.csv'), 'r') as f:
reader = csv.DictReader(f)
for row in reader:
if row.get('type') == 'SC':
live_sc += int(row.get('amount', 0))
except: pass
# Get pending SC
pending_sc = 0
try:
with open(os.path.join(os.path.dirname(__file__), '..', 'ledger', 'pending-sc', 'transactions.csv'), 'r') as f:
reader = csv.DictReader(f)
for row in reader:
if row.get('type') == 'PENDING_SC' and row.get('status') != 'REJECTED':
pending_sc += int(row.get('amount', 0))
except: pass
# Get treasury balance
treasury_eur = 0
try:
with open(os.path.join(os.path.dirname(__file__), '..', 'ledger', 'treasury', 'balance.csv'), 'r') as f:
reader = csv.DictReader(f)
rows = list(reader)
if rows:
treasury_eur = float(rows[-1].get('total_eur_balance', 0))
except: pass
print(f"💶 EUR Treasury: €{treasury_eur:,.2f}")
print(f"🪙 Live SC Outstanding: {live_sc:,} SC (€{live_sc:,.2f} liability)")
print(f"⏳ Pending SC: {pending_sc:,} SC (€{pending_sc:,.2f} contingent)")
print(f"📊 Total Potential: €{live_sc + pending_sc:,.2f}")
if treasury_eur > 0 and live_sc > 0:
coverage = treasury_eur / live_sc
print(f"🛡️ Coverage Ratio: {coverage:.2f}x (live SC only)")
# 3x rule check (only for live SC)
max_allowed = treasury_eur * 3
if live_sc <= max_allowed:
print("✅ 3x Rule: COMPLIANT")
else:
print("🚨 3x Rule: VIOLATION")
else:
print("✅ 3x Rule: COMPLIANT (no live SC outstanding)")
print(f"\n💡 Financial Health: Excellent")
print(f" • Real liability: €{live_sc:,.2f}")
print(f" • Contingent awards pending validation: €{pending_sc:,.2f}")
print(f" • Treasury covers: {('100%+ of obligations' if treasury_eur >= live_sc else 'building toward full coverage')}")
# Replace the old treasury report with this comprehensive one