Simon-Initiative / oli-torus

Next Generation OLI Authoring and Delivery Platform
https://proton.oli.cmu.edu
MIT License
81 stars 35 forks source link

[BUG FIX] [MER-3176] guard against division by zero in proficiency queries #4884

Closed andersweinstein closed 1 month ago

andersweinstein commented 1 month ago

Got division by zero errors from a proficiency query in Oli.Delivery.Metrics.proficiency_per_student_across/2 . Such an error prevents display of the Students page, and probably other displays showing proficiencies.

This PR adds NULLIF guards around proficiency calculation denominators using ResourceSummary.num_first_attempts to prevent possible division by zero.

The source of the error is not understood. The queries evidently were written on the assumption they will never get a 0 valued sum of num_first_attempts (though might get null). The error suggests some resource is unexpectedly causing an explicit 0 to be recorded in num_first_attempts in the resource summary table, rather than leaving it null.

The error was observed in a somewhat unusual situation: a client-side evaluated activity, the LogicLab, which asynchronously resets part attempts and submits activity evaluations, in context of a containing graded page that was never itself submitted, with this being done by a unique guest student who can never return to complete it.

But since this can happen in the system, should protect against it. Change should be harmless.