Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getFetchProcessPathRollupR :: Text -> Handler RepPlain
- getFetchProcessPathRollupR siteId = do
- day <- yesterday
- req <- assmbleRequest $ assmbleUrl day $ unpack siteId
- runDB $ do
- k <- getKey (UniqueSite siteId)
- (Site siteId)
- withManager $ \m -> do
- src <- http req m
- responseBody src $$+- (intoCSV defCSVSettings =$= parsePPR (zonedTimeToUTC day) k =$ sinkP\
- ersist)
- return $ RepPlain $ toContent ("OK" :: String)
- assmbleUrl :: (FormatTime t) => t -> String -> String
- parsePPR :: UTCTime -> SiteId -> Conduit (MapRow Text) (ResourceT (YesodDB App App)) ProcessPathRollup
- parsePPR time site = awaitForever $ \r -> do
- let t = (!) r
- d = liftM fst . double . t
- i = liftM fst . decimal . t
- reportKey <- getKey (UniqueReport (t "Report"))
- (Report (t "Report"))
- lineitemKey <- getKey (UniqueLineitem (t "LineItem Name") (t "LineItem Id"))
- (Lineitem (t "LineItem Id") (t "LineItem Name"))
- mainProcessKey <- getKey (UniqueMainProcess (t "Main Process"))
- (MainProcess (t "Main Process"))
- coreProcessKey <- getKey (UniqueCoreProcess (t "Core Process"))
- (CoreProcess (t "Core Process"))
- unitTypeKey <- getKey (UniqueUnitType (t "Unit Type"))
- (UnitType (t "Unit Type"))
- case (ProcessPathRollup
- <$> (Right site)
- <*> (Right time)
- <*> (Right reportKey)
- <*> (i "Line Number")
- <*> (Right lineitemKey)
- <*> (Right mainProcessKey)
- <*> (Right coreProcessKey)
- <*> (Right unitTypeKey)
- <*> (i "Actual Volume")
- <*> (d "Actual Hours")
- <*> (d "Actual Rate")
- <*> (d "Plan Variance (Hrs)")
- <*> (d "Hours @ Plan Rate")
- <*> (d "Plan Variance (Hrs)")
- <*> (d "% to Plan")
- <*> (d "YOY Baseline Volume")
- <*> (d "YOY Rate")
- <*> (d "YOY Vol / Actual Rate (Hrs)")
- <*> (d "YOY Vol / PY Rate (Hrs)")
- <*> (d "YOY %")) of
- Left err -> fail err
- Right ppr -> yield ppr
- sinkPersist :: Sink ProcessPathRollup (ResourceT (YesodDB App App)) ()
- sinkPersist = awaitForever $ void . lift . lift . insert
- getKey us r = do
- mk <- getBy us
- case mk of
- Nothing -> insert r
- Just (Entity l _) -> return l
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement