Sure.
"pw.graded_count < %s" is going to check a new field in the PeerWorkflow
table, and exclude all rows that have enough completed assessments. This is
done before the count() or group by, which will reduce the cost of the
query as more workflows are completed.

"and pw.id not in (select pwi.author_id from assessment_peerworkflowitem
pwi where pwi.scorer_id=%s) " Is the logic for "Do not get PeerWorkflows
that I have already graded". We can check the PeerWorkflowItems where your
ID matches the scorer_id, which is a FK lookup; from what I read off X-ray
and SQL Explains, this is relatively cheap. Based on the returned rows, we
check to see if the PeerWorkflow ID matches the author_id.

"and (pwi.scorer_id is NULL or pwi.assessment_id is not NULL or
pwi.started_at > %s) " Is the logic for making sure the PeerWorkflowItems
are complete (have an associated assessment FK) or, if NULL, started
grading within the last 8 hours.  This is the logic for accumulating our
'count' of graded + locked assessments on a submission.


On Wed, Mar 26, 2014 at 9:34 AM, David Ormsbee <notifications@github.com>wrote:

> In apps/openassessment/assessment/peer_api.py:
>
> > -        timeout,
> > -        graded_by
> > -    )
> > -    return sub
> > +    try:
> > +        peer_workflows = list(PeerWorkflow.objects.raw(
> > +            "select pw.id, pw.submission_uuid "
> > +            "from assessment_peerworkflow pw "
> > +            "left join assessment_peerworkflowitem pwi "
> > +            "on pw.id=pwi.author_id "
> > +            "where pw.item_id=%s "
> > +            "and pw.course_id=%s "
> > +            "and pw.student_id<>%s "
> > +            "and pw.graded_count < %s "
> > +            "and pw.id not in (select pwi.author_id from assessment_peerworkflowitem pwi where pwi.scorer_id=%s) "
> > +            "and (pwi.scorer_id is NULL or pwi.assessment_id is not NULL or pwi.started_at > %s) "
>
> So maybe I'm misunderstanding -- could you please explain the three lines
> above in particular?
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/edx/edx-ora2/pull/208/files#r10975827>
> .
>