Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Jul 9, 2024
1 parent a6168c4 commit 97087b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/api/v2/report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging

from fastapi import APIRouter, Depends, status
Expand All @@ -18,7 +17,12 @@


@router.post("/report", status_code=status.HTTP_201_CREATED, response_model=Ok)
async def post_reports(detections: list[Detection], session=Depends(get_session)):
async def post_reports(
detections: list[Detection],
session=Depends(get_session),
):
global player_cache

report_repo = Report()
player_repo = Player(session=session, cache=player_cache)

Expand All @@ -29,9 +33,7 @@ async def post_reports(detections: list[Detection], session=Depends(get_session)

# get unique list of names
player_names = list(set([d.reported for d in data] + [d.reporter for d in data]))
players = await asyncio.gather(
*[player_repo.get_or_insert(player_name=p) for p in player_names]
)
players = [await player_repo.get_or_insert(player_name=p) for p in player_names]
players = {p.name: p.id for p in players}

_data = []
Expand Down
18 changes: 8 additions & 10 deletions src/app/repositories/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ async def get_report_score(self, player_names: tuple[str]):
func.coalesce(sub_query_alias.c.manual_detect, 0).label("manual_detect"),
)

async with self.session:
result: AsyncResult = await self.session.execute(sql)
await self.session.commit()
result: AsyncResult = await self.session.execute(sql)
await self.session.commit()
return tuple(result.mappings())

async def get_feedback_score(self, player_names: list[str]):
Expand All @@ -95,24 +94,24 @@ async def get_feedback_score(self, player_names: list[str]):
fb_subject.confirmed_player,
)

async with self.session:
result: AsyncResult = await self.session.execute(query)
await self.session.commit()
result: AsyncResult = await self.session.execute(query)
await self.session.commit()
return tuple(result.mappings())

async def get_prediction(self, player_names: list[str]):
query: Select = select(dbPrediction)
query = query.select_from(dbPrediction)
query = query.where(dbPrediction.name.in_(player_names))
async with self.session:
result: AsyncResult = await self.session.execute(query)
result = result.scalars().all()

result: AsyncResult = await self.session.execute(query)
result = result.scalars().all()
return jsonable_encoder(result)

async def get(self, player_name: str) -> PlayerInDB:
player_name = self.sanitize_name(player_name)

sql = sqla.select(dbPlayer).where(dbPlayer.name == player_name)

result = await self.session.execute(sql)
data = result.scalars().all()

Expand All @@ -131,7 +130,6 @@ async def get_cache(self, player_name: str) -> PlayerInDB:

if isinstance(player, PlayerInDB):
await self.cache.put(key=player_name, value=player)

return player

async def insert(self, player: PlayerCreate) -> PlayerInDB:
Expand Down

0 comments on commit 97087b2

Please sign in to comment.