From 05d37fbc0ce4edd737b86b6c7646bcd16dbf1746 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Apr 2020 13:13:53 +0200 Subject: [PATCH] fix(allocations): better handle participants without applications --- src/Handler/Allocation/Compute.hs | 1 + src/Handler/Allocation/Prios.hs | 10 +++++++++- src/Handler/Allocation/Users.hs | 8 ++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Handler/Allocation/Compute.hs b/src/Handler/Allocation/Compute.hs index b4b7041f2..b579c056e 100644 --- a/src/Handler/Allocation/Compute.hs +++ b/src/Handler/Allocation/Compute.hs @@ -42,6 +42,7 @@ missingPrioritiesUsers aId = $cachedHereBinary aId $ do -- Ignore users without applications E.where_ . E.exists . E.from $ \courseApplication -> do E.where_ $ courseApplication E.^. CourseApplicationAllocation E.==. E.just (E.val aId) + E.&&. courseApplication E.^. CourseApplicationUser E.==. user E.^. UserId E.where_ . E.exists . E.from $ \allocationCourse -> E.where_ $ allocationCourse E.^. AllocationCourseCourse E.==. courseApplication E.^. CourseApplicationCourse E.&&. allocationCourse E.^. AllocationCourseAllocation E.==. E.val aId diff --git a/src/Handler/Allocation/Prios.hs b/src/Handler/Allocation/Prios.hs index 9edc03250..ca4b4c499 100644 --- a/src/Handler/Allocation/Prios.hs +++ b/src/Handler/Allocation/Prios.hs @@ -66,7 +66,15 @@ postAPriosR tid ssh ash = do [ AllocationUserAllocation ==. aId ] [ AllocationUserPriority =. Nothing ] matrSunk <- runConduit $ sourcePrios .| sinkAllocationPriorities aId - matrMissing <- fromIntegral <$> count [ AllocationUserAllocation ==. aId, AllocationUserPriority ==. Nothing ] + matrMissing <- E.selectCountRows . E.from $ \allocationUser -> do + E.where_ $ allocationUser E.^. AllocationUserAllocation E.==. E.val aId + E.&&. E.isNothing (allocationUser E.^. AllocationUserPriority) + + E.where_ . E.exists . E.from $ \(courseApplication `E.InnerJoin` allocationCourse) -> do + E.on $ allocationCourse E.^. AllocationCourseCourse E.==. courseApplication E.^. CourseApplicationCourse + E.&&. courseApplication E.^. CourseApplicationAllocation E.==. E.just (allocationCourse E.^. AllocationCourseAllocation) + E.where_ $ courseApplication E.^. CourseApplicationUser E.==. allocationUser E.^. AllocationUserUser + E.&&. courseApplication E.^. CourseApplicationAllocation E.==. E.just (E.val aId) return (matrSunk, matrMissing) when (matrSunk > 0) $ diff --git a/src/Handler/Allocation/Users.hs b/src/Handler/Allocation/Users.hs index c44c10ad1..0cd22584e 100644 --- a/src/Handler/Allocation/Users.hs +++ b/src/Handler/Allocation/Users.hs @@ -34,7 +34,9 @@ queryAllocationUser = to $(E.sqlIJproj 2 2) queryAppliedCourses :: Getter UserTableExpr (E.SqlExpr (E.Value Int)) queryAppliedCourses = queryAllocationUser . to queryAppliedCourses' - where queryAppliedCourses' allocationUser = E.subSelectCount . E.from $ \courseApplication -> + where queryAppliedCourses' allocationUser = E.subSelectCount . E.from $ \(courseApplication `E.InnerJoin` allocationCourse) -> do + E.on $ allocationCourse E.^. AllocationCourseCourse E.==. courseApplication E.^. CourseApplicationCourse + E.&&. courseApplication E.^. CourseApplicationAllocation E.==. E.just (allocationCourse E.^. AllocationCourseAllocation) E.where_ $ courseApplication E.^. CourseApplicationUser E.==. allocationUser E.^. AllocationUserUser E.&&. courseApplication E.^. CourseApplicationAllocation E.==. E.just (allocationUser E.^. AllocationUserAllocation) @@ -46,7 +48,9 @@ queryAssignedCourses = queryAllocationUser . to queryAssignedCourses' queryVetoedCourses :: Getter UserTableExpr (E.SqlExpr (E.Value Int)) queryVetoedCourses = queryAllocationUser . to queryVetoedCourses' - where queryVetoedCourses' allocationUser = E.subSelectCount . E.from $ \courseApplication -> do + where queryVetoedCourses' allocationUser = E.subSelectCount . E.from $ \(courseApplication `E.InnerJoin` allocationCourse) -> do + E.on $ allocationCourse E.^. AllocationCourseCourse E.==. courseApplication E.^. CourseApplicationCourse + E.&&. courseApplication E.^. CourseApplicationAllocation E.==. E.just (allocationCourse E.^. AllocationCourseAllocation) E.where_ $ courseApplication E.^. CourseApplicationUser E.==. allocationUser E.^. AllocationUserUser E.&&. courseApplication E.^. CourseApplicationAllocation E.==. E.just (allocationUser E.^. AllocationUserAllocation) E.where_ $ courseApplication E.^. CourseApplicationRatingVeto