[+] rename module folder
1. rename python module folder; 2. clean up payloads/logic.py; 3. update partially payloads/alembic/env.py;
This commit is contained in:
parent
0ee9e87b7f
commit
fe33d5c7f6
83
deps/test-task-2025-07-17-v2/python/online/fxreader/pr34/test_task_2025_07_17_v1/payloads/logic.py
vendored
83
deps/test-task-2025-07-17-v2/python/online/fxreader/pr34/test_task_2025_07_17_v1/payloads/logic.py
vendored
@ -1,83 +0,0 @@
|
||||
import datetime
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker
|
||||
from sqlalchemy.orm import selectinload, make_transient
|
||||
from sqlalchemy.future import select
|
||||
|
||||
from .models import Ticker, Market
|
||||
from .utils import get_or_create
|
||||
|
||||
async def markets_get_by_symbol(
|
||||
session: 'async_sessionmaker[AsyncSession]',
|
||||
symbols: set[str],
|
||||
) -> dict[str, int]:
|
||||
res : dict[str, int] = dict()
|
||||
|
||||
async with session() as active_session:
|
||||
async with active_session.begin() as transaction:
|
||||
for o in symbols:
|
||||
m = (await get_or_create(
|
||||
active_session,
|
||||
Market,
|
||||
name=o,
|
||||
))[0]
|
||||
res[o] = m.id
|
||||
|
||||
return res
|
||||
|
||||
async def ticker_store_multiple(
|
||||
session: 'async_sessionmaker[AsyncSession]',
|
||||
tickers: list[Ticker],
|
||||
) -> None:
|
||||
async with session() as active_session:
|
||||
async with active_session.begin() as transaction:
|
||||
active_session.add_all(
|
||||
tickers,
|
||||
)
|
||||
|
||||
async def tickers_get_by_period(
|
||||
session: 'async_sessionmaker[AsyncSession]',
|
||||
market_id: int,
|
||||
period: datetime.timedelta,
|
||||
) -> list[Ticker]:
|
||||
async with session() as active_session:
|
||||
async with active_session.begin() as transaction:
|
||||
q = select(
|
||||
Ticker
|
||||
).join(Ticker.market).where(
|
||||
Market.id == market_id,
|
||||
Ticker.timestamp >= datetime.datetime.now(
|
||||
tz=datetime.timezone.utc
|
||||
) - period
|
||||
).order_by(Ticker.timestamp.desc()).options(
|
||||
selectinload(Ticker.market)
|
||||
)
|
||||
|
||||
res = await active_session.execute(q)
|
||||
|
||||
rows = [o[0] for o in res]
|
||||
|
||||
for o in rows:
|
||||
active_session.expunge(o)
|
||||
make_transient(o.market)
|
||||
|
||||
return rows
|
||||
|
||||
async def markets_all(
|
||||
session: 'async_sessionmaker[AsyncSession]',
|
||||
) -> list[Market]:
|
||||
async with session() as active_session:
|
||||
async with active_session.begin() as transaction:
|
||||
q = select(
|
||||
Market
|
||||
)
|
||||
|
||||
res = await active_session.execute(q)
|
||||
|
||||
rows = [o[0] for o in res]
|
||||
|
||||
for o in rows:
|
||||
active_session.expunge(o)
|
||||
|
||||
return rows
|
@ -12,10 +12,10 @@ from sqlalchemy.engine.base import Connection
|
||||
|
||||
from alembic import context
|
||||
|
||||
from online.fxreader.pr34.test_task_2025_06_30_v1.tickers.settings import Settings
|
||||
from online.fxreader.pr34.test_task_2025_06_30_v1.tickers.models import (
|
||||
from online.fxreader.pr34.test_task_2025_07_17_v2.payloads.settings import Settings
|
||||
from online.fxreader.pr34.test_task_2025_07_17_v2.payloads.models import (
|
||||
Base,
|
||||
Market,
|
||||
# Market,
|
||||
)
|
||||
|
||||
# this is the Alembic Config object, which provides
|
84
deps/test-task-2025-07-17-v2/python/online/fxreader/pr34/test_task_2025_07_17_v2/payloads/logic.py
vendored
Normal file
84
deps/test-task-2025-07-17-v2/python/online/fxreader/pr34/test_task_2025_07_17_v2/payloads/logic.py
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
import datetime
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker
|
||||
from sqlalchemy.orm import selectinload, make_transient
|
||||
from sqlalchemy.future import select
|
||||
|
||||
from .models import Payload
|
||||
from .utils import get_or_create
|
||||
|
||||
# async def markets_get_by_symbol(
|
||||
# session: 'async_sessionmaker[AsyncSession]',
|
||||
# symbols: set[str],
|
||||
# ) -> dict[str, int]:
|
||||
# res : dict[str, int] = dict()
|
||||
#
|
||||
# async with session() as active_session:
|
||||
# async with active_session.begin() as transaction:
|
||||
# for o in symbols:
|
||||
# m = (await get_or_create(
|
||||
# active_session,
|
||||
# Market,
|
||||
# name=o,
|
||||
# ))[0]
|
||||
# res[o] = m.id
|
||||
#
|
||||
# return res
|
||||
#
|
||||
# async def ticker_store_multiple(
|
||||
# session: 'async_sessionmaker[AsyncSession]',
|
||||
# tickers: list[Ticker],
|
||||
# ) -> None:
|
||||
# async with session() as active_session:
|
||||
# async with active_session.begin() as transaction:
|
||||
# active_session.add_all(
|
||||
# tickers,
|
||||
# )
|
||||
#
|
||||
# async def tickers_get_by_period(
|
||||
# session: 'async_sessionmaker[AsyncSession]',
|
||||
# market_id: int,
|
||||
# period: datetime.timedelta,
|
||||
# ) -> list[Ticker]:
|
||||
# async with session() as active_session:
|
||||
# async with active_session.begin() as transaction:
|
||||
# q = select(
|
||||
# Ticker
|
||||
# ).join(Ticker.market).where(
|
||||
# Market.id == market_id,
|
||||
# Ticker.timestamp >= datetime.datetime.now(
|
||||
# tz=datetime.timezone.utc
|
||||
# ) - period
|
||||
# ).order_by(Ticker.timestamp.desc()).options(
|
||||
# selectinload(Ticker.market)
|
||||
# )
|
||||
#
|
||||
# res = await active_session.execute(q)
|
||||
#
|
||||
# rows = [o[0] for o in res]
|
||||
#
|
||||
# for o in rows:
|
||||
# active_session.expunge(o)
|
||||
# make_transient(o.market)
|
||||
#
|
||||
# return rows
|
||||
#
|
||||
# async def markets_all(
|
||||
# session: 'async_sessionmaker[AsyncSession]',
|
||||
# ) -> list[Market]:
|
||||
# async with session() as active_session:
|
||||
# async with active_session.begin() as transaction:
|
||||
# q = select(
|
||||
# Market
|
||||
# )
|
||||
#
|
||||
# res = await active_session.execute(q)
|
||||
#
|
||||
# rows = [o[0] for o in res]
|
||||
#
|
||||
# for o in rows:
|
||||
# active_session.expunge(o)
|
||||
#
|
||||
# return rows
|
||||
#
|
Loading…
Reference in New Issue
Block a user