MESReport / utils /mes_player_model.py
ChenyuRabbitLove's picture
feat: add mes player model for loading player data from google big query
d4ccbc6
raw
history blame
1.47 kB
from dataclasses import dataclass, field
from typing import List, Dict, Union
from datetime import datetime, date
import pandas as pd
@dataclass
class Player:
player_backend_user_id: str
player_nickname: str = field(default=None)
player_group: int = field(default=None)
partners: List[str] = field(default_factory=list)
badges: List[str] = field(default_factory=list)
rewards_status: Union[str, Dict[str, Dict[str, Union[bool, str]]]] = field(
default_factory=dict
)
adventure_logs: List[str] = field(default_factory=list)
total_active_days: int = field(default=0)
total_gained_scores: int = field(default=0)
total_finished_contents: int = field(default=0)
created_at_date: datetime.date = field(default_factory=date.today)
updated_at_date: datetime.date = field(default_factory=date.today)
def __post_init__(self, available_achievements: List, init: bool):
self.badges = self.badges.tolist()
self.partners = self.partners.tolist()
self.adventure_logs = self.adventure_logs.tolist()
self.assign_weekly_partner()
@staticmethod
def from_series(series: pd.Series) -> "Player":
"""
Creates a Player instance from a pandas Series.
Args:
series (pd.Series): A pandas Series with player attributes.
Returns:
Player: A Player instance.
"""
data = series.copy()
return Player(**data)