Skip to content

Commit

Permalink
add no double validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciroye committed Aug 1, 2023
1 parent 9a5d21b commit fec916e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion backend/app/infrastructure/repositories/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pydantic import Json
from sqlalchemy import func

from app.infrastructure.models.models import Context, Example, Round
from app.infrastructure.models.models import Context, Example, Round, Validation
from app.infrastructure.repositories.abstract import AbstractRepository


Expand Down Expand Up @@ -54,10 +54,16 @@ def get_example_to_validate(
return (
self.session.query(Example, Context)
.join(Context, Example.cid == Context.id)
.outerjoin(
Validation,
Validation.eid == Example.id & Validation.uid == user_id,
isouter=True,
)
.filter(Context.r_realid == real_round_id)
.filter(Example.uid != user_id)
.filter(Example.retracted == 0)
.filter(Example.total_verified < num_matching_validations)
.filter(Validation.id.is_(None))
.order_by(func.random())
.first()
)
Expand All @@ -68,11 +74,17 @@ def get_example_to_validate_fooling(
return (
self.session.query(Example, Context)
.join(Context, Example.cid == Context.id)
.outerjoin(
Validation,
Validation.eid == Example.id & Validation.uid != user_id,
isouter=True,
)
.filter(Context.r_realid == real_round_id)
.filter(Example.uid != user_id)
.filter(Example.retracted == 0)
.filter(Example.total_verified < num_matching_validations)
.filter(Example.model_wrong == 1)
.filter(Validation.id.is_(None))
.order_by(func.random())
.first()
)
Expand Down

0 comments on commit fec916e

Please sign in to comment.