Files
g0v0-server/app/calculators/performance/_base.py
MingxuanGame 2c81e22749 feat(calculator): support generate PerformanceAttributes & DifficultyAttributes from JSON Schema (#59)
Prepare for custom rulesets.

Schema Genetator: https://github.com/GooGuTeam/custom-rulesets/tree/main/CustomRulesetMetadataGenerator

```bash
dotnet -- schemas path/to/rulesets -o schema.json
```

```bash
python scripts/generate_ruleset_attributes.py schema.json 
```
2025-10-25 19:10:53 +08:00

38 lines
1.0 KiB
Python

import abc
from typing import TYPE_CHECKING
from app.models.mods import APIMod
from app.models.performance import DifficultyAttributes, PerformanceAttributes
from app.models.score import GameMode
if TYPE_CHECKING:
from app.database.score import Score
class CalculateError(Exception):
"""An error occurred during performance calculation."""
class DifficultyError(CalculateError):
"""The difficulty could not be calculated."""
class ConvertError(DifficultyError):
"""A beatmap cannot be converted to the specified game mode."""
class PerformanceError(CalculateError):
"""The performance could not be calculated."""
class PerformanceCalculator(abc.ABC):
@abc.abstractmethod
async def calculate_performance(self, beatmap_raw: str, score: "Score") -> PerformanceAttributes:
raise NotImplementedError
@abc.abstractmethod
async def calculate_difficulty(
self, beatmap_raw: str, mods: list[APIMod] | None = None, gamemode: GameMode | None = None
) -> DifficultyAttributes:
raise NotImplementedError