packages feed

posplyu 0.1.1 → 0.1.2

raw patch · 2 files changed

+14/−3 lines, 2 files

Files

Main.hs view
@@ -29,6 +29,7 @@ 	, optExpect :: Bool 	, optDatabaseFile :: FilePath 	, optList :: Bool+	, optAverage :: Word 	} deriving Show  defaultOptions    = Options@@ -36,6 +37,7 @@ 	, optExpect = False 	, optDatabaseFile = "" 	, optList = False+	, optAverage = 0 	}  options :: [OptDescr (Options -> Options)]@@ -44,6 +46,7 @@ 	, Option ['x'] ["expect"] (NoArg (\o -> o { optExpect = True })) "print the expected sleepiness time" 	, Option ['d'] ["database-file"] (ReqArg (\a o -> o { optDatabaseFile = a}) "FILE") "use FILE as the sleep data base" 	, Option ['l'] ["list"] (NoArg (\o -> o { optList = True })) "display the database in the current timezone"+	, Option ['a'] ["average"] (OptArg ((\a o -> o { optAverage = a }) . read . fromMaybe "30") "N") "show the average daily sleep of the last N days" 	]  parseOpts :: [String] -> IO Options@@ -66,6 +69,13 @@ 		editLocal <- mapM (mapM utcToLocalZonedTime) edit 		edited <- toUser editLocal 		writeDB (optDatabaseFile opts) $ left ++ map (map zonedTimeToUTC) edited+	when (0 < optAverage opts) $ do+		db <- readDB $ optDatabaseFile opts+		t <- getCurrentTime+		let sleepPeriods = takeWhile (\[x, y] -> (diffUTCTime t y) < ((fromIntegral $ optAverage opts) * nominalDay)) $ filter (not . isNap) $ reverse db+		let totalSlept = sum $ map (\[x, y] -> diffUTCTime y x) sleepPeriods+		let sleptPerDayHours = (fromIntegral $ round totalSlept) / (3600.0 * (fromIntegral $ optAverage opts))+		print (sleptPerDayHours :: Double) 	when (optList opts) $ do 		db <- readDB $ optDatabaseFile opts 		times <- mapM (mapM utcToLocalZonedTime) db@@ -80,7 +90,7 @@ 			then "in " ++ showTDiff (diffUTCTime expectedTime currentTime) 			else showTDiff (diffUTCTime currentTime expectedTime) ++ " ago" 		putStrLn $ "Sleepiness expected at " ++ show expectedLocalTime ++ " (" ++ relTimeS ++ ")"-	when (not $ or [0 < optEdit opts, optExpect opts, optList opts]) $ do+	when (not $ or [0 < optEdit opts, 0 < optAverage opts, optExpect opts, optList opts]) $ do 		let dirname = intercalate "/" $ init $ split (dropDelims $ whenElt (== '/')) $ optDatabaseFile opts 		createDirectoryIfMissing True dirname 		d <- openDisplay ""@@ -123,6 +133,7 @@  isNap :: [UTCTime] -> Bool isNap [a, b] = diffUTCTime b a < 60 * 60 * 3+isNap a = error $ "Unexpected nap: " ++ show a  notify :: FilePath -> Bool -> IO () notify dbfn status = do
posplyu.cabal view
@@ -1,6 +1,6 @@ name:                posplyu -- semver-version:             0.1.1+version:             0.1.2 synopsis:            Sleep tracker for X11, using XScreenSaver extension and manual input. description:         posplyu is a sleep tracker for X11, using XScreenSaver extension and manual input, motivated by http://super-memory.com/articles/sleep.htm and designed to facilitate transitioning to the free running sleep regiment while living mostly with a GNU/Linux system handy. The tool allows you to measure and somewhat predict your sleeping cycle. For now it assumes a 24h cycle with one sleep period. category:            Tools@@ -18,7 +18,7 @@ Source-repository this   type:              git   location:          https://github.com/l29ah/posplyu.git-  tag:               0.1.1+  tag:               0.1.2   executable posplyu