Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4a9584ba7e
Fetching contributors…

Cannot retrieve contributors at this time

36 lines (24 sloc) 0.954 kb
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules #-}
import Predict
import Database.MongoDB
import Control.Monad.Trans (liftIO)
import System.Environment
main = do
args <- getArgs
pipe <- runIOE $ connect (host "127.0.0.1")
e <- access pipe master "personal-runway" (run (read (args!!0)::Float))
close pipe
print e
run money = do
-- left is latest
deltas <- lastDeltas 30
let toggl = last14 $ predict 14 $ reverse $ floatify (series "+" deltas)
let toshl = last14 $ predict 14 $ reverse $ floatify (series "-" deltas)
liftIO $ putStrLn $ show (simulate money toggl toshl)
lastDeltas n = rest =<< find (select [] "deltas") {sort = ["day" =: -1]} {limit = n}
series field docs = map (valueAt field) docs
floatify xs = map (\x -> read x::Float) $ map show xs
-- left is earliest
last14 xs = reverse $ take 14 $ reverse xs
simulate money toggl toshl =
foldl (\acc (plus, minus) -> acc+plus-minus) money $ zip toggl toshl
Jump to Line
Something went wrong with that request. Please try again.