-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
257 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,50 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
|
||
module Plexams.Types.Slots | ||
( Slot(..) | ||
, Slots | ||
) where | ||
|
||
import Data.Aeson | ||
import qualified Data.Map as M | ||
import GHC.Generics | ||
import Plexams.Types.Common | ||
import Plexams.Types.Exam | ||
import Plexams.Types.Persons | ||
|
||
type Slots = M.Map (DayIndex, SlotIndex) Slot | ||
|
||
data Slot = Slot | ||
{ examsInSlot :: M.Map Ancode Exam -- Ancode -> Exam | ||
, reserveInvigilator :: Maybe Invigilator -- ^ Reserveaufsicht für die Prüfung | ||
} | ||
deriving (Show, Eq, Generic) | ||
|
||
instance FromJSON Slot | ||
instance ToJSON Slot | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE TupleSections #-} | ||
|
||
module Plexams.Types.Slots | ||
( Slot(..) | ||
, Slots | ||
, adjacentSlotPairs | ||
, slotsByDay | ||
) where | ||
|
||
import Data.Aeson | ||
import qualified Data.Map as M | ||
import Data.Maybe (mapMaybe) | ||
import GHC.Exts (groupWith) | ||
import GHC.Generics | ||
import Plexams.Types.Common | ||
import Plexams.Types.Exam | ||
import Plexams.Types.Persons | ||
|
||
type Slots = M.Map (DayIndex, SlotIndex) Slot | ||
|
||
data Slot = Slot | ||
{ examsInSlot :: M.Map Ancode Exam -- Ancode -> Exam | ||
, reserveInvigilator :: Maybe Invigilator -- ^ Reserveaufsicht für die Prüfung | ||
} | ||
deriving (Show, Eq, Generic) | ||
|
||
instance FromJSON Slot | ||
instance ToJSON Slot | ||
|
||
-- dayindex: from 0 to maxDayIndex | ||
-- slotindex: from 0 to maxSlotIndex | ||
adjacentSlotPairs :: Slots -> [[((DayIndex, SlotIndex), Slot)]] | ||
adjacentSlotPairs slots = | ||
let maxSlotIndex = maximum $ map snd $ M.keys slots | ||
maxDayIndex = maximum $ map fst $ M.keys slots | ||
indexPairs = map (\(d,s) -> map (d,) s) | ||
[(d, slotIndexPair) | ||
| d <- [0..maxDayIndex] | ||
, slotIndexPair <- [[x,x+1] | x <- [0..maxSlotIndex-1]] | ||
] | ||
maybeSlotPair [idx1, idx2] = do | ||
slot1 <- M.lookup idx1 slots | ||
slot2 <- M.lookup idx2 slots | ||
return [(idx1, slot1), (idx2, slot2)] | ||
maybeSlotPair _ = Nothing | ||
in mapMaybe maybeSlotPair indexPairs | ||
|
||
slotsByDay :: Slots -> [[((DayIndex, SlotIndex), Slot)]] | ||
slotsByDay slots = groupWith (fst . fst) $ M.toList slots |
Oops, something went wrong.