85 lines
2.1 KiB
Python
85 lines
2.1 KiB
Python
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class StationBase(BaseModel):
|
|
station_hash: str
|
|
operator: str
|
|
station_name: str
|
|
address: Optional[str]
|
|
coord_x: Optional[float]
|
|
coord_y: Optional[float]
|
|
current_price: Optional[float]
|
|
|
|
|
|
class CompetitorStation(BaseModel):
|
|
station_hash: str
|
|
operator: str
|
|
station_name: str
|
|
distance_km: float
|
|
current_price: Optional[float]
|
|
|
|
|
|
class GeoCompetitionResponse(BaseModel):
|
|
base_station: StationBase
|
|
competitors: List[CompetitorStation]
|
|
ylt_price: Optional[float]
|
|
min_competitor_price: Optional[float]
|
|
max_competitor_price: Optional[float]
|
|
cheaper_count: int
|
|
same_count: int
|
|
more_expensive_count: int
|
|
|
|
|
|
class GeoCompetitionSummary(BaseModel):
|
|
summary: str
|
|
|
|
|
|
class PriceSeries(BaseModel):
|
|
operator: str
|
|
series: List[Optional[float]]
|
|
|
|
|
|
class PriceComparisonResponse(BaseModel):
|
|
hours: List[int]
|
|
ylt: PriceSeries
|
|
competitors: List[PriceSeries]
|
|
min_diff: Optional[float]
|
|
max_diff: Optional[float]
|
|
avg_diff: Optional[float]
|
|
|
|
|
|
class PriceComparisonSummary(BaseModel):
|
|
summary: str
|
|
|
|
|
|
from DbKit.Db import Db
|
|
|
|
class YltAnalyticsModel:
|
|
def __init__(self):
|
|
self.db = Db()
|
|
|
|
async def get_operators_price_trends(self, days: int):
|
|
return await self.db.find("YltAnalytics.getOperatorsPriceTrends", {"days": days})
|
|
|
|
async def list_ylt_stations(self, q: str = None):
|
|
params = {}
|
|
if q:
|
|
params["q"] = True
|
|
params["kw"] = f"%{q}%"
|
|
return await self.db.find("YltAnalytics.listYltStations", params)
|
|
|
|
async def fetch_current_stations(self):
|
|
return await self.db.find("YltAnalytics.fetchCurrentStations")
|
|
|
|
async def fetch_station_schedule_json(self, station_hash: str):
|
|
rows = await self.db.find("YltAnalytics.fetchStationScheduleJson", {"h": station_hash})
|
|
if not rows:
|
|
return None
|
|
return rows[0].get("schedule_json")
|
|
|
|
async def fetch_current_station_rows(self, operator: str):
|
|
return await self.db.find("YltAnalytics.fetchCurrentStationRows", {"op": operator})
|
|
|