🐛 Fix pay log count error

This commit is contained in:
xtaodada 2023-01-07 18:48:53 +08:00
parent d377c4c241
commit 834dd30b7e
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 14 additions and 18 deletions

View File

@ -4,7 +4,7 @@ POOL_301 = [
"four": ["罗莎莉亚", "早柚", "九条裟罗"], "four": ["罗莎莉亚", "早柚", "九条裟罗"],
"from": "2022-12-27 18:00:00", "from": "2022-12-27 18:00:00",
"name": "影寂天下人|苍流踏花", "name": "影寂天下人|苍流踏花",
"to": "2022-01-17 18:00:00", "to": "2023-01-17 18:00:00",
}, },
{ {
"five": ["流浪者", "荒泷一斗"], "five": ["流浪者", "荒泷一斗"],

View File

@ -4,7 +4,7 @@ POOL_302 = [
"four": ["恶王丸", "曚云之月", "匣里龙吟", "西风长枪", "祭礼残章"], "four": ["恶王丸", "曚云之月", "匣里龙吟", "西风长枪", "祭礼残章"],
"from": "2022-12-27 18:00:00", "from": "2022-12-27 18:00:00",
"name": "神铸赋形", "name": "神铸赋形",
"to": "2022-01-17 18:00:00", "to": "2023-01-17 18:00:00",
}, },
{ {
"five": ["图莱杜拉的回忆", "赤角石溃杵"], "five": ["图莱杜拉的回忆", "赤角石溃杵"],

View File

@ -140,14 +140,13 @@ class PayLog:
return new_num return new_num
@staticmethod @staticmethod
async def get_month_data(pay_log: PayLogModel, price_data: List[Dict]) -> Tuple[int, int, List[Dict]]: async def get_month_data(pay_log: PayLogModel, price_data: List[Dict]) -> Tuple[int, List[Dict]]:
"""获取月份数据 """获取月份数据
:param pay_log: 日志数据 :param pay_log: 日志数据
:param price_data: 商品数据 :param price_data: 商品数据
:return: 月份数据 :return: 月份数据
""" """
all_amount: int = 0 all_amount: int = 0
all_pay: int = 0
months: List[int] = [] months: List[int] = []
month_datas: List[Dict] = [] month_datas: List[Dict] = []
last_month: Optional[Dict] = None last_month: Optional[Dict] = None
@ -156,7 +155,6 @@ class PayLog:
if i.amount <= 0: if i.amount <= 0:
continue continue
all_amount += i.amount all_amount += i.amount
all_pay += i.amount
if i.time.month not in months: if i.time.month not in months:
months.append(i.time.month) months.append(i.time.month)
if last_month: if last_month:
@ -173,9 +171,6 @@ class PayLog:
for j in price_data: for j in price_data:
if i.amount in j["price"]: if i.amount in j["price"]:
j["count"] += 1 j["count"] += 1
j["amount"] += i.amount
if i.amount == price_data[0]["price"][0]:
all_amount -= i.amount
break break
month_data.append(i) month_data.append(i)
if last_month: if last_month:
@ -184,7 +179,7 @@ class PayLog:
if not month_datas: if not month_datas:
raise PayLogNotFound raise PayLogNotFound
month_datas.sort(key=lambda k: k["amount"], reverse=True) month_datas.sort(key=lambda k: k["amount"], reverse=True)
return all_amount, all_pay, month_datas return all_amount, month_datas
async def get_analysis(self, user_id: int, client: Client): async def get_analysis(self, user_id: int, client: Client):
"""获取分析数据 """获取分析数据
@ -200,14 +195,15 @@ class PayLog:
{ {
"price": price, "price": price,
"count": 0, "count": 0,
"amount": 0,
} }
for price in [[680], [300], [8080, 12960], [3880, 6560], [2240, 3960], [1090, 1960], [330, 600], [60, 120]] for price in [[680], [300], [8080, 12960], [3880, 6560], [2240, 3960], [1090, 1960], [330, 600], [60, 120]]
] ]
price_data_name = ["大月卡", "小月卡", "648", "328", "198", "98", "30", "6"] price_data_name = ["大月卡", "小月卡", "648", "328", "198", "98", "30", "6"]
all_pay, all_amount, month_datas = await PayLog.get_month_data(pay_log, price_data) real_price = [68, 30, 648, 328, 198, 98, 30, 6]
all_amount, month_datas = await PayLog.get_month_data(pay_log, price_data)
all_pay = sum((price_data[i]["count"] * real_price[i]) for i in range(len(price_data)))
datas = [ datas = [
{"value": f"{all_pay / 10:.0f}", "name": "总消费"}, {"value": f"{all_pay:.0f}", "name": "总消费"},
{"value": all_amount, "name": "总结晶"}, {"value": all_amount, "name": "总结晶"},
{"value": f"{month_datas[0]['month']}", "name": "消费最多"}, {"value": f"{month_datas[0]['month']}", "name": "消费最多"},
{ {
@ -224,7 +220,7 @@ class PayLog:
] ]
pie_datas = [ pie_datas = [
{ {
"value": f"{price_data[i]['amount'] / 10:.0f}", "value": f"{price_data[i]['count'] * real_price[i]:.0f}",
"name": f"{price_data_name[i]}", "name": f"{price_data_name[i]}",
} }
for i in range(len(price_data)) for i in range(len(price_data))

View File

@ -50,9 +50,9 @@ class PayLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
logger.debug("尝试获取已绑定的原神账号") logger.debug("尝试获取已绑定的原神账号")
client = await get_genshin_client(user.id, need_cookie=False) client = await get_genshin_client(user.id, need_cookie=False)
new_num = await self.pay_log.get_log_data(user.id, client, authkey) new_num = await self.pay_log.get_log_data(user.id, client, authkey)
return "更新完成,本次没有新增数据" if new_num == 0 else f"更新完成,本次共新增{new_num}抽卡记录" return "更新完成,本次没有新增数据" if new_num == 0 else f"更新完成,本次共新增{new_num}充值记录"
except PayLogNotFound: except PayLogNotFound:
return "派蒙没有找到你的充值记录,快去氪金吧~" return "派蒙没有找到你的充值记录,快去充值吧~"
except PayLogAccountNotFound: except PayLogAccountNotFound:
return "导入失败,可能文件包含的祈愿记录所属 uid 与你当前绑定的 uid 不同" return "导入失败,可能文件包含的祈愿记录所属 uid 与你当前绑定的 uid 不同"
except PayLogInvalidAuthkey: except PayLogInvalidAuthkey:
@ -192,12 +192,12 @@ class PayLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
client = await get_genshin_client(cid, need_cookie=False) client = await get_genshin_client(cid, need_cookie=False)
_, status = await self.pay_log.load_history_info(str(cid), str(client.uid), only_status=True) _, status = await self.pay_log.load_history_info(str(cid), str(client.uid), only_status=True)
if not status: if not status:
await message.reply_text("该用户还没有导入抽卡记录") await message.reply_text("该用户还没有导入充值记录")
return return
status = await self.pay_log.remove_history_info(str(cid), str(client.uid)) status = await self.pay_log.remove_history_info(str(cid), str(client.uid))
await message.reply_text("抽卡记录已强制删除" if status else "抽卡记录删除失败") await message.reply_text("充值记录已强制删除" if status else "充值记录删除失败")
except PayLogNotFound: except PayLogNotFound:
await message.reply_text("该用户还没有导入抽卡记录") await message.reply_text("该用户还没有导入充值记录")
except UserNotFoundError: except UserNotFoundError:
await message.reply_text("该用户暂未绑定账号") await message.reply_text("该用户暂未绑定账号")
except (ValueError, IndexError): except (ValueError, IndexError):