From a74ca853000116b91e636d84df0892462d19c97b Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Thu, 24 Apr 2025 23:56:19 -0400 Subject: [PATCH] allnet: fix playhistory --- core/allnet.py | 15 +++++---------- core/data/schema/arcade.py | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/core/allnet.py b/core/allnet.py index cd349f7..b062541 100644 --- a/core/allnet.py +++ b/core/allnet.py @@ -611,12 +611,13 @@ class BillingServlet: "playlimit": req.playlimit, "messages": [] } + playhist = "000000/0:000000/0:000000/0" if machine is not None: if self.config.allnet.save_billing: - lastcredit = await self.data.arcade.billing_get_credit(machine['id'], req.gameid) + lastcredit = await self.data.arcade.billing_get_last_playcount(machine['id'], req.gameid) if lastcredit is not None: - last_playct = lastcredit['playcount'] + last_playct = lastcredit['playct'] else: last_playct = 0 @@ -630,14 +631,8 @@ class BillingServlet: if plays is not None and len(plays) > 0: playhist = "" - for x in range(len(plays), 0, -1): playhist += f"{plays[x]['year']:04d}{plays[x]['month']:02d}/{plays[x]['playct']}:" + for x in range(len(plays) - 1, -1, -1): playhist += f"{plays[x]['year']:04d}{plays[x]['month']:02d}/{plays[x]['playct']}:" playhist = playhist[:-1] - - else: - playhist = "000000/0:000000/0:000000/0" - - else: - playhist = "000000/0:000000/0:000000/0" for x in range(1, len(req_dict)): if not req_dict[x]: @@ -693,7 +688,7 @@ class BillingServlet: ) self.logger.info( - f"Credit Trace from {req.keychipid}: {tmp.operation_type} mode, {tmp.credit_rate} coins per credit, Consumed {tmp.credit0} | {tmp.credit1} | {tmp.credit2} | {tmp.credit3} | {tmp.credit4} | {tmp.credit5} | {tmp.credit6} | {tmp.credit7} | " + f"Credit Trace from {req.keychipid}: {tmp.operation_type} mode, {tmp.credit_rate} coins per credit, breakdown: {tmp.credit0} | {tmp.credit1} | {tmp.credit2} | {tmp.credit3} | {tmp.credit4} | {tmp.credit5} | {tmp.credit6} | {tmp.credit7} | " ) except KeyError as e: diff --git a/core/data/schema/arcade.py b/core/data/schema/arcade.py index 2053f62..d1790b8 100644 --- a/core/data/schema/arcade.py +++ b/core/data/schema/arcade.py @@ -426,13 +426,20 @@ class ArcadeData(BaseData): product_code=product_code, product_count=product_count, func_type=func_type, - player_num=player_num + player_number=player_num )) if result is None: self.logger.error(f"Failed to add billing charge for machine {machine_id}!") return None return result.lastrowid + + async def billing_get_last_charge(self, machine_id: int, game_id: str) -> Optional[Row]: + result = await self.execute(billing_charge.select( + and_(billing_charge.c.machine == machine_id, billing_charge.c.game_id == game_id) + ).order_by(billing_charge.c.id.desc()).limit(3)) + if result: + return result.fetchone() async def billing_set_credit(self, machine_id: int, game_id: str, chute_type: int, service_type: int, op_mode: int, coin_rate0: int, coin_rate1: int, bonus_adder: int, coin_to_credit_rate: int, coin_count_slot0: int, coin_count_slot1: int, coin_count_slot2: int, coin_count_slot3: int, @@ -483,7 +490,9 @@ class ArcadeData(BaseData): return result.lastrowid async def billing_get_credit(self, machine_id: int, game_id: str) -> Optional[Row]: - result = await self.execute(billing_credit.select(billing_credit.c.machine == machine_id)) + result = await self.execute(billing_credit.select( + and_(billing_credit.c.machine == machine_id, billing_credit.c.game_id == game_id) + )) if result: return result.fetchone() @@ -512,6 +521,15 @@ class ArcadeData(BaseData): if result is not None: return result.fetchall() + async def billing_get_last_playcount(self, machine_id: int, game_id: str) -> Optional[Row]: + result = await self.execute(billing_playct.select(and_( + billing_playct.c.machine == machine_id, + billing_playct.c.game_id == game_id + )).order_by(billing_playct.c.year.desc(), billing_playct.c.month.desc()).limit(1)) + + if result is not None: + return result.fetchone() + def format_serial( self, platform_code: str, platform_rev: int, serial_letter: str, serial_num: int, append: int, dash: bool = False ) -> str: