This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move apps stats from postgresql view to spark job
- Loading branch information
Showing
20 changed files
with
427 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from fastapi import APIRouter | ||
|
||
from .entire_market import router as entire_market_router | ||
from .market_item import router as market_item_router | ||
from .game import router as game_router | ||
|
||
router = APIRouter() | ||
router.include_router(entire_market_router) | ||
router.include_router(market_item_router) | ||
router.include_router(game_router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Literal | ||
|
||
from dependency_injector.wiring import inject, Provide | ||
from fastapi import Depends, APIRouter | ||
|
||
from steam_trade_bot.api.models.market_item import EntireMarketStatsResponse | ||
from steam_trade_bot.containers import Container | ||
from steam_trade_bot.domain.interfaces.unit_of_work import IUnitOfWork | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/get_entire_market_stats/", response_model=EntireMarketStatsResponse) | ||
@inject | ||
async def get_entire_market_stats( | ||
mode: Literal["monthly", "weekly", "daily"] = "daily", | ||
count: int | None = None, | ||
offset: int | None = None, | ||
uow: IUnitOfWork = Depends(Provide[Container.repositories.unit_of_work]), | ||
): | ||
async with uow: | ||
stats = await uow.entire_market_daily_stats.get_all(mode=mode, count=count, offset=offset) | ||
return EntireMarketStatsResponse( | ||
total_volume=round(sum(x.volume for x in stats), 2), | ||
total_volume_no_fee=round(sum(x.volume_no_fee for x in stats), 2), | ||
total_volume_game_fee=round(sum(x.volume_game_fee for x in stats), 2), | ||
total_volume_steam_fee=round(sum(x.volume_steam_fee for x in stats), 2), | ||
total_quantity=round(sum(x.quantity for x in stats), 2), | ||
items=stats | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from dependency_injector.wiring import inject, Provide | ||
from fastapi import Depends, APIRouter | ||
|
||
from steam_trade_bot.api.models.market_item import GamesListResponse | ||
from steam_trade_bot.containers import Container | ||
from steam_trade_bot.domain.entities.game import GameStatsResponse | ||
from steam_trade_bot.domain.interfaces.unit_of_work import IUnitOfWork | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/get_games/", response_model=GamesListResponse) | ||
@inject | ||
async def get_games( | ||
count: int = 100, | ||
offset: int = 0, | ||
uow: IUnitOfWork = Depends(Provide[Container.repositories.unit_of_work]), | ||
): | ||
async with uow: | ||
games = await uow.game.get_all( | ||
count=count, | ||
offset=offset, | ||
) | ||
return GamesListResponse( | ||
count=len(games), | ||
offset=offset, | ||
items=games, | ||
) | ||
|
||
|
||
@router.get("/get_apps_stats/", response_model=list[GameStatsResponse]) | ||
@inject | ||
async def get_apps_stats( | ||
count: int | None = None, | ||
offset: int | None = None, | ||
uow: IUnitOfWork = Depends(Provide[Container.repositories.unit_of_work]), | ||
): | ||
async with uow: | ||
stats = await uow.app_stats.get_all( | ||
count=count, | ||
offset=offset | ||
) | ||
|
||
return stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import dataclasses | ||
import json | ||
|
||
from dependency_injector.wiring import inject, Provide | ||
from fastapi import Depends, APIRouter | ||
|
||
from steam_trade_bot.api.models.market_item import MarketItemsListResponse, MarketItemResponse, MarketItemSellHistoryResponse | ||
from steam_trade_bot.containers import Container | ||
from steam_trade_bot.domain.entities.market import MarketItem, MarketItemOrders | ||
from steam_trade_bot.domain.interfaces.unit_of_work import IUnitOfWork | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/get_market_items/", response_model=MarketItemsListResponse) | ||
@inject | ||
async def get_market_items( | ||
app_id: int = 730, | ||
count: int = 100, | ||
offset: int = 0, | ||
uow: IUnitOfWork = Depends(Provide[Container.repositories.unit_of_work]), | ||
): | ||
async with uow: | ||
items = await uow.market_item.get_all( | ||
app_id=app_id, | ||
count=count, | ||
offset=offset, | ||
) | ||
return MarketItemsListResponse( | ||
count=len(items), | ||
offset=offset, | ||
items=[MarketItemResponse(**item.dict()) for item in items], | ||
) | ||
|
||
|
||
@router.get("/get_market_item/", response_model=MarketItem) | ||
@inject | ||
async def get_market_item( | ||
app_id: int = 730, | ||
market_hash_name: str = "Sticker | Skull Lil Boney", | ||
uow: IUnitOfWork = Depends(Provide[Container.repositories.unit_of_work]), | ||
): | ||
async with uow: | ||
item = await uow.market_item.get( | ||
app_id=app_id, | ||
market_hash_name=market_hash_name, | ||
) | ||
return item | ||
|
||
|
||
@router.get("/get_market_item_orders/", response_model=MarketItemOrders) | ||
@inject | ||
async def get_market_item_orders( | ||
app_id: int = 730, | ||
market_hash_name: str = "Sticker | Skull Lil Boney", | ||
uow: IUnitOfWork = Depends(Provide[Container.repositories.unit_of_work]), | ||
): | ||
async with uow: | ||
item = await uow.market_item_orders.get( | ||
app_id=app_id, | ||
market_hash_name=market_hash_name, | ||
) | ||
return item | ||
|
||
|
||
@router.get("/get_item_sell_history/", response_model=MarketItemSellHistoryResponse) | ||
@inject | ||
async def get_item_sell_history( | ||
app_id: int = 730, | ||
market_hash_name: str = "Sticker | Skull Lil Boney", | ||
uow: IUnitOfWork = Depends(Provide[Container.repositories.unit_of_work]), | ||
): | ||
async with uow: | ||
history = await uow.sell_history.get( | ||
app_id=app_id, | ||
market_hash_name=market_hash_name, | ||
) | ||
stats = await uow.sell_history_stats.get( | ||
app_id=app_id, | ||
market_hash_name=market_hash_name | ||
) | ||
|
||
return MarketItemSellHistoryResponse( | ||
app_id=history.app_id, | ||
market_hash_name=history.market_hash_name, | ||
timestamp=history.timestamp, | ||
total_sold=stats.total_sold, | ||
total_volume=stats.total_volume, | ||
total_volume_approx_fee=round(float(stats.total_volume) * 0.13, 2), | ||
first_sale_datetime=stats.first_sale_timestamp, | ||
last_sale_datetime=stats.last_sale_timestamp, | ||
history=json.loads(history.history), | ||
) |
Oops, something went wrong.