Merge branch 'main' into feat/open-meteo

This commit is contained in:
skkim committed 2026-10-12 14:43:39 +09:00
commit aa05d870a2
80 files changed
+4893 -351

No files matched your search

+5 -5
View File
@@ -9,13 +9,13 @@ from common.database.model.models import Post
class FeedCRUD:
async def day(self, s: AsyncSession, day: date) -> list[Post]:
stmt = select(Post).where(Post.feed_date == day, Post.deleted.is_(False)).order_by(Post.position)
async def day(self, s: AsyncSession, day: date, scopes: list[str]) -> list[Post]:
stmt = select(Post).where(Post.feed_date == day, Post.scope.in_(scopes), Post.deleted.is_(False)).order_by(Post.position, Post.scope)
return list((await s.scalars(stmt)).all())
async def positions(self, s: AsyncSession, day: date) -> set[int]:
"""그날 이미 만든 카드 번호. 지운 카드도 넣어 다시 만들지 않게 한다."""
return set((await s.scalars(select(Post.position).where(Post.feed_date == day))).all())
async def positions(self, s: AsyncSession, day: date) -> set[tuple[str, int]]:
"""그날 이미 만든 (scope, 카드 번호). 지운 카드도 넣어 다시 만들지 않게 한다."""
return {(scope, pos) for scope, pos in (await s.execute(select(Post.scope, Post.position).where(Post.feed_date == day))).all()}
async def insert_day(self, s: AsyncSession, rows: list[dict]) -> None:
if rows:
+8 -1
View File
@@ -1,6 +1,6 @@
from datetime import date
from sqlalchemy import func, select
from sqlalchemy import func, select, text
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.ext.asyncio import AsyncSession
@@ -34,6 +34,13 @@ class IndexCRUD:
stmt = select(func.min(IndexScore.computed_at)).where(IndexScore.region_code == region_code, IndexScore.score_date == day)
return await s.scalar(stmt)
async def has_unslotted(self, s: AsyncSession, region_code: str, day: date) -> bool:
"""그날 행 중 구간 점수가 비어 있는 행(구간 계산 전 행)이 있는지."""
stmt = select(IndexScore.index_id).where(
IndexScore.region_code == region_code, IndexScore.score_date == day, text("index_score.slots = '{}'::jsonb")
).limit(1)
return (await s.scalar(stmt)) is not None
async def upsert_scores(self, s: AsyncSession, rows: list[dict]) -> None:
if not rows:
return
+8 -4
View File
@@ -26,14 +26,18 @@ class WeekCRUD:
if rows:
await s.execute(insert(Holiday).values(rows).on_conflict_do_nothing(index_elements=["holiday_date", "name"]))
async def places(self, s: AsyncSession, sido_code: str) -> list[Place]:
stmt = select(Place).where(Place.region_code.startswith(sido_code)).order_by(Place.sort_order)
async def places_in_box(self, s: AsyncSession, lat: float, lon: float, dlat: float, dlon: float) -> list[Place]:
stmt = select(Place).where(Place.lat.between(lat - dlat, lat + dlat), Place.lon.between(lon - dlon, lon + dlon))
return list((await s.scalars(stmt)).all())
async def all_places(self, s: AsyncSession) -> list[Place]:
return list((await s.scalars(select(Place).where(Place.lat.is_not(None)))).all())
async def replace_places(self, s: AsyncSession, rows: list[dict]) -> None:
await s.execute(delete(Place))
if rows:
await s.execute(insert(Place).values(rows))
# asyncpg 는 한 문장에 인자 32767개까지라 나눠 넣는다.
for i in range(0, len(rows), 1000):
await s.execute(insert(Place).values(rows[i:i + 1000]))
async def events(self, s: AsyncSession, sido_codes: list[str], since: date, until: date) -> list[Event]:
stmt = select(Event).where(Event.sido_code.in_(sido_codes), Event.end_date >= since, Event.start_date <= until)