2022-10-21 11:34:49 +00:00
|
|
|
import datetime
|
|
|
|
from enum import Enum
|
2023-03-14 01:27:22 +00:00
|
|
|
from typing import Any, Dict, List, Union
|
2022-10-21 11:34:49 +00:00
|
|
|
|
2024-12-01 09:22:34 +00:00
|
|
|
from pydantic import field_validator
|
|
|
|
|
|
|
|
from simnet.models.base import APIModel as BaseModel, DateTimeField, add_timezone
|
2022-10-21 11:34:49 +00:00
|
|
|
|
2024-07-05 14:10:36 +00:00
|
|
|
from metadata.shortname import not_real_roles, roleToId, weaponToId, buddyToId
|
|
|
|
from modules.gacha_log.const import ZZZGF_VERSION
|
2022-10-21 11:34:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ImportType(Enum):
|
2023-03-31 06:01:03 +00:00
|
|
|
PaiGram = "PaiGram"
|
2024-07-05 14:10:36 +00:00
|
|
|
ZZZGF = "ZZZGF"
|
2022-10-21 11:34:49 +00:00
|
|
|
UNKNOWN = "UNKNOWN"
|
|
|
|
|
|
|
|
|
|
|
|
class FiveStarItem(BaseModel):
|
|
|
|
name: str
|
|
|
|
icon: str
|
|
|
|
count: int
|
|
|
|
type: str
|
|
|
|
isUp: bool
|
|
|
|
isBig: bool
|
2024-12-01 09:22:34 +00:00
|
|
|
time: DateTimeField
|
2022-10-21 11:34:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FourStarItem(BaseModel):
|
|
|
|
name: str
|
|
|
|
icon: str
|
|
|
|
count: int
|
|
|
|
type: str
|
2024-12-01 09:22:34 +00:00
|
|
|
time: DateTimeField
|
2022-10-21 11:34:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GachaItem(BaseModel):
|
|
|
|
id: str
|
|
|
|
name: str
|
2024-07-05 14:10:36 +00:00
|
|
|
gacha_id: str = ""
|
2022-10-21 11:34:49 +00:00
|
|
|
gacha_type: str
|
2024-07-05 14:10:36 +00:00
|
|
|
item_id: str = ""
|
2022-10-21 11:34:49 +00:00
|
|
|
item_type: str
|
|
|
|
rank_type: str
|
2024-12-01 09:22:34 +00:00
|
|
|
time: DateTimeField
|
2022-10-21 11:34:49 +00:00
|
|
|
|
2024-11-30 14:11:02 +00:00
|
|
|
@field_validator("name")
|
|
|
|
@classmethod
|
2022-10-21 11:34:49 +00:00
|
|
|
def name_validator(cls, v):
|
2024-07-05 14:10:36 +00:00
|
|
|
if item_id := (roleToId(v) or weaponToId(v) or buddyToId(v)):
|
2022-10-21 11:34:49 +00:00
|
|
|
if item_id not in not_real_roles:
|
|
|
|
return v
|
2023-07-18 09:29:31 +00:00
|
|
|
raise ValueError(f"Invalid name {v}")
|
2022-10-21 11:34:49 +00:00
|
|
|
|
2024-11-30 14:11:02 +00:00
|
|
|
@field_validator("gacha_type")
|
|
|
|
@classmethod
|
2022-10-21 11:34:49 +00:00
|
|
|
def check_gacha_type(cls, v):
|
2024-07-05 14:10:36 +00:00
|
|
|
if v not in {"1", "2", "3", "5"}:
|
|
|
|
raise ValueError(f"gacha_type must be 1, 2, 3 or 5, invalid value: {v}")
|
2022-10-21 11:34:49 +00:00
|
|
|
return v
|
|
|
|
|
2024-11-30 14:11:02 +00:00
|
|
|
@field_validator("item_type")
|
|
|
|
@classmethod
|
2022-10-21 11:34:49 +00:00
|
|
|
def check_item_type(cls, item):
|
2024-07-05 14:10:36 +00:00
|
|
|
if item not in {"代理人", "音擎", "邦布"}:
|
2023-07-18 09:29:31 +00:00
|
|
|
raise ValueError(f"error item type {item}")
|
2022-10-21 11:34:49 +00:00
|
|
|
return item
|
|
|
|
|
2024-11-30 14:11:02 +00:00
|
|
|
@field_validator("rank_type")
|
|
|
|
@classmethod
|
2022-10-21 11:34:49 +00:00
|
|
|
def check_rank_type(cls, rank):
|
|
|
|
if rank not in {"5", "4", "3"}:
|
2023-07-18 09:29:31 +00:00
|
|
|
raise ValueError(f"error rank type {rank}")
|
2022-10-21 11:34:49 +00:00
|
|
|
return rank
|
|
|
|
|
|
|
|
|
|
|
|
class GachaLogInfo(BaseModel):
|
|
|
|
user_id: str
|
|
|
|
uid: str
|
2024-12-01 09:22:34 +00:00
|
|
|
update_time: DateTimeField
|
2022-10-21 11:34:49 +00:00
|
|
|
import_type: str = ""
|
|
|
|
item_list: Dict[str, List[GachaItem]] = {
|
2024-07-05 14:10:36 +00:00
|
|
|
"代理人调频": [],
|
|
|
|
"音擎调频": [],
|
|
|
|
"常驻调频": [],
|
|
|
|
"邦布调频": [],
|
2022-10-21 11:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def get_import_type(self) -> ImportType:
|
|
|
|
try:
|
|
|
|
return ImportType(self.import_type)
|
|
|
|
except ValueError:
|
|
|
|
return ImportType.UNKNOWN
|
|
|
|
|
|
|
|
|
|
|
|
class Pool:
|
|
|
|
def __init__(self, five: List[str], four: List[str], name: str, to: str, **kwargs):
|
|
|
|
self.five = five
|
|
|
|
self.real_name = name
|
|
|
|
self.name = "、".join(self.five)
|
|
|
|
self.four = four
|
|
|
|
self.from_ = kwargs.get("from")
|
|
|
|
self.to = to
|
2024-12-01 09:22:34 +00:00
|
|
|
self.from_time = add_timezone(datetime.datetime.strptime(self.from_, "%Y-%m-%d %H:%M:%S"))
|
|
|
|
self.to_time = add_timezone(datetime.datetime.strptime(self.to, "%Y-%m-%d %H:%M:%S"))
|
2022-10-21 11:34:49 +00:00
|
|
|
self.start = self.from_time
|
|
|
|
self.start_init = False
|
|
|
|
self.end = self.to_time
|
|
|
|
self.dict = {}
|
|
|
|
self.count = 0
|
|
|
|
|
|
|
|
def parse(self, item: Union[FiveStarItem, FourStarItem]):
|
|
|
|
if self.from_time <= item.time <= self.to_time:
|
|
|
|
if self.dict.get(item.name):
|
|
|
|
self.dict[item.name]["count"] += 1
|
|
|
|
else:
|
|
|
|
self.dict[item.name] = {
|
|
|
|
"name": item.name,
|
|
|
|
"icon": item.icon,
|
|
|
|
"count": 1,
|
|
|
|
"rank_type": 5 if isinstance(item, FiveStarItem) else 4,
|
|
|
|
}
|
|
|
|
|
|
|
|
def count_item(self, item: List[GachaItem]):
|
|
|
|
for i in item:
|
|
|
|
if self.from_time <= i.time <= self.to_time:
|
|
|
|
self.count += 1
|
|
|
|
if not self.start_init:
|
|
|
|
self.start = i.time
|
2022-10-29 07:39:06 +00:00
|
|
|
self.start_init = True
|
2022-10-21 11:34:49 +00:00
|
|
|
self.end = i.time
|
|
|
|
|
|
|
|
def to_list(self):
|
|
|
|
return list(self.dict.values())
|
|
|
|
|
|
|
|
|
|
|
|
class ItemType(Enum):
|
2024-07-05 14:10:36 +00:00
|
|
|
CHARACTER = "代理人"
|
|
|
|
WEAPON = "音擎"
|
|
|
|
BANGBOO = "邦布"
|
2022-10-21 11:34:49 +00:00
|
|
|
|
|
|
|
|
2024-07-05 14:10:36 +00:00
|
|
|
class ZZZGFGachaType(Enum):
|
|
|
|
STANDARD = "1"
|
|
|
|
CHARACTER = "2"
|
|
|
|
WEAPON = "3"
|
|
|
|
BANGBOO = "5"
|
2022-10-21 11:34:49 +00:00
|
|
|
|
|
|
|
|
2024-07-05 14:10:36 +00:00
|
|
|
class ZZZGFItem(BaseModel):
|
2022-10-21 11:34:49 +00:00
|
|
|
id: str
|
|
|
|
name: str
|
|
|
|
count: str = "1"
|
2024-07-05 14:10:36 +00:00
|
|
|
gacha_id: str = ""
|
|
|
|
gacha_type: ZZZGFGachaType
|
2022-10-21 11:34:49 +00:00
|
|
|
item_id: str = ""
|
|
|
|
item_type: ItemType
|
|
|
|
rank_type: str
|
|
|
|
time: str
|
|
|
|
|
|
|
|
|
2024-07-05 14:10:36 +00:00
|
|
|
class ZZZGFInfo(BaseModel):
|
2022-10-21 11:34:49 +00:00
|
|
|
uid: str = "0"
|
|
|
|
lang: str = "zh-cn"
|
2024-07-05 14:10:36 +00:00
|
|
|
region_time_zone: int = 8
|
2022-10-21 11:34:49 +00:00
|
|
|
export_time: str = ""
|
|
|
|
export_timestamp: int = 0
|
|
|
|
export_app: str = ""
|
|
|
|
export_app_version: str = ""
|
2024-07-05 14:10:36 +00:00
|
|
|
zzzgf_version: str = ZZZGF_VERSION
|
2022-10-21 11:34:49 +00:00
|
|
|
|
|
|
|
def __init__(self, **data: Any):
|
|
|
|
super().__init__(**data)
|
|
|
|
if not self.export_time:
|
|
|
|
self.export_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
self.export_timestamp = int(datetime.datetime.now().timestamp())
|
|
|
|
|
|
|
|
|
2024-07-05 14:10:36 +00:00
|
|
|
class ZZZGFModel(BaseModel):
|
|
|
|
info: ZZZGFInfo
|
|
|
|
list: List[ZZZGFItem]
|