fv
import random import time from datetime import datetime from collections import Counter # Simulierte Länderliste countries = ["USA", "Russia", "Germany", "China", "Brazil", "India", "UK", "France"] # Gewichtung für USA und Russland (höhere Wahrscheinlichkeit) weights = [0.3, 0.3, 0.05, 0.05, 0.05, 0.05, 0.1, 0.1] # Zähler für Besucher visitor_log = [] def simulate_visitor(): # Zufälliges Land basierend auf Gewichtung country = random.choices(countries, weights=weights, k=1)[0] timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") visitor = {"country": country, "timestamp": timestamp} visitor_log.append(visitor) return visitor def generate_traffic(target_visitors=500, duration=60): print(f"Starte Simulation für {target_visitors} Besucher in {duration} Sekunden...") start_time = time.time() visitors_per_second = target_visitors / duration while len(visitor_log) < target_visitors and (time.time() - start_time) < duration: simulate_visitor() print(f"Besucher #{len(visitor_log)} aus {visitor_log[-1]['country']} um {visitor_log[-1]['timestamp']}") # Kurze Pause, um die Simulation realistisch zu halten time.sleep(1 / visitors_per_second) # Zusammenfassung country_counts = Counter(visitor["country"] for visitor in visitor_log) print("\nZusammenfassung der Besucher:") for country, count in country_counts.items(): print(f"{country}: {count} Besucher") print(f"Total: {len(visitor_log)} Besucher") if __name__ == "__main__": try: generate_traffic(target_visitors=500, duration=60) except KeyboardInterrupt: print("\nSimulation abgebrochen.") country_counts = Counter(visitor["country"] for visitor in visitor_log) print("\nZusammenfassung der Besucher:") for country, count in country_counts.items(): print(f"{country}: {count} Besucher") print(f"Total: {len(visitor_log)} Besucher")
Kommentare
Kommentar veröffentlichen