Fix glory simulator

This commit is contained in:
Eden Kirin
2025-10-24 09:50:34 +02:00
parent 7e51e74f6d
commit 54157a8c16

View File

@ -142,31 +142,41 @@ class GlorySimulator:
cmd = data.decode("ascii", errors="ignore").strip() cmd = data.decode("ascii", errors="ignore").strip()
if cmd == "GT": if cmd == "GT":
# Get batch total # Get batch total (monetary value)
# For simulator: reset and generate new counts for each GT request # For simulator: reset and generate new counts for each GT request
# This simulates a fresh batch counting session # This simulates a fresh batch counting session
logger.info("GT received - resetting batch and simulating new count") logger.info("GT received - resetting batch and simulating new count")
self.batch_counts = {} self.batch_counts = {}
self._simulate_counting() self._simulate_counting()
total = sum(self.batch_counts.values()) # Calculate total monetary value (sum of count × denomination for all coins)
response = f"BT{total:08d}" total_value = sum(
logger.info(f"Get batch total: {total} coins") count * int(denom)
for denom, count in self.batch_counts.items()
)
response = f"BT{total_value:08d}"
logger.info(f"Get batch total: ${total_value/100:.2f}")
return self.create_message(response) return self.create_message(response)
elif cmd == "GS": elif cmd == "GS":
# Get subtotal # Get subtotal (monetary value)
total = sum(self.sub_counts.values()) total_value = sum(
response = f"BS{total:08d}" count * int(denom)
logger.info(f"Get subtotal: {total} coins") for denom, count in self.sub_counts.items()
)
response = f"BS{total_value:08d}"
logger.info(f"Get subtotal: ${total_value/100:.2f}")
return self.create_message(response) return self.create_message(response)
elif cmd == "GG": elif cmd == "GG":
# Get grand total # Get grand total (monetary value)
total = sum(self.grand_counts.values()) total_value = sum(
response = f"BG{total:08d}" count * int(denom)
logger.info(f"Get grand total: {total} coins") for denom, count in self.grand_counts.items()
)
response = f"BG{total_value:08d}"
logger.info(f"Get grand total: ${total_value/100:.2f}")
return self.create_message(response) return self.create_message(response)
elif cmd.startswith("GD"): elif cmd.startswith("GD"):
@ -178,11 +188,14 @@ class GlorySimulator:
return self.create_message(response) return self.create_message(response)
elif cmd.startswith("GT") and len(cmd) > 2: elif cmd.startswith("GT") and len(cmd) > 2:
# Get batch counts of denomination # Get batch value of denomination (monetary value, not count)
denom_str = cmd[2:] denom_str = cmd[2:]
count = self.batch_counts.get(denom_str, 0) count = self.batch_counts.get(denom_str, 0)
response = f"BT{count:08d}" # Calculate monetary value: count × denomination (in cents)
logger.info(f"Get batch count for {denom_str}: {count} coins") denom_value = int(denom_str) # e.g., "001" = 1 cent, "025" = 25 cents
monetary_value = count * denom_value
response = f"BT{monetary_value:08d}"
logger.info(f"Get batch value for {denom_str}: {count} coins × ${denom_value/100:.2f} = ${monetary_value/100:.2f}")
return self.create_message(response) return self.create_message(response)
elif cmd == "GI": elif cmd == "GI":
@ -255,26 +268,35 @@ class GlorySimulator:
cmd = data.decode("ascii", errors="ignore").strip() cmd = data.decode("ascii", errors="ignore").strip()
if cmd == "AB" or cmd == "Ab": if cmd == "AB" or cmd == "Ab":
# Accept batch # Accept batch (monetary value)
total = sum(self.batch_counts.values()) total_value = sum(
response = f"BT{total:08d}" count * int(denom)
logger.info(f"Accept batch: {total}") for denom, count in self.batch_counts.items()
)
response = f"BT{total_value:08d}"
logger.info(f"Accept batch: ${total_value/100:.2f}")
self.pending_message = response self.pending_message = response
return self.create_message(response) return self.create_message(response)
elif cmd == "AS" or cmd == "As": elif cmd == "AS" or cmd == "As":
# Accept subtotal # Accept subtotal (monetary value)
total = sum(self.sub_counts.values()) total_value = sum(
response = f"BS{total:08d}" count * int(denom)
logger.info(f"Accept subtotal: {total}") for denom, count in self.sub_counts.items()
)
response = f"BS{total_value:08d}"
logger.info(f"Accept subtotal: ${total_value/100:.2f}")
self.pending_message = response self.pending_message = response
return self.create_message(response) return self.create_message(response)
elif cmd == "AG" or cmd == "Ag": elif cmd == "AG" or cmd == "Ag":
# Accept grand total # Accept grand total (monetary value)
total = sum(self.grand_counts.values()) total_value = sum(
response = f"BG{total:08d}" count * int(denom)
logger.info(f"Accept grand total: {total}") for denom, count in self.grand_counts.items()
)
response = f"BG{total_value:08d}"
logger.info(f"Accept grand total: ${total_value/100:.2f}")
self.pending_message = response self.pending_message = response
return self.create_message(response) return self.create_message(response)