From 7e51e74f6d351fc87fb1edb004737fb0322ed078 Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Thu, 23 Oct 2025 14:53:58 +0200 Subject: [PATCH] Update glory simulator --- source/glory.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/source/glory.py b/source/glory.py index e4ead8f..fc4d000 100644 --- a/source/glory.py +++ b/source/glory.py @@ -143,14 +143,16 @@ class GlorySimulator: if cmd == "GT": # Get batch total - # If no counts, generate random simulation data - # if not self.batch_counts and self.motor_has_run: - if True: - self._simulate_counting() + # For simulator: reset and generate new counts for each GT request + # This simulates a fresh batch counting session + logger.info("GT received - resetting batch and simulating new count") + self.batch_counts = {} + self._simulate_counting() total = sum(self.batch_counts.values()) response = f"BT{total:08d}" logger.info(f"Get batch total: {total} coins") + return self.create_message(response) elif cmd == "GS": @@ -225,10 +227,11 @@ class GlorySimulator: cmd = data.decode("ascii", errors="ignore").strip() if cmd == "MG": - # Start motor + # Start motor - reset batch counts for new counting session self.motor_running = 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 self._simulate_counting() elif cmd == "MS": @@ -318,28 +321,28 @@ class GlorySimulator: """Simulate coin counting when motor runs""" # Generate random counts for simulation # Standard denominations with realistic count distributions + # All ranges start at 1 to ensure non-zero counts denominations = { "001": (20, 150), # Pennies - high count "005": (10, 100), # Nickels "010": (10, 80), # Dimes "025": (5, 60), # Quarters - "050": (0, 20), # Half dollars - rare - "100": (0, 10), # Dollar coins - rare + "050": (1, 20), # Half dollars - rare (changed from 0) + "100": (1, 10), # Dollar coins - rare (changed from 0) } for denom, (min_count, max_count) in denominations.items(): count = random.randint(min_count, max_count) - if count > 0: - # Update batch counts - self.batch_counts[denom] = self.batch_counts.get(denom, 0) + count - # Update partial counts - self.partial_counts[denom] = self.partial_counts.get(denom, 0) + count - # Update subtotal - self.sub_counts[denom] = self.sub_counts.get(denom, 0) + count - # Update grand total - self.grand_counts[denom] = self.grand_counts.get(denom, 0) + count + # Update batch counts + self.batch_counts[denom] = self.batch_counts.get(denom, 0) + count + # Update partial counts + self.partial_counts[denom] = self.partial_counts.get(denom, 0) + count + # Update subtotal + self.sub_counts[denom] = self.sub_counts.get(denom, 0) + count + # Update grand total + 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 total_value = sum(