first commit
Some checks failed
Deploy / lint (push) Failing after 7s
Deploy / test (push) Has been skipped
Deploy / deploy (push) Has been skipped

This commit is contained in:
Dennis Thiessen
2026-02-20 17:31:01 +01:00
commit 61ab24490d
160 changed files with 17034 additions and 0 deletions

46
app/routers/sentiment.py Normal file
View File

@@ -0,0 +1,46 @@
"""Sentiment router — sentiment data endpoints."""
from fastapi import APIRouter, Depends, Query
from sqlalchemy.ext.asyncio import AsyncSession
from app.dependencies import get_db, require_access
from app.schemas.common import APIEnvelope
from app.schemas.sentiment import SentimentResponse, SentimentScoreResult
from app.services.sentiment_service import (
compute_sentiment_dimension_score,
get_sentiment_scores,
)
router = APIRouter(tags=["sentiment"])
@router.get("/sentiment/{symbol}", response_model=APIEnvelope)
async def read_sentiment(
symbol: str,
lookback_hours: float = Query(24, gt=0, description="Lookback window in hours"),
_user=Depends(require_access),
db: AsyncSession = Depends(get_db),
) -> APIEnvelope:
"""Get recent sentiment scores and computed dimension score for a symbol."""
scores = await get_sentiment_scores(db, symbol, lookback_hours)
dimension_score = await compute_sentiment_dimension_score(
db, symbol, lookback_hours
)
data = SentimentResponse(
symbol=symbol.strip().upper(),
scores=[
SentimentScoreResult(
id=s.id,
classification=s.classification,
confidence=s.confidence,
source=s.source,
timestamp=s.timestamp,
)
for s in scores
],
count=len(scores),
dimension_score=round(dimension_score, 2) if dimension_score is not None else None,
lookback_hours=lookback_hours,
)
return APIEnvelope(status="success", data=data.model_dump())