module Data.TimeSeries where
import Data.Time
import Data.Fixed (Pico)
import Graphics.Rendering.Plot.Light.Internal.Utils
data Tick = Tick Day TimeOfDay
deriving (Eq, Show, Ord)
mkTick :: Integer -> Int -> Int -> Int -> Int -> Pico -> Maybe Tick
mkTick yy mm dd hr mi se = do
tim <- makeTimeOfDayValid hr mi se
let d = fromGregorian yy mm dd
return $ Tick d tim
data TsPoint a =
Tsp {
_tick :: Tick,
_val :: a
} deriving (Eq, Show)
tickToFractional :: Fractional b => TsPoint a -> b
tickToFractional = fromRational . fromTick . _tick
fromTick :: Tick -> Rational
fromTick (Tick d t) = fromIntegral (toModifiedJulianDay d) + timeOfDayToDayFraction t
toTick :: Rational -> Tick
toTick n = Tick d t where
t = dayFractionToTimeOfDay dec
d = ModifiedJulianDay wh
(wh, dec) = wholeDecimal n
hourTick, halfHourTick, quarterHourTick :: Double
hourTick = 1/24
halfHourTick = 1/2 * hourTick
quarterHourTick = 1/4 * hourTick