aboutsummaryrefslogtreecommitdiff
path: root/jb/views/common.py
diff options
context:
space:
mode:
authorMax Nanis2026-02-24 17:26:15 -0500
committerMax Nanis2026-02-24 17:26:15 -0500
commit8c1940445503fd6678d0961600f2be81622793a2 (patch)
treeb9173562b8824b5eaa805e446d9d780e1f23fb2a /jb/views/common.py
parent25d8c3c214baf10f6520cc1351f78473150e5d7a (diff)
downloadamt-jb-8c1940445503fd6678d0961600f2be81622793a2.tar.gz
amt-jb-8c1940445503fd6678d0961600f2be81622793a2.zip
Extensive use of type checking. Movement of pytest conf towards handling managers (for db agnostic unittest). Starting to organize pytests.
Diffstat (limited to 'jb/views/common.py')
-rw-r--r--jb/views/common.py68
1 files changed, 2 insertions, 66 deletions
diff --git a/jb/views/common.py b/jb/views/common.py
index 46ac608..0dc8b56 100644
--- a/jb/views/common.py
+++ b/jb/views/common.py
@@ -11,7 +11,7 @@ from starlette.responses import RedirectResponse
from jb.config import settings, JB_EVENTS_STREAM
from jb.decorators import REDIS, HM
from jb.flow.monitoring import emit_assignment_event, emit_mturk_notification_event
-from jb.models.currency import USDCent
+from generalresearchutils.currency import USDCent
from jb.models.definitions import ReportValue, AssignmentStatus
from jb.models.event import MTurkEvent
from jb.settings import BASE_HTML
@@ -71,6 +71,7 @@ async def work(request: Request):
url=f"/preview/?{request.url.query}" if request.url.query else "/preview/",
status_code=302,
)
+
if amt_assignment_id is None or amt_assignment_id == "ASSIGNMENT_ID_NOT_AVAILABLE":
# Worker is previewing the HIT
amt_hit_type_id = "unknown"
@@ -91,71 +92,6 @@ async def work(request: Request):
return HTMLResponse(BASE_HTML)
-@common_router.get(path="/survey/", response_class=JSONResponse)
-def survey(
- request: Request,
- worker_id: str = Query(),
- duration: int = Query(default=1200),
-):
- if not worker_id:
- raise HTTPException(status_code=400, detail="Missing worker_id")
-
- # (1) Check wallet
- wallet_url = f"{settings.fsb_host}{settings.product_id}/wallet/"
- wallet_res = requests.get(wallet_url, params={"bpuid": worker_id})
- if wallet_res.status_code != 200:
- raise HTTPException(status_code=502, detail="Wallet check failed")
-
- wallet_data = wallet_res.json()
- wallet_balance = wallet_data["wallet"]["amount"]
- if wallet_balance < -100:
- return JSONResponse(
- {
- "total_surveys": 0,
- "link": None,
- "duration": None,
- "payout": None,
- }
- )
-
- # (2) Get offerwall
- client_ip = "69.253.144.55" if settings.debug else request.client.host
- offerwall_url = f"{settings.fsb_host}{settings.product_id}/offerwall/d48cce47/"
- offerwall_res = requests.get(
- offerwall_url,
- params={
- "bpuid": worker_id,
- "ip": client_ip,
- "n_bins": 1,
- "duration": duration,
- },
- )
-
- if offerwall_res.status_code != 200:
- raise HTTPException(status_code=502, detail="Offerwall request failed")
-
- try:
- rj = offerwall_res.json()
- bucket = rj["offerwall"]["buckets"][0]
- return JSONResponse(
- {
- "total_surveys": rj["offerwall"]["availability_count"],
- "link": bucket["uri"],
- "duration": round(bucket["duration"]["q2"] / 60),
- "payout": USDCent(bucket["payout"]["q2"]).to_usd_str(),
- }
- )
- except Exception:
- return JSONResponse(
- {
- "total_surveys": 0,
- "link": None,
- "duration": None,
- "payout": None,
- }
- )
-
-
@common_router.post(path=f"/{settings.sns_path}/", include_in_schema=False)
async def mturk_notifications(request: Request):
"""