Compare commits
No commits in common. "04797427fc3dad1af1ff081ffdf441f3ba37a2cf" and "8bd67b2096b4abf52b94a35f4ff87450344eaa72" have entirely different histories.
04797427fc
...
8bd67b2096
24
app/Main.hs
24
app/Main.hs
@ -10,21 +10,16 @@ import Control.Monad.Logger (runStderrLoggingT)
|
|||||||
import Control.Monad.Trans.Resource (runResourceT)
|
import Control.Monad.Trans.Resource (runResourceT)
|
||||||
import Data.ByteString.Lazy as BS
|
import Data.ByteString.Lazy as BS
|
||||||
import Data.List as List
|
import Data.List as List
|
||||||
import Data.Text (Text, unpack)
|
|
||||||
-- https://github.com/yesodweb/yesod-cookbook/blob/master/cookbook/Static-file-subsite-Hello-World.md
|
|
||||||
|
|
||||||
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
|
|
||||||
import Database.Persist.Postgresql (ConnectionPool, ConnectionString, SqlBackend, runMigration, runSqlPool, withPostgresqlPool)
|
import Database.Persist.Postgresql (ConnectionPool, ConnectionString, SqlBackend, runMigration, runSqlPool, withPostgresqlPool)
|
||||||
import Debug.Trace (traceShow)
|
import Debug.Trace (traceShow)
|
||||||
import Store (fetch, migrateAll, save)
|
import Store (fetch, migrateAll, save)
|
||||||
import Text.Read (readMaybe)
|
|
||||||
import Track (parseBS)
|
import Track (parseBS)
|
||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
import Yesod.Form.Fields
|
import Yesod.Form.Fields
|
||||||
import Yesod.Form.Functions
|
import Yesod.Form.Functions
|
||||||
import Yesod.Form.Input
|
|
||||||
import Yesod.Form.Types
|
import Yesod.Form.Types
|
||||||
import Yesod.Persist
|
import Yesod.Persist
|
||||||
|
-- https://github.com/yesodweb/yesod-cookbook/blob/master/cookbook/Static-file-subsite-Hello-World.md
|
||||||
import Yesod.Static
|
import Yesod.Static
|
||||||
|
|
||||||
staticFiles "frontend" -- this param appears to be a pathname
|
staticFiles "frontend" -- this param appears to be a pathname
|
||||||
@ -93,26 +88,17 @@ var app = Elm.Main.init({
|
|||||||
<p>Copyright © 2024 Daniel Barlow
|
<p>Copyright © 2024 Daniel Barlow
|
||||||
|]
|
|]
|
||||||
|
|
||||||
type Form x = Html -> MForm (HandlerFor Souplesse) (FormResult x, Widget)
|
|
||||||
|
|
||||||
data Timerange = Timerange {start :: Int, duration :: Int} deriving (Show)
|
|
||||||
|
|
||||||
getPointsR :: Handler Value
|
getPointsR :: Handler Value
|
||||||
getPointsR = do
|
getPointsR = do
|
||||||
tr <-
|
points <- runDB Store.fetch
|
||||||
runInputGet $
|
returnJson points
|
||||||
Timerange
|
|
||||||
<$> ireq intField "start"
|
|
||||||
<*> ireq intField "duration"
|
|
||||||
let start' = posixSecondsToUTCTime $ fromInteger $ toInteger $ start tr
|
|
||||||
duration' = fromInteger $ toInteger $ duration tr
|
|
||||||
points <- runDB $ Store.fetch start' duration'
|
|
||||||
returnJson (traceShow tr points)
|
|
||||||
|
|
||||||
data FileForm = FileForm
|
data FileForm = FileForm
|
||||||
{ fileInfo :: FileInfo
|
{ fileInfo :: FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Form x = Html -> MForm (HandlerFor Souplesse) (FormResult x, Widget)
|
||||||
|
|
||||||
uploadForm :: Form FileForm
|
uploadForm :: Form FileForm
|
||||||
uploadForm =
|
uploadForm =
|
||||||
renderDivs $
|
renderDivs $
|
||||||
|
16
lib/Store.hs
16
lib/Store.hs
@ -17,7 +17,7 @@ module Store (save, fetch, migrateAll) where
|
|||||||
|
|
||||||
import Control.Monad.IO.Class (MonadIO, liftIO)
|
import Control.Monad.IO.Class (MonadIO, liftIO)
|
||||||
import Control.Monad.Trans.Reader (ReaderT)
|
import Control.Monad.Trans.Reader (ReaderT)
|
||||||
import Data.Time.Clock (DiffTime, NominalDiffTime, UTCTime, addUTCTime)
|
import Data.Time.Clock (UTCTime)
|
||||||
import Database.Persist
|
import Database.Persist
|
||||||
import Database.Persist.Class
|
import Database.Persist.Class
|
||||||
import Database.Persist.Postgresql
|
import Database.Persist.Postgresql
|
||||||
@ -30,7 +30,6 @@ import Database.Persist.Postgresql
|
|||||||
runSqlPool,
|
runSqlPool,
|
||||||
)
|
)
|
||||||
import Database.Persist.TH
|
import Database.Persist.TH
|
||||||
import Text.Read (readMaybe)
|
|
||||||
import Track (Point (..), Pos (..))
|
import Track (Point (..), Pos (..))
|
||||||
import Track as T
|
import Track as T
|
||||||
|
|
||||||
@ -62,14 +61,13 @@ toPoint entity =
|
|||||||
in Point
|
in Point
|
||||||
pos
|
pos
|
||||||
(trkptTime tkp)
|
(trkptTime tkp)
|
||||||
(trkptCadence tkp)
|
Nothing
|
||||||
(trkptPower tkp)
|
Nothing
|
||||||
(trkptHeartRate tkp)
|
Nothing
|
||||||
|
|
||||||
save p = do insert $ fromPoint p
|
save p = do insert $ fromPoint p
|
||||||
|
|
||||||
fetch :: (MonadIO m) => UTCTime -> NominalDiffTime -> ReaderT SqlBackend m [Point]
|
fetch :: (MonadIO m) => ReaderT SqlBackend m [Point]
|
||||||
fetch start duration = do
|
fetch = do
|
||||||
let finish = addUTCTime duration start
|
trkpts <- selectList [TrkptLat <=. 360] [] -- Asc TrkptTime]
|
||||||
trkpts <- selectList [TrkptTime >. start, TrkptTime <. finish] []
|
|
||||||
return $ map toPoint trkpts
|
return $ map toPoint trkpts
|
||||||
|
@ -58,10 +58,7 @@ instance ToJSON Point where
|
|||||||
toJSON Point {..} =
|
toJSON Point {..} =
|
||||||
object
|
object
|
||||||
[ "pos" .= pos,
|
[ "pos" .= pos,
|
||||||
"time" .= time,
|
"time" .= time
|
||||||
"cadence" .= cadence,
|
|
||||||
"power" .= power,
|
|
||||||
"heartRate" .= heartRate
|
|
||||||
]
|
]
|
||||||
|
|
||||||
-- TODO do we even need this type?
|
-- TODO do we even need this type?
|
||||||
|
@ -78,7 +78,6 @@ executable souplesse
|
|||||||
, persistent-postgresql
|
, persistent-postgresql
|
||||||
, resourcet
|
, resourcet
|
||||||
, monad-logger
|
, monad-logger
|
||||||
, time
|
|
||||||
, yesod-core == 1.6.25.1
|
, yesod-core == 1.6.25.1
|
||||||
, yesod-static
|
, yesod-static
|
||||||
, yesod-form
|
, yesod-form
|
||||||
|
Loading…
Reference in New Issue
Block a user