From ff061c40cd58cef6f84740c044dd9effcce5de37 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 21 Mar 2015 18:08:51 +0900 Subject: comment out new monad: broken --- sariulclocks.cabal | 2 +- src/Utils/ScoresFile.hs | 51 ++++++++++++++++++++++++++----------------------- src/sariulccron.hs | 20 +++++++++++-------- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/sariulclocks.cabal b/sariulclocks.cabal index 4266dc6..bf2fe90 100644 --- a/sariulclocks.cabal +++ b/sariulclocks.cabal @@ -20,7 +20,7 @@ executable sariulclocks.cgi main-is: sariulclocks.hs -- other-modules: -- other-extensions: - build-depends: base, cgi, xhtml, time, directory, filepath, split, old-time, mtl, text + build-depends: base, cgi, xhtml, time, directory, filepath, split, old-time, mtl, text, boxes hs-source-dirs: src default-language: Haskell2010 ld-options: -static -pthread diff --git a/src/Utils/ScoresFile.hs b/src/Utils/ScoresFile.hs index eac386c..f981a4a 100644 --- a/src/Utils/ScoresFile.hs +++ b/src/Utils/ScoresFile.hs @@ -14,7 +14,7 @@ import Control.Monad (liftM) import Data.List.Split (splitOn) import Data.Maybe (fromJust) import System.FilePath (()) -import Control.Monad.SariulClocks +-- import Control.Monad.SariulClocks import Control.Monad.Trans (liftIO) scoresToCSV :: ScoresList -> String @@ -35,27 +35,30 @@ scoresFromCSV csv = foldr step [] (lines csv) classString:scoreString:timeString:[] = splitOn "," line theClass = fromJust $ lookupSariulClass ((read . (:[]) . head) classString) ((read . (:[]) . last) classString) --- try to read from scores-XX.csv where XX is largest timestamp -readScoresFile :: SariulScoresMonad a => a (Maybe ScoresList) -readScoresFile = do - curDir <- liftIO getCurrentDirectory - let dataDir = curDir "data" - filenames <- liftM (reverse . sort . filter isCSV) $ liftIO $ getDirectoryContents dataDir - if null filenames - then return Nothing - else do - -- let scores = liftM scoresFromCSV $ liftIO $ readFile (dataDir head filenames) - scores <- liftIO $ scoresFromCSV <$> readFile (dataDir head filenames) - putScores scores - return $ Just scores - where isCSV path = takeExtension path == ".csv" +-- -- try to read from scores-XX.csv where XX is largest timestamp +-- readScoresFile :: SariulScoresMonad a => a (Maybe ScoresList) +-- readScoresFile = do +-- curDir <- liftIO getCurrentDirectory +-- let dataDir = curDir "data" +-- filenames <- liftM (reverse . sort . filter isCSV) $ liftIO $ getDirectoryContents dataDir +-- if null filenames +-- then return Nothing +-- else do +-- -- let scores = liftM scoresFromCSV $ liftIO $ readFile (dataDir head filenames) +-- scores <- liftIO $ scoresFromCSV <$> readFile (dataDir head filenames) +-- putScores scores +-- return $ Just scores +-- where isCSV path = takeExtension path == ".csv" --- writes to score-XX.csv where XX is unix timestamp: a simple-minded logging -writeScoresFile :: SariulScoresMonad a => a () -writeScoresFile = do - scores <- getScores - curDir <- liftIO getCurrentDirectory - let dataDir = curDir "data" - timestamp <- liftM round $ liftIO getPOSIXTime - let filename = dataDir ("scores-" ++ show timestamp ++ ".csv") - liftIO $ writeFile filename (scoresToCSV scores) +-- -- writes to score-XX.csv where XX is unix timestamp: a simple-minded logging +-- writeScoresFile :: SariulScoresMonad a => a () +-- writeScoresFile = do +-- scores <- getScores +-- curDir <- liftIO getCurrentDirectory +-- let dataDir = curDir "data" +-- timestamp <- liftM round $ liftIO getPOSIXTime +-- let filename = dataDir ("scores-" ++ show timestamp ++ ".csv") +-- liftIO $ writeFile filename (scoresToCSV scores) + +readScoresFile = undefined +writeScoresFile = undefined diff --git a/src/sariulccron.hs b/src/sariulccron.hs index fdaf61c..87b5e30 100644 --- a/src/sariulccron.hs +++ b/src/sariulccron.hs @@ -1,19 +1,23 @@ -import Control.Monad.SariulClocks +-- import Control.Monad.SariulClocks import Utils.ScoresFile import Types.Scores import Types.Classes import Control.Monad (liftM, when) +import Text.PrettyPrint.Boxes + +scoresBox :: ScoresList -> Box +scoresBox = undefined weeklyCron :: ScoresList -> ScoresList weeklyCron scores = undefined -main :: IO () -main = runSariulClocksIO $ do - scores <- readScoresFile - when (isJust scores) $ do - modifyScores weeklyCron - shouldModify <- liftM (((/=) scores) . Just) getScores - when shouldModify writeScoresFile +-- main :: IO () +-- main = runSariulClocksIO $ do +-- scores <- readScoresFile +-- when (isJust scores) $ do +-- modifyScores weeklyCron +-- shouldModify <- liftM (((/=) scores) . Just) getScores +-- when shouldModify writeScoresFile isJust :: Maybe a -> Bool isJust (Just _) = True -- cgit v1.2.3