feat(participants): corrections

This commit is contained in:
ros 2021-05-25 17:14:36 +02:00
parent 02354f0998
commit fd11121544
3 changed files with 13 additions and 43 deletions

View File

@ -1,4 +1,4 @@
{-# OPTIONS_GHC -fno-warn-redundant-constraints -fno-warn-incomplete-uni-patterns -Wno-error=deprecations #-}
{-# OPTIONS_GHC -fno-warn-redundant-constraints -fno-warn-incomplete-uni-patterns #-}
module Handler.Participants
( getParticipantsListR
, getParticipantsR
@ -110,9 +110,9 @@ postParticipantsIntersectR = do
-> Set.size $ Map.findWithDefault Set.empty lCid courseUsers `Set.intersection` Map.findWithDefault Set.empty uCid courseUsers
selfIntersections = Map.mapKeysMonotonic (\cid -> (cid, cid)) $ Set.size <$> courseUsers
intersections' = Map.union intersections selfIntersections
let allUsersUnion = setUnionAll $ Map.elems courseUsers
let allUsersUnion = Set.size.Set.unions $ Map.elems courseUsers
let mapIntersect = mapIntersectNotOne courseUsers
let allUsersIntersection = setIntersectionAll $ Map.elems courseUsers
let allUsersIntersection = Set.size.setIntersections $ Map.elems courseUsers
return (courses, intersections', mapIntersect, allUsersUnion, allUsersIntersection)
let

View File

@ -563,6 +563,10 @@ withoutSubsequenceBy cmp = go []
| x `cmp` y = go acc a' b
| otherwise = go (y:acc) a b
----------
-- Sets --
----------
-- all functions that used to be here are now in Utils/Set.hs
----------
-- Maps --

View File

@ -1,7 +1,5 @@
module Utils.Set
( setUnionAll
, setIntersectionAll
, setIntersectNotOne
( setIntersectNotOne
, setIntersections
, setMapMaybe
, setSymmDiff
@ -9,7 +7,6 @@ module Utils.Set
, setPartitionEithers
, setFromFunc
, mapIntersectNotOne
, getAllUserIdsSetList
) where
import qualified Data.Set as Set
@ -20,56 +17,25 @@ import Data.Universe
import Control.Lens.Prism
import Control.Lens
-- | cardinal number of a Set
setUnionAll :: Ord a => [Set.Set a] -> Int
setUnionAll [] = 0
setUnionAll [x] = Set.size x
setUnionAll (x:y:z) = setUnionAll (xy:z) where xy = Set.union x y
-- | cardinal number of an intersection of a set and a list of sets
setIntersectNotOne :: Ord a => Set.Set a -> [Set.Set a] -> Int
setIntersectNotOne _ [] = 0
setIntersectNotOne k r = Set.size $ Set.intersection k others where others = setUnionOthers r
-- | Union of a list of sets
setUnionOthers :: Ord a => [Set.Set a] -> Set.Set a
setUnionOthers [] = Set.empty
setUnionOthers [x] = x
setUnionOthers (x:y:z) = setUnionOthers (xy:z) where xy = Set.union x y
-- | cardinal number of a Set
setIntersectionAll :: Ord a => [Set.Set a] -> Int
setIntersectionAll [] = 0
setIntersectionAll [x] = Set.size x
setIntersectionAll (x:y:z) = setIntersectionAll (xy:z) where xy = Set.intersection x y
setIntersectNotOne k r = Set.size $ Set.intersection k others where others = Set.unions r
----------------------------------
-- Functions fro Particiants.hs --
-- Functions for Particiants.hs --
----------------------------------
-- | list of values of a Map with Sets as values
getAllUserIdsSetList :: Map.Map a (Set b) -> [Set b]
getAllUserIdsSetList m = loop (Map.toList m) [] where
loop [] uids = uids
loop ((_,v):xs) uids = loop xs $ uids ++ [v]
-- | value of a Map with given key
getUserIdsOfOneCourse :: (Ord a, Ord b) => Map.Map a (Set b) -> a -> Set b
getUserIdsOfOneCourse m cid
|m == Map.empty = Set.empty
|otherwise = m Map.! cid
-- | extracts from a map a list of values (sets) without one specific entry (a)
getAllUserIdsWithoutOne :: (Ord a, Ord b) => Map.Map a (Set b) -> a -> [Set b]
getAllUserIdsWithoutOne m cid
|m == Map.empty = []
|otherwise = getAllUserIdsSetList $ Map.delete cid m
getAllElemsWithoutOne :: (Ord a) => Map.Map a (Set b) -> a -> [Set b]
getAllElemsWithoutOne m cid = Map.elems $ Map.delete cid m
-- | transforms values (sets) of a map to integers. The number gives information about how many entreis are not only in this one
mapIntersectNotOne :: (Ord a, Ord b) => Map.Map a (Set b) -> Map.Map a Int
mapIntersectNotOne m = loop (Map.toList m) Map.empty where
loop [] ino = ino
loop ((k,_):xs) ino = loop xs $ Map.insert k (setIntersectNotOne (getUserIdsOfOneCourse m k) (getAllUserIdsWithoutOne m k)) ino
loop ((k,_):xs) ino = loop xs $ Map.insert k (setIntersectNotOne (Map.findWithDefault Set.empty k m) (getAllElemsWithoutOne m k)) ino
-----------------------------
-- Functions from Utils.hs --