#!/usr/bin/env python3 """ Eurojackpot CSV Processor Dieses Script liest zwei CSV-Dateien ein: 1. Alle möglichen Zahlenkombinationen (5 Zahlen) 2. Bereits gezogene Zahlen mit Datumsstempel Es markiert in der ersten Datei alle bereits gezogenen Kombinationen mit 1 (sonst 0). """ import pandas as pd import sys from pathlib import Path def load_combinations_file(filepath): """Lädt die Datei mit allen möglichen Kombinationen.""" try: df = pd.read_csv(filepath) print(f"Kombinationen geladen: {len(df)} Zeilen") print(f"Spalten: {list(df.columns)}") return df except Exception as e: print(f"Fehler beim Laden der Kombinationsdatei: {e}") return None def load_drawn_numbers_file(filepath): """Lädt die Datei mit bereits gezogenen Zahlen.""" try: df = pd.read_csv(filepath) print(f"Gezogene Zahlen geladen: {len(df)} Zeilen") print(f"Spalten: {list(df.columns)}") return df except Exception as e: print(f"Fehler beim Laden der gezogenen Zahlen: {e}") return None def create_combination_key(row, z_columns): """Erstellt einen eindeutigen Schlüssel aus den 5 Zahlen (sortiert).""" numbers = [row[col] for col in z_columns] return tuple(sorted(numbers)) def process_eurojackpot_data(combinations_file, drawn_numbers_file, output_file): """Hauptfunktion zur Verarbeitung der Eurojackpot-Daten.""" # CSV-Dateien laden print("Lade Kombinationsdatei...") combinations_df = load_combinations_file(combinations_file) if combinations_df is None: return False print("\nLade Datei mit gezogenen Zahlen...") drawn_df = load_drawn_numbers_file(drawn_numbers_file) if drawn_df is None: return False # Spalten für Zahlen identifizieren # Annahme: In der Kombinationsdatei sind die ersten 5 Spalten die Zahlen # In der gezogenen Zahlen-Datei sind es Z1, Z2, Z3, Z4, Z5 # Für Kombinationsdatei - erste 5 numerische Spalten verwenden numeric_cols = combinations_df.select_dtypes(include=['number']).columns if len(numeric_cols) >= 5: combo_z_columns = numeric_cols[:5].tolist() else: # Fallback: erste 5 Spalten nehmen combo_z_columns = combinations_df.columns[:5].tolist() print(f"Verwendete Spalten für Kombinationen: {combo_z_columns}") # Für gezogene Zahlen - Z1 bis Z5 Spalten suchen z_columns = [col for col in drawn_df.columns if col.startswith('Z') and col[1:].isdigit()] z_columns = sorted(z_columns)[:5] # Ersten 5 Z-Spalten nehmen if not z_columns: # Fallback: nach Spalten mit "Zahl" im Namen suchen oder numerische Spalten z_columns = [col for col in drawn_df.columns if 'zahl' in col.lower()][:5] if not z_columns: z_columns = drawn_df.select_dtypes(include=['number']).columns[:5].tolist() print(f"Verwendete Spalten für gezogene Zahlen: {z_columns}") # Set mit allen gezogenen Kombinationen erstellen print("\nErstelle Set mit gezogenen Kombinationen...") drawn_combinations = set() for _, row in drawn_df.iterrows(): combo_key = create_combination_key(row, z_columns) drawn_combinations.add(combo_key) print(f"Anzahl eindeutige gezogene Kombinationen: {len(drawn_combinations)}") # Neue Spalte für Markierungen hinzufügen print("\nMarkiere gezogene Kombinationen...") combinations_df['bereits_gezogen'] = 0 marked_count = 0 for idx, row in combinations_df.iterrows(): combo_key = create_combination_key(row, combo_z_columns) if combo_key in drawn_combinations: combinations_df.at[idx, 'bereits_gezogen'] = 1 marked_count += 1 print(f"Anzahl markierte Kombinationen: {marked_count}") # Ergebnis speichern print(f"\nSpeichere Ergebnis in: {output_file}") combinations_df.to_csv(output_file, index=False) # Statistiken ausgeben total_combinations = len(combinations_df) drawn_percentage = (marked_count / total_combinations) * 100 if total_combinations > 0 else 0 print(f"\n=== STATISTIKEN ===") print(f"Gesamte Kombinationen: {total_combinations:,}") print(f"Bereits gezogene Kombinationen: {marked_count:,}") print(f"Prozentsatz bereits gezogen: {drawn_percentage:.4f}%") print(f"Noch nicht gezogene Kombinationen: {total_combinations - marked_count:,}") return True def main(): """Hauptfunktion mit Benutzerinteraktion.""" print("=== Eurojackpot CSV Processor ===\n") # Dateipfade abfragen oder Standard verwenden if len(sys.argv) >= 4: combinations_file = sys.argv[1] drawn_numbers_file = sys.argv[2] output_file = sys.argv[3] else: print("Geben Sie die Dateipfade ein (oder drücken Sie Enter für Standard):") combinations_file = input("Pfad zur Kombinationsdatei (alle_kombinationen.csv): ").strip() if not combinations_file: combinations_file = "alle_kombinationen.csv" drawn_numbers_file = input("Pfad zur Datei mit gezogenen Zahlen (gezogene_zahlen.csv): ").strip() if not drawn_numbers_file: drawn_numbers_file = "gezogene_zahlen.csv" output_file = input("Pfad für Ausgabedatei (kombinationen_markiert.csv): ").strip() if not output_file: output_file = "kombinationen_markiert.csv" # Überprüfen ob Dateien existieren if not Path(combinations_file).exists(): print(f"Fehler: Kombinationsdatei '{combinations_file}' nicht gefunden!") return if not Path(drawn_numbers_file).exists(): print(f"Fehler: Datei mit gezogenen Zahlen '{drawn_numbers_file}' nicht gefunden!") return # Verarbeitung starten success = process_eurojackpot_data(combinations_file, drawn_numbers_file, output_file) if success: print(f"\n✅ Verarbeitung erfolgreich abgeschlossen!") print(f"Ergebnis gespeichert in: {output_file}") else: print("\n❌ Fehler bei der Verarbeitung!") if __name__ == "__main__": main()