diff --git a/currency-ledger/scripts/generate-reports-broken-backup.py b/currency-ledger/scripts/generate-reports-broken-backup.py new file mode 100755 index 0000000..6f3a6a8 --- /dev/null +++ b/currency-ledger/scripts/generate-reports-broken-backup.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +""" +Currency Ledger Report Generator - Enhanced Working Version +""" + +import csv +from datetime import datetime +import os +from collections import defaultdict + +def generate_pending_sc_summary(): + """Generate pending SC summary report""" + print("ā³ 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) + total_pending = 0 + + for row in reader: + # Skip comment lines + if not row.get('timestamp') or row.get('timestamp').startswith('#'): + continue + + if row.get('type') == 'PENDING_SC': + amount = int(row.get('amount', 0)) + tranche = row.get('vesting_tranche', 'unknown') + + pending_by_tranche[tranche] += amount + total_pending += amount + + print(f"Total Pending SC: {total_pending:,}") + + if pending_by_tranche: + print("\nšŸ“Š BY VESTING TRANCHE:") + for tranche, amount in sorted(pending_by_tranche.items()): + print(f" {tranche}: {amount:,} SC") + + except FileNotFoundError: + print("šŸ“ No pending SC transactions found") + except Exception as e: + print(f"āŒ Error generating pending SC 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) + + print("šŸ“Š SMARTUP CREDITS SUMMARY") + print("=" * 30) + print("Total SC Minted: 0") + print("Total SC Redeemed: 0") + print("SC Outstanding: 0") + print("šŸ“ No live SC transactions yet") + + print() + generate_pending_sc_summary() + + print("\nšŸ’° TREASURY HEALTH REPORT") + print("=" * 30) + print("šŸ’¶ EUR Treasury: €0.00") + print("šŸŖ™ SC Outstanding: 0 SC") + print("šŸ’ø SC Liability: €0.00") + print("āœ… 3x Rule: COMPLIANT (no live SC outstanding)") + + print("\nšŸ“Š FINANCIAL HEALTH: EXCELLENT") + print(" • No current debt or obligations") + print(" • Pending SC awaiting democratic validation") + print(" • Founder compensation tied to collective success") + + print("\n" + "=" * 50) + print("šŸ’” All ledger data is public and auditable in git history") + +if __name__ == "__main__": + main() diff --git a/currency-ledger/scripts/generate-reports-fixed.py b/currency-ledger/scripts/generate-reports-fixed.py deleted file mode 100644 index c6f95cf..0000000 --- a/currency-ledger/scripts/generate-reports-fixed.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env python3 -""" -Currency Ledger Report Generator - Working Version with Real Data Parsing -""" - -import csv -from datetime import datetime -import os -from collections import defaultdict - -def parse_sc_transactions(): - """Parse live SC transactions and calculate totals""" - ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'smartup-credits', 'transactions.csv') - - total_minted = 0 - total_redeemed = 0 - transactions = [] - - try: - with open(ledger_file, 'r') as f: - reader = csv.DictReader(f) - for row in reader: - # Skip comment lines and empty rows - if not row['timestamp'].startswith('#') and row['timestamp'] != '': - transactions.append(row) - amount = int(row['amount']) - if row['type'] == 'SC': - total_minted += amount - elif row['type'] == 'REDEEM': - total_redeemed += amount - except FileNotFoundError: - pass - - return total_minted, total_redeemed, transactions - -def parse_treasury_balance(): - """Parse treasury balance and get latest state""" - ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'treasury', 'balance.csv') - - latest_balance = { - 'total_eur_balance': 0, - 'sc_outstanding': 0, - 'sc_liability_eur': 0 - } - - try: - with open(ledger_file, 'r') as f: - reader = csv.DictReader(f) - for row in reader: - # Skip comment lines and get latest entry - if not row['timestamp'].startswith('#') and row['timestamp'] != '': - latest_balance = { - 'total_eur_balance': float(row['total_eur_balance']), - 'sc_outstanding': int(row['sc_outstanding']), - 'sc_liability_eur': float(row['sc_liability_eur']) - } - except FileNotFoundError: - pass - - return latest_balance - -def generate_pending_sc_summary(): - """Generate pending SC summary report""" - print("ā³ PENDING SC SUMMARY REPORT") - print("=" * 32) - - ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'pending-sc', 'transactions.csv') - - total_pending = 0 - by_tranche = defaultdict(int) - - try: - with open(ledger_file, 'r') as f: - reader = csv.DictReader(f) - for row in reader: - if not row['timestamp'].startswith('#') and row['timestamp'] != '': - amount = int(row['amount']) - total_pending += amount - tranche = row['vesting_tranche'] or 'immediate' - by_tranche[tranche] += amount - - print(f"Total Pending SC: {total_pending:,}") - - if by_tranche: - print(f"\nšŸ“Š BY VESTING TRANCHE:") - for tranche, amount in by_tranche.items(): - print(f" {tranche}: {amount:,} SC") - - except FileNotFoundError: - print("šŸ“ No pending SC transactions") - -def main(): - """Generate comprehensive financial report""" - - print("šŸ“ˆ SMARTUP ZERO FINANCIAL REPORTS") - print(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") - print("=" * 50) - - # Parse live SC data - total_minted, total_redeemed, transactions = parse_sc_transactions() - sc_outstanding = total_minted - total_redeemed - - print("šŸ“Š SMARTUP CREDITS SUMMARY") - print("=" * 30) - print(f"Total SC Minted: {total_minted:,}") - print(f"Total SC Redeemed: {total_redeemed:,}") - print(f"SC Outstanding: {sc_outstanding:,}") - - if transactions: - print(f"\nšŸ“ RECENT TRANSACTIONS:") - for tx in transactions[-3:]: # Show last 3 - print(f" {tx['timestamp'][:10]} | {tx['amount']} SC → {tx['to']} | {tx['reference']}") - else: - print("šŸ“ No live SC transactions yet") - - print() - generate_pending_sc_summary() - - # Parse treasury data - treasury = parse_treasury_balance() - - print("\nšŸ’° TREASURY HEALTH REPORT") - print("=" * 30) - print(f"šŸ’¶ EUR Treasury: €{treasury['total_eur_balance']:.2f}") - print(f"šŸŖ™ SC Outstanding: {treasury['sc_outstanding']:,} SC") - print(f"šŸ’ø SC Liability: €{treasury['sc_liability_eur']:.2f}") - - # Calculate 3x rule compliance - if treasury['total_eur_balance'] == 0: - if treasury['sc_outstanding'] == 0: - print("āœ… 3x Rule: COMPLIANT (no live SC outstanding)") - else: - print("āš ļø 3x Rule: PENDING (SC outstanding but no treasury funding yet)") - else: - ratio = treasury['sc_outstanding'] / (treasury['total_eur_balance'] * 3) - if ratio <= 1: - print(f"āœ… 3x Rule: COMPLIANT ({ratio:.1%} of limit)") - else: - print(f"āŒ 3x Rule: VIOLATION ({ratio:.1%} of limit)") - - # Financial health assessment - print(f"\nšŸ“Š FINANCIAL HEALTH: {'EXCELLENT' if treasury['sc_outstanding'] <= 1000 else 'GOOD' if treasury['sc_outstanding'] <= 10000 else 'NEEDS_FUNDING'}") - if treasury['total_eur_balance'] == 0 and treasury['sc_outstanding'] > 0: - print(" • SC holders earning value through effort-based work") - print(" • Treasury funding needed for SC redemption capability") - - print("\n" + "=" * 50) - print("šŸ’” All ledger data is public and auditable in git history") - -if __name__ == "__main__": - main() diff --git a/currency-ledger/scripts/generate-reports.py b/currency-ledger/scripts/generate-reports.py old mode 100755 new mode 100644 index 6f3a6a8..c6f95cf --- a/currency-ledger/scripts/generate-reports.py +++ b/currency-ledger/scripts/generate-reports.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 """ -Currency Ledger Report Generator - Enhanced Working Version +Currency Ledger Report Generator - Working Version with Real Data Parsing """ import csv @@ -8,6 +8,57 @@ from datetime import datetime import os from collections import defaultdict +def parse_sc_transactions(): + """Parse live SC transactions and calculate totals""" + ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'smartup-credits', 'transactions.csv') + + total_minted = 0 + total_redeemed = 0 + transactions = [] + + try: + with open(ledger_file, 'r') as f: + reader = csv.DictReader(f) + for row in reader: + # Skip comment lines and empty rows + if not row['timestamp'].startswith('#') and row['timestamp'] != '': + transactions.append(row) + amount = int(row['amount']) + if row['type'] == 'SC': + total_minted += amount + elif row['type'] == 'REDEEM': + total_redeemed += amount + except FileNotFoundError: + pass + + return total_minted, total_redeemed, transactions + +def parse_treasury_balance(): + """Parse treasury balance and get latest state""" + ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'treasury', 'balance.csv') + + latest_balance = { + 'total_eur_balance': 0, + 'sc_outstanding': 0, + 'sc_liability_eur': 0 + } + + try: + with open(ledger_file, 'r') as f: + reader = csv.DictReader(f) + for row in reader: + # Skip comment lines and get latest entry + if not row['timestamp'].startswith('#') and row['timestamp'] != '': + latest_balance = { + 'total_eur_balance': float(row['total_eur_balance']), + 'sc_outstanding': int(row['sc_outstanding']), + 'sc_liability_eur': float(row['sc_liability_eur']) + } + except FileNotFoundError: + pass + + return latest_balance + def generate_pending_sc_summary(): """Generate pending SC summary report""" print("ā³ PENDING SC SUMMARY REPORT") @@ -15,64 +66,83 @@ def generate_pending_sc_summary(): ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'pending-sc', 'transactions.csv') + total_pending = 0 + by_tranche = defaultdict(int) + try: with open(ledger_file, 'r') as f: reader = csv.DictReader(f) - - pending_by_tranche = defaultdict(int) - total_pending = 0 - for row in reader: - # Skip comment lines - if not row.get('timestamp') or row.get('timestamp').startswith('#'): - continue - - if row.get('type') == 'PENDING_SC': - amount = int(row.get('amount', 0)) - tranche = row.get('vesting_tranche', 'unknown') - - pending_by_tranche[tranche] += amount + if not row['timestamp'].startswith('#') and row['timestamp'] != '': + amount = int(row['amount']) total_pending += amount - - print(f"Total Pending SC: {total_pending:,}") - - if pending_by_tranche: - print("\nšŸ“Š BY VESTING TRANCHE:") - for tranche, amount in sorted(pending_by_tranche.items()): - print(f" {tranche}: {amount:,} SC") - + tranche = row['vesting_tranche'] or 'immediate' + by_tranche[tranche] += amount + + print(f"Total Pending SC: {total_pending:,}") + + if by_tranche: + print(f"\nšŸ“Š BY VESTING TRANCHE:") + for tranche, amount in by_tranche.items(): + print(f" {tranche}: {amount:,} SC") + except FileNotFoundError: - print("šŸ“ No pending SC transactions found") - except Exception as e: - print(f"āŒ Error generating pending SC report: {e}") + print("šŸ“ No pending SC transactions") def main(): - """Generate all reports""" + """Generate comprehensive financial report""" + print("šŸ“ˆ SMARTUP ZERO FINANCIAL REPORTS") print(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print("=" * 50) + # Parse live SC data + total_minted, total_redeemed, transactions = parse_sc_transactions() + sc_outstanding = total_minted - total_redeemed + print("šŸ“Š SMARTUP CREDITS SUMMARY") print("=" * 30) - print("Total SC Minted: 0") - print("Total SC Redeemed: 0") - print("SC Outstanding: 0") - print("šŸ“ No live SC transactions yet") + print(f"Total SC Minted: {total_minted:,}") + print(f"Total SC Redeemed: {total_redeemed:,}") + print(f"SC Outstanding: {sc_outstanding:,}") + + if transactions: + print(f"\nšŸ“ RECENT TRANSACTIONS:") + for tx in transactions[-3:]: # Show last 3 + print(f" {tx['timestamp'][:10]} | {tx['amount']} SC → {tx['to']} | {tx['reference']}") + else: + print("šŸ“ No live SC transactions yet") print() generate_pending_sc_summary() - print("\nšŸ’° TREASURY HEALTH REPORT") - print("=" * 30) - print("šŸ’¶ EUR Treasury: €0.00") - print("šŸŖ™ SC Outstanding: 0 SC") - print("šŸ’ø SC Liability: €0.00") - print("āœ… 3x Rule: COMPLIANT (no live SC outstanding)") + # Parse treasury data + treasury = parse_treasury_balance() - print("\nšŸ“Š FINANCIAL HEALTH: EXCELLENT") - print(" • No current debt or obligations") - print(" • Pending SC awaiting democratic validation") - print(" • Founder compensation tied to collective success") + print("\nšŸ’° TREASURY HEALTH REPORT") + print("=" * 30) + print(f"šŸ’¶ EUR Treasury: €{treasury['total_eur_balance']:.2f}") + print(f"šŸŖ™ SC Outstanding: {treasury['sc_outstanding']:,} SC") + print(f"šŸ’ø SC Liability: €{treasury['sc_liability_eur']:.2f}") + + # Calculate 3x rule compliance + if treasury['total_eur_balance'] == 0: + if treasury['sc_outstanding'] == 0: + print("āœ… 3x Rule: COMPLIANT (no live SC outstanding)") + else: + print("āš ļø 3x Rule: PENDING (SC outstanding but no treasury funding yet)") + else: + ratio = treasury['sc_outstanding'] / (treasury['total_eur_balance'] * 3) + if ratio <= 1: + print(f"āœ… 3x Rule: COMPLIANT ({ratio:.1%} of limit)") + else: + print(f"āŒ 3x Rule: VIOLATION ({ratio:.1%} of limit)") + + # Financial health assessment + print(f"\nšŸ“Š FINANCIAL HEALTH: {'EXCELLENT' if treasury['sc_outstanding'] <= 1000 else 'GOOD' if treasury['sc_outstanding'] <= 10000 else 'NEEDS_FUNDING'}") + if treasury['total_eur_balance'] == 0 and treasury['sc_outstanding'] > 0: + print(" • SC holders earning value through effort-based work") + print(" • Treasury funding needed for SC redemption capability") print("\n" + "=" * 50) print("šŸ’” All ledger data is public and auditable in git history") diff --git a/currency-ledger/scripts/system-check.py b/currency-ledger/scripts/system-check.py index 3a4073d..9d5dcd2 100755 --- a/currency-ledger/scripts/system-check.py +++ b/currency-ledger/scripts/system-check.py @@ -1,54 +1,221 @@ #!/usr/bin/env python3 """ -Comprehensive System Check - Working Version +Comprehensive Smartup Zero System Health Check +Validates complete currency ledger and task management system """ import os import csv import yaml -from datetime import datetime +from pathlib import Path -def check_file_structure(): - """Check all required files exist""" - print("šŸ“ CHECKING FILE STRUCTURE") - print("=" * 30) +class SystemChecker: + def __init__(self): + self.base_path = Path(__file__).parent.parent + self.errors = [] + self.warnings = [] + + def check_file_structure(self): + """Validate complete file structure exists""" + print("šŸ“ CHECKING FILE STRUCTURE") + print("=" * 30) + + required_files = [ + "ledger/smartup-credits/transactions.csv", + "ledger/social-karma/transactions.csv", + "ledger/pending-sc/transactions.csv", + "ledger/treasury/balance.csv", + "ledger/task-management/task-budgets.csv", + "ledger/task-management/session-logs.csv", + "ownership/book-of-owners.csv", + "policies/credit-rates.yml", + "policies/validation-rules.yml", + "policies/task-management/effort-assessment-template.yml", + "policies/task-management/mission-leader-rules.yml" + ] + + for file_path in required_files: + full_path = self.base_path / file_path + if full_path.exists(): + print(f"āœ… {file_path}") + else: + print(f"āŒ {file_path}") + self.errors.append(f"Missing required file: {file_path}") - base_path = os.path.join(os.path.dirname(__file__), '..') - required_files = [ - 'ledger/smartup-credits/transactions.csv', - 'ledger/social-karma/transactions.csv', - 'ledger/treasury/balance.csv', - 'ownership/book-of-owners.csv', - 'policies/credit-rates.yml', - 'scripts/manage-organization.py' - ] + def validate_csv_integrity(self): + """Check CSV files can be parsed and have proper headers""" + print(f"\nšŸ“Š VALIDATING CSV INTEGRITY") + print("=" * 30) + + csv_files = { + "ledger/smartup-credits/transactions.csv": ["timestamp", "type", "amount", "from", "to", "reference"], + "ledger/treasury/balance.csv": ["timestamp", "event_type", "total_eur_balance", "sc_outstanding"], + "ledger/task-management/task-budgets.csv": ["task_id", "total_sc_budget", "attacker_alias", "defender_alias"], + "ownership/book-of-owners.csv": ["owner_id", "display_name", "license_type"] + } + + for file_path, required_headers in csv_files.items(): + full_path = self.base_path / file_path + if full_path.exists(): + try: + with open(full_path, 'r') as f: + reader = csv.DictReader(f) + headers = reader.fieldnames + + missing_headers = [h for h in required_headers if h not in headers] + if missing_headers: + print(f"āš ļø {file_path} - Missing headers: {missing_headers}") + self.warnings.append(f"{file_path} missing headers: {missing_headers}") + else: + print(f"āœ… {file_path}") + + except Exception as e: + print(f"āŒ {file_path} - Parse error: {e}") + self.errors.append(f"CSV parse error in {file_path}: {e}") - all_exist = True - for file_path in required_files: - full_path = os.path.join(base_path, file_path) - if os.path.exists(full_path): - print(f"āœ… {file_path}") + def validate_treasury_balance(self): + """Check 3x rule compliance and balance integrity""" + print(f"\nšŸ’° VALIDATING TREASURY BALANCE") + print("=" * 30) + + try: + # Get latest treasury state + treasury_file = self.base_path / "ledger/treasury/balance.csv" + latest_balance = {"sc_outstanding": 0, "total_eur_balance": 0} + + with open(treasury_file, 'r') as f: + reader = csv.DictReader(f) + for row in reader: + if not row['timestamp'].startswith('#') and row['timestamp']: + latest_balance = { + "sc_outstanding": int(row['sc_outstanding']), + "total_eur_balance": float(row['total_eur_balance']) + } + + # Calculate SC outstanding from transactions + sc_file = self.base_path / "ledger/smartup-credits/transactions.csv" + calculated_outstanding = 0 + + with open(sc_file, 'r') as f: + reader = csv.DictReader(f) + for row in reader: + if not row['timestamp'].startswith('#') and row['timestamp']: + if row['type'] == 'SC': + calculated_outstanding += int(row['amount']) + elif row['type'] in ['REDEEM', 'DESTROY']: + calculated_outstanding -= int(row['amount']) + + print(f"Treasury SC Outstanding: {latest_balance['sc_outstanding']}") + print(f"Calculated SC Outstanding: {calculated_outstanding}") + print(f"EUR Treasury Balance: €{latest_balance['total_eur_balance']}") + + if latest_balance['sc_outstanding'] != calculated_outstanding: + self.errors.append(f"Treasury/SC mismatch: {latest_balance['sc_outstanding']} vs {calculated_outstanding}") + print(f"āŒ Treasury balance mismatch!") + else: + print(f"āœ… Treasury balance consistent") + + # Check 3x rule + if latest_balance['total_eur_balance'] > 0: + ratio = latest_balance['sc_outstanding'] / (latest_balance['total_eur_balance'] * 3) + if ratio <= 1: + print(f"āœ… 3x Rule compliant ({ratio:.1%})") + else: + print(f"āŒ 3x Rule violation ({ratio:.1%})") + self.errors.append(f"3x rule violation: {ratio:.1%}") + else: + if latest_balance['sc_outstanding'] > 0: + print(f"āš ļø 3x Rule: SC outstanding but no treasury funding") + self.warnings.append("SC outstanding without treasury funding") + else: + print(f"āœ… 3x Rule: No SC outstanding, no treasury needed") + + except Exception as e: + print(f"āŒ Treasury validation failed: {e}") + self.errors.append(f"Treasury validation error: {e}") + + def validate_task_system(self): + """Check task-management system integrity""" + print(f"\nšŸŽÆ VALIDATING TASK SYSTEM") + print("=" * 30) + + try: + # Check if task budgets match session logs + budget_file = self.base_path / "ledger/task-management/task-budgets.csv" + session_file = self.base_path / "ledger/task-management/session-logs.csv" + + task_budgets = {} + if budget_file.exists(): + with open(budget_file, 'r') as f: + reader = csv.DictReader(f) + for row in reader: + task_budgets[row['task_id']] = row + + print(f"āœ… {len(task_budgets)} tasks in budget system") + + session_logs = {} + if session_file.exists(): + with open(session_file, 'r') as f: + reader = csv.DictReader(f) + for row in reader: + session_logs[row['task_id']] = row + + print(f"āœ… {len(session_logs)} completed sessions logged") + + # Verify ADM split calculations + for task_id, budget in task_budgets.items(): + total_budget = int(budget['total_sc_budget']) + attacker_sc = int(budget['attacker_sc']) + defender_sc = int(budget['defender_sc']) + + expected_attacker = int(total_budget * 0.9) + expected_defender = int(total_budget * 0.1) + + if attacker_sc != expected_attacker or defender_sc != expected_defender: + print(f"āš ļø {task_id}: ADM split incorrect") + self.warnings.append(f"{task_id} has incorrect ADM split") + else: + print(f"āœ… {task_id}: ADM split correct") + + except Exception as e: + print(f"āŒ Task system validation failed: {e}") + self.errors.append(f"Task system validation error: {e}") + + def run_complete_check(self): + """Run all system checks""" + print("šŸš€ SMARTUP ZERO COMPREHENSIVE SYSTEM CHECK") + print("=" * 50) + + self.check_file_structure() + self.validate_csv_integrity() + self.validate_treasury_balance() + self.validate_task_system() + + print(f"\nšŸ“Š SYSTEM CHECK RESULTS") + print("=" * 30) + + if self.errors: + print(f"āŒ {len(self.errors)} ERRORS FOUND:") + for error in self.errors: + print(f" • {error}") + + if self.warnings: + print(f"āš ļø {len(self.warnings)} WARNINGS:") + for warning in self.warnings: + print(f" • {warning}") + + if not self.errors and not self.warnings: + print("šŸŽ‰ SYSTEM CHECK PASSED!") + print("āœ… All components operational") + print("āœ… Data integrity verified") + print("āœ… Ready for production use") + elif not self.errors: + print("āœ… SYSTEM OPERATIONAL (with warnings)") + print("šŸ’” Address warnings for optimal performance") else: - print(f"āŒ {file_path} - MISSING") - all_exist = False - - return all_exist - -def main(): - """Run system check""" - print("šŸš€ SMARTUP ZERO SYSTEM CHECK") - print("=" * 50) - - files_ok = check_file_structure() - - print("\n" + "=" * 50) - if files_ok: - print("šŸŽ‰ SYSTEM CHECK PASSED!") - print("āœ… All individual script tests working") - print("āœ… Book of Owners shows robbert_founder properly configured") - print("āœ… Ready for founding work audit!") - else: - print("🚨 System check failed") + print("āŒ SYSTEM CHECK FAILED") + print("šŸ”§ Fix errors before production deployment") if __name__ == "__main__": - main() + checker = SystemChecker() + checker.run_complete_check()