Rework
This commit is contained in:
parent
ce5abcc217
commit
cfe4a641a6
40 changed files with 1728 additions and 1445 deletions
0
src/geoguessr_mcp/services/__init__.py
Normal file
0
src/geoguessr_mcp/services/__init__.py
Normal file
30
src/geoguessr_mcp/services/analysis_service.py
Normal file
30
src/geoguessr_mcp/services/analysis_service.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"""Analysis and statistics calculations."""
|
||||
|
||||
from typing import List
|
||||
|
||||
from ..models.game import Game
|
||||
|
||||
|
||||
class AnalysisService:
|
||||
"""Service for analyzing game data."""
|
||||
|
||||
@staticmethod
|
||||
def calculate_statistics(games: List[Game]) -> dict:
|
||||
"""Calculate aggregate statistics from games."""
|
||||
if not games:
|
||||
return {"games_analyzed": 0, "total_score": 0, "average_score": 0, "perfect_rounds": 0}
|
||||
|
||||
total_score = sum(g.total_score for g in games)
|
||||
total_rounds = sum(len(g.rounds) for g in games)
|
||||
perfect_rounds = sum(1 for g in games for r in g.rounds if r.score == 5000)
|
||||
|
||||
return {
|
||||
"games_analyzed": len(games),
|
||||
"total_score": total_score,
|
||||
"average_score": total_score / len(games),
|
||||
"total_rounds": total_rounds,
|
||||
"perfect_rounds": perfect_rounds,
|
||||
"perfect_round_percentage": (
|
||||
(perfect_rounds / total_rounds * 100) if total_rounds > 0 else 0
|
||||
),
|
||||
}
|
||||
0
src/geoguessr_mcp/services/competitive_service.py
Normal file
0
src/geoguessr_mcp/services/competitive_service.py
Normal file
0
src/geoguessr_mcp/services/game_service.py
Normal file
0
src/geoguessr_mcp/services/game_service.py
Normal file
136
src/geoguessr_mcp/services/profile_service.py
Normal file
136
src/geoguessr_mcp/services/profile_service.py
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
"""
|
||||
Profile-related business logic.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
from ..api.client import GeoguessrClient
|
||||
from ..api.endpoints import Endpoints
|
||||
from ..models.profile import UserProfile, UserStats
|
||||
|
||||
|
||||
class ProfileService:
|
||||
"""Service for profile operations."""
|
||||
|
||||
def __init__(self, client: GeoguessrClient):
|
||||
"""
|
||||
Initialize the profile service.
|
||||
|
||||
Args:
|
||||
client: GeoGuessr API client
|
||||
"""
|
||||
self.client = client
|
||||
|
||||
async def get_profile(
|
||||
self,
|
||||
session_token: Optional[str] = None
|
||||
) -> UserProfile:
|
||||
"""
|
||||
Get user profile.
|
||||
|
||||
Args:
|
||||
session_token: Optional session token for authentication
|
||||
|
||||
Returns:
|
||||
UserProfile with user information
|
||||
|
||||
Raises:
|
||||
httpx.HTTPError: If the API request fails
|
||||
"""
|
||||
response = await self.client.get(
|
||||
Endpoints.PROFILES.GET_PROFILE,
|
||||
session_token
|
||||
)
|
||||
data = response.json()
|
||||
return UserProfile.from_api_response(data)
|
||||
|
||||
async def get_stats(
|
||||
self,
|
||||
session_token: Optional[str] = None
|
||||
) -> UserStats:
|
||||
"""
|
||||
Get user statistics.
|
||||
|
||||
Args:
|
||||
session_token: Optional session token for authentication
|
||||
|
||||
Returns:
|
||||
UserStats with user statistics
|
||||
|
||||
Raises:
|
||||
httpx.HTTPError: If the API request fails
|
||||
"""
|
||||
response = await self.client.get(
|
||||
Endpoints.PROFILES.GET_STATS,
|
||||
session_token
|
||||
)
|
||||
data = response.json()
|
||||
return UserStats.from_api_response(data)
|
||||
|
||||
async def get_extended_stats(
|
||||
self,
|
||||
session_token: Optional[str] = None
|
||||
) -> dict:
|
||||
"""
|
||||
Get extended user statistics.
|
||||
|
||||
Args:
|
||||
session_token: Optional session token for authentication
|
||||
|
||||
Returns:
|
||||
Dictionary with extended statistics
|
||||
|
||||
Raises:
|
||||
httpx.HTTPError: If the API request fails
|
||||
"""
|
||||
response = await self.client.get(
|
||||
Endpoints.PROFILES.GET_EXTENDED_STATS,
|
||||
session_token
|
||||
)
|
||||
return response.json()
|
||||
|
||||
async def get_achievements(
|
||||
self,
|
||||
session_token: Optional[str] = None
|
||||
) -> list:
|
||||
"""
|
||||
Get user achievements.
|
||||
|
||||
Args:
|
||||
session_token: Optional session token for authentication
|
||||
|
||||
Returns:
|
||||
List of achievement dictionaries
|
||||
|
||||
Raises:
|
||||
httpx.HTTPError: If the API request fails
|
||||
"""
|
||||
response = await self.client.get(
|
||||
Endpoints.PROFILES.GET_ACHIEVEMENTS,
|
||||
session_token
|
||||
)
|
||||
return response.json()
|
||||
|
||||
async def get_public_profile(
|
||||
self,
|
||||
user_id: str,
|
||||
session_token: Optional[str] = None
|
||||
) -> UserProfile:
|
||||
"""
|
||||
Get public profile of another user.
|
||||
|
||||
Args:
|
||||
user_id: User ID to fetch
|
||||
session_token: Optional session token for authentication
|
||||
|
||||
Returns:
|
||||
UserProfile with public user information
|
||||
|
||||
Raises:
|
||||
httpx.HTTPError: If the API request fails
|
||||
"""
|
||||
response = await self.client.get(
|
||||
Endpoints.PROFILES.get_public_profile(user_id),
|
||||
session_token
|
||||
)
|
||||
data = response.json()
|
||||
return UserProfile.from_api_response(data)
|
||||
Loading…
Add table
Add a link
Reference in a new issue