Update glory simulator

This commit is contained in:
Eden Kirin
2025-10-23 14:53:58 +02:00
parent 9d0557f96d
commit 7e51e74f6d

View File

@ -143,14 +143,16 @@ class GlorySimulator:
if cmd == "GT": if cmd == "GT":
# Get batch total # Get batch total
# If no counts, generate random simulation data # For simulator: reset and generate new counts for each GT request
# if not self.batch_counts and self.motor_has_run: # This simulates a fresh batch counting session
if True: logger.info("GT received - resetting batch and simulating new count")
self._simulate_counting() self.batch_counts = {}
self._simulate_counting()
total = sum(self.batch_counts.values()) total = sum(self.batch_counts.values())
response = f"BT{total:08d}" response = f"BT{total:08d}"
logger.info(f"Get batch total: {total} coins") logger.info(f"Get batch total: {total} coins")
return self.create_message(response) return self.create_message(response)
elif cmd == "GS": elif cmd == "GS":
@ -225,10 +227,11 @@ class GlorySimulator:
cmd = data.decode("ascii", errors="ignore").strip() cmd = data.decode("ascii", errors="ignore").strip()
if cmd == "MG": if cmd == "MG":
# Start motor # Start motor - reset batch counts for new counting session
self.motor_running = True self.motor_running = True
self.motor_has_run = True self.motor_has_run = True
logger.info("Motor started") self.batch_counts = {} # Reset batch for new counting session
logger.info("Motor started - batch counts reset")
# Simulate coin counting # Simulate coin counting
self._simulate_counting() self._simulate_counting()
elif cmd == "MS": elif cmd == "MS":
@ -318,28 +321,28 @@ class GlorySimulator:
"""Simulate coin counting when motor runs""" """Simulate coin counting when motor runs"""
# Generate random counts for simulation # Generate random counts for simulation
# Standard denominations with realistic count distributions # Standard denominations with realistic count distributions
# All ranges start at 1 to ensure non-zero counts
denominations = { denominations = {
"001": (20, 150), # Pennies - high count "001": (20, 150), # Pennies - high count
"005": (10, 100), # Nickels "005": (10, 100), # Nickels
"010": (10, 80), # Dimes "010": (10, 80), # Dimes
"025": (5, 60), # Quarters "025": (5, 60), # Quarters
"050": (0, 20), # Half dollars - rare "050": (1, 20), # Half dollars - rare (changed from 0)
"100": (0, 10), # Dollar coins - rare "100": (1, 10), # Dollar coins - rare (changed from 0)
} }
for denom, (min_count, max_count) in denominations.items(): for denom, (min_count, max_count) in denominations.items():
count = random.randint(min_count, max_count) count = random.randint(min_count, max_count)
if count > 0: # Update batch counts
# Update batch counts self.batch_counts[denom] = self.batch_counts.get(denom, 0) + count
self.batch_counts[denom] = self.batch_counts.get(denom, 0) + count # Update partial counts
# Update partial counts self.partial_counts[denom] = self.partial_counts.get(denom, 0) + count
self.partial_counts[denom] = self.partial_counts.get(denom, 0) + count # Update subtotal
# Update subtotal self.sub_counts[denom] = self.sub_counts.get(denom, 0) + count
self.sub_counts[denom] = self.sub_counts.get(denom, 0) + count # Update grand total
# Update grand total self.grand_counts[denom] = self.grand_counts.get(denom, 0) + count
self.grand_counts[denom] = self.grand_counts.get(denom, 0) + count
logger.info(f"Counted {count} coins of denomination {denom}") logger.info(f"Counted {count} coins of denomination {denom}")
# Log total value counted # Log total value counted
total_value = sum( total_value = sum(