-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test case and model change * define route for post * wip daily * min size vs min value * cleanup anon user * stuck, daily * lower case labels * checkpoint * checkpoint, add player working * working valdiator for feedback input * Update foreign key references in Feedback model * cleanup of ok debug returns * checkpoint working post of feedback! * working code, need to fix tests * minor fix * better but not perfect * bug fix * change to self.assertions * add anon users to players, 10 * self.asserts and worked on post feedback valid anon * Refactor test_post_feedback_valid_anon method to generate random data * remove duplicate players and subjects * remove duplicate players * remove print * revert * valid player names from reports * Refactor player API tests * use and_ and first() * rename class to TestReportAPI * cleanup debug ouput * improve logging * remove unneccesary and * hardcoded anonymous users * improve report --------- Co-authored-by: extreme4all <>
- Loading branch information
1 parent
66b2583
commit bd99cd8
Showing
19 changed files
with
466 additions
and
286 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
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from fastapi import APIRouter | ||
|
||
from . import player, report | ||
from . import feedback, player, report | ||
|
||
router = APIRouter() | ||
router.include_router(player.router) | ||
router.include_router(report.router) | ||
router.include_router(feedback.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,28 @@ | ||
import logging | ||
|
||
from fastapi import APIRouter, Depends, HTTPException, status | ||
|
||
from src.app.models.feedback import Feedback | ||
from src.app.views.input.feedback import FeedbackInput | ||
from src.app.views.response.ok import Ok | ||
from src.core.fastapi.dependencies.session import get_session | ||
from src.core.fastapi.dependencies.to_jagex_name import to_jagex_name | ||
|
||
router = APIRouter(tags=["Feedback"]) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@router.post("/feedback", response_model=Ok, status_code=status.HTTP_201_CREATED) | ||
async def post_feedback( | ||
feedback: FeedbackInput, | ||
session=Depends(get_session), | ||
): | ||
""" """ | ||
_feedback = Feedback(session) | ||
|
||
feedback.player_name = await to_jagex_name(feedback.player_name) | ||
|
||
success, detail = await _feedback.insert_feedback(feedback=feedback) | ||
if not success: | ||
raise HTTPException(status_code=422, detail=detail) | ||
return Ok() |
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,70 @@ | ||
import logging | ||
import time | ||
|
||
from fastapi.encoders import jsonable_encoder | ||
from sqlalchemy import and_, func, insert, select | ||
from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession | ||
from sqlalchemy.sql.expression import Insert, Select | ||
|
||
from src.app.views.input.feedback import FeedbackInput | ||
from src.core.database.models.feedback import PredictionFeedback as dbFeedback | ||
from src.core.database.models.player import Player as dbPlayer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Feedback: | ||
def __init__(self, session: AsyncSession) -> None: | ||
self.session = session | ||
|
||
async def insert_feedback(self, feedback: FeedbackInput) -> tuple[bool, str]: | ||
sql_select: Select = select(dbPlayer.id) | ||
sql_select = sql_select.where(dbPlayer.name == feedback.player_name) | ||
|
||
sql_dupe_check: Select = select(dbFeedback) | ||
sql_dupe_check = sql_dupe_check.where( | ||
and_( | ||
dbFeedback.prediction == feedback.prediction, | ||
dbFeedback.subject_id == feedback.subject_id, | ||
) | ||
) | ||
|
||
sql_insert: Insert = insert(dbFeedback) | ||
data = { | ||
"voter_id": None, | ||
"subject_id": feedback.subject_id, | ||
"prediction": feedback.prediction, | ||
"confidence": feedback.confidence, | ||
"vote": feedback.vote, | ||
"feedback_text": feedback.feedback_text, | ||
"proposed_label": feedback.proposed_label, | ||
} | ||
|
||
async with self.session: | ||
result: AsyncResult = await self.session.execute(sql_select) | ||
result = result.first() | ||
|
||
# check if voter exists | ||
if not result: | ||
logger.info({"voter_does_not_exist": FeedbackInput}) | ||
await self.session.rollback() | ||
return False, "voter_does_not_exist" | ||
|
||
voter_id = result["id"] | ||
sql_dupe_check = sql_dupe_check.where(dbFeedback.voter_id == voter_id) | ||
|
||
result: AsyncResult = await self.session.execute(sql_dupe_check) | ||
result = result.first() | ||
|
||
# check if duplicate record | ||
if result: | ||
logger.info({"duplicate_record": FeedbackInput, "voter id": voter_id}) | ||
await self.session.rollback() | ||
return False, "duplicate_record" | ||
|
||
# add voter_id and insert | ||
data["voter_id"] = voter_id | ||
sql_insert = sql_insert.values(data) | ||
result: AsyncResult = await self.session.execute(sql_insert) | ||
await self.session.commit() | ||
return True, "success" |
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
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
Oops, something went wrong.