76 lines
3.4 KiB
Python
76 lines
3.4 KiB
Python
"""
|
|
Pydantic schemas for user_predictions.
|
|
|
|
This module defines request and response schemas for user prediction tracking operations.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import Optional, Any
|
|
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
|
|
class UserPredictionBase(BaseModel):
|
|
"""Base schema for user prediction data."""
|
|
user_id: int = Field(..., description="Foreign key to users table")
|
|
prediction_id: int = Field(..., description="Foreign key to predictions table")
|
|
viewed_at: datetime = Field(..., description="Timestamp when user viewed prediction")
|
|
was_correct: Optional[bool] = Field(None, description="True if prediction was correct, False if incorrect, NULL if match not completed")
|
|
|
|
|
|
class UserPredictionCreate(UserPredictionBase):
|
|
"""Schema for creating a new user prediction record."""
|
|
pass
|
|
|
|
|
|
class UserPredictionUpdate(BaseModel):
|
|
"""Schema for updating a user prediction record."""
|
|
was_correct: Optional[bool] = Field(None, description="Update whether prediction was correct")
|
|
|
|
|
|
class PredictionMatchInfo(BaseModel):
|
|
"""Schema for match information included in user prediction response."""
|
|
id: int = Field(..., description="Match ID")
|
|
home_team: str = Field(..., description="Home team name")
|
|
away_team: str = Field(..., description="Away team name")
|
|
date: datetime = Field(..., description="Match date and time")
|
|
league: str = Field(..., description="League name")
|
|
status: str = Field(..., description="Match status")
|
|
actual_winner: Optional[str] = Field(None, description="Actual winner when match is completed")
|
|
|
|
|
|
class PredictionInfo(BaseModel):
|
|
"""Schema for prediction information included in user prediction response."""
|
|
id: int = Field(..., description="Prediction ID")
|
|
match_id: int = Field(..., description="Match ID")
|
|
energy_score: str = Field(..., description="Energy score")
|
|
confidence: str = Field(..., description="Confidence level")
|
|
predicted_winner: str = Field(..., description="Predicted winner")
|
|
created_at: datetime = Field(..., description="Prediction creation time")
|
|
|
|
|
|
class UserPredictionResponse(BaseModel):
|
|
"""Schema for user prediction response with full details."""
|
|
id: int = Field(..., description="Primary key")
|
|
user_id: int = Field(..., description="User ID")
|
|
prediction_id: int = Field(..., description="Prediction ID")
|
|
viewed_at: datetime = Field(..., description="When user viewed prediction")
|
|
was_correct: Optional[bool] = Field(None, description="True if prediction was correct")
|
|
prediction: PredictionInfo = Field(..., description="Full prediction details")
|
|
model_config = ConfigDict(from_attributes=False)
|
|
|
|
|
|
class UserPredictionListResponse(BaseModel):
|
|
"""Schema for a list of user predictions with metadata."""
|
|
data: list[UserPredictionResponse] = Field(..., description="List of user predictions")
|
|
meta: dict = Field(..., description="Metadata including totals")
|
|
|
|
|
|
class UserStatsResponse(BaseModel):
|
|
"""Schema for user statistics."""
|
|
total_predictions_viewed: int = Field(..., description="Total number of predictions viewed by user")
|
|
correct_predictions: int = Field(..., description="Number of correct predictions")
|
|
incorrect_predictions: int = Field(..., description="Number of incorrect predictions")
|
|
accuracy_rate: float = Field(..., description="Accuracy rate as percentage (0-100)")
|
|
roi: float = Field(..., description="Return on Investment in EUR")
|