Spaces:
Running
Running
from dataclasses import dataclass, field | |
from typing import List, Dict, Union | |
from datetime import datetime, date | |
import pandas as pd | |
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() | |
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) |