diff --git a/db.hs b/db.hs index 573e87084..605bb3564 100755 --- a/db.hs +++ b/db.hs @@ -18,6 +18,8 @@ import System.Console.GetOpt import System.Exit (exitWith, ExitCode(..)) import System.IO (hPutStrLn, stderr) +import qualified Data.ByteString as BS + import Data.Time @@ -46,6 +48,12 @@ main = do hPutStrLn stderr $ usageInfo "db.hs" argsDescr exitWith $ ExitFailure 2 +insertFile :: FilePath -> DB FileId +insertFile fileTitle = do + fileContent <- liftIO $ Just <$> BS.readFile ("testdata/" <> fileTitle) + fileModified <- liftIO getCurrentTime + insert File{..} + fillDb :: DB () fillDb = do AppSettings{ appUserDefaults = UserDefaultConf{..}, .. } <- getsYesod appSettings @@ -233,10 +241,10 @@ fillDb = do , courseDescription = Nothing , courseLinkExternal = Nothing , courseShorthand = "ProMo" - , courseTerm = TermKey summer2017 + , courseTerm = TermKey summer2018 , courseSchool = ifi , courseCapacity = Just 50 - , courseRegisterFrom = Nothing + , courseRegisterFrom = Just now , courseRegisterTo = Nothing , courseDeregisterUntil = Nothing , courseRegisterSecret = Nothing @@ -245,6 +253,28 @@ fillDb = do insert_ $ CourseEdit jost now pmo void . insert $ DegreeCourse pmo sdBsc sdInf void . insert $ Lecturer jost pmo + sh1 <- insert Sheet + { sheetCourse = pmo + , sheetName = "Blatt 1" + , sheetDescription = Nothing + , sheetType = Normal 6 + , sheetGrouping = Arbitrary 3 + , sheetMarkingText = Nothing + , sheetVisibleFrom = Just now + , sheetActiveFrom = now + , sheetActiveTo = (14 * nominalDay) `addUTCTime` now + , sheetHintFrom = Nothing + , sheetSolutionFrom = Nothing + } + void . insert $ SheetEdit jost now sh1 + void . insert $ SheetCorrector jost sh1 (Load (Just True) 0) + void . insert $ SheetCorrector gkleen sh1 (Load (Just True) 1) + h102 <- insertFile "H10-2.hs" + h103 <- insertFile "H10-3.hs" + pdf10 <- insertFile "ProMo_Uebung10.pdf" + void . insert $ SheetFile sh1 h102 SheetHint + void . insert $ SheetFile sh1 h103 SheetSolution + void . insert $ SheetFile sh1 pdf10 SheetExercise -- datenbanksysteme dbs <- insert Course { courseName = "Datenbanksysteme" diff --git a/testdata/H10-2.hs b/testdata/H10-2.hs new file mode 100644 index 000000000..27c8978e7 --- /dev/null +++ b/testdata/H10-2.hs @@ -0,0 +1,25 @@ +{- Übung H10-2 zur Vorlesung "Programmierung und Modellierung" + Lehrstuhl für theoretische Informatik, LMU München + Steffen Jost, Leah Neukirchen +-} + +import Control.Monad + +chainAction1 :: Monad m => a -> [(a -> m a)] -> m a +chainAction1 = undefined -- !!! TODO !!! + +chainAction2 :: Monad m => a -> [(a -> m a)] -> m a +chainAction2 = undefined -- !!! TODO !!! + +chainAction3 :: Monad m => a-> [(a -> m a)] -> m a +chainAction3 = undefined -- !!! TODO !!! + + +tellOp :: (Show a, Show b) => (a -> b) -> a -> IO b +tellOp f x = let fx = f x in do + putStrLn $ (show x) ++ " -> " ++ (show fx) + return fx + +test1 :: [Int -> IO Int] +test1 = map tellOp [(*3),(+1),(`mod` 7),(+5),(*2)] + diff --git a/testdata/H10-3.hs b/testdata/H10-3.hs new file mode 100644 index 000000000..33a8bd2f3 --- /dev/null +++ b/testdata/H10-3.hs @@ -0,0 +1,84 @@ +{- Übung H10-3 zur Vorlesung "Programmierung und Modellierung" + Lehrstuhl für theoretische Informatik, LMU München + Steffen Jost, Leah Neukirchen + + Bitte nur die Zeilen mit + error "TODO" -- TODO: Ihre Aufgabe !!! + bearbeiten. + (Sie dürfen an diesen Stellen auch beliebig + viele neue Zeilen einfügen.) + + Entweder mit ghc kompilieren und ausführen oder + einfach in ghci laden und main auswerten. +-} + + +import Control.Monad.Trans.State + +type Wetter = String +data Welt = Welt { zeit :: Int, wetter :: Wetter } + deriving Show + +main = + let startState = Welt { zeit=0, wetter="Regen" } + (result,finalState) = runState actions startState + in do + putStrLn "Zustand Welt bei Start ist: " + print startState + putStrLn "Zustand Welt bei Ende ist: " + print finalState + putStrLn "Ergebnis der Aktion ist: " + print result + + +actions :: State Welt [(String,Int)] +actions = do + tick + tick + tick + tick + wetter1 <- swapWetter "Sonne" + zeit1 <- gets zeit + let r1 = (wetter1, zeit1) + tick + tick + wetter2 <- swapWetter "Sturm" + zeit2 <- zeit <$> get + let r2 = (wetter2, zeit2) + tick + return [r1,r2] + + +--- !!! NUR AB HIER BEARBEITEN !!! + + + +tick :: State Welt () +tick = + error "TODO: tick noch nicht implementiert!" -- TODO: Ihre Aufgabe !!! + + + + +swapWetter :: Wetter -> State Welt Wetter +swapWetter = + error "TODO: swapWetter noch nicht implementiert!" -- TODO: Ihre Aufgabe !!! + + + + + + + + + + + + + + + + + + + diff --git a/testdata/ProMo_Uebung10.pdf b/testdata/ProMo_Uebung10.pdf new file mode 100644 index 000000000..f00811232 Binary files /dev/null and b/testdata/ProMo_Uebung10.pdf differ