summaryrefslogtreecommitdiff
path: root/clientreport.hs
diff options
context:
space:
mode:
Diffstat (limited to 'clientreport.hs')
-rw-r--r--clientreport.hs48
1 files changed, 48 insertions, 0 deletions
diff --git a/clientreport.hs b/clientreport.hs
new file mode 100644
index 0000000..c2cfdd5
--- /dev/null
+++ b/clientreport.hs
@@ -0,0 +1,48 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+import qualified Data.CaseInsensitive as CI
+import Data.List (sortBy)
+import Data.Maybe
+import qualified Data.Map as Map
+import Data.Monoid ((<>))
+import Data.Ord (comparing) -- , Down(..))
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Text.IO as TIO
+import Data.Yaml
+
+import System.Environment (getArgs)
+
+data Client = Client {
+ _assignee :: Text
+ , _status :: Text
+ , _clientname :: Text
+ , _filename :: Text -- should be ByteString?
+}
+
+toClient :: Map.Map Text Text -> Client
+toClient ymap = Client user status client filename
+ where
+ user = fromMaybe "ERROR" (Map.lookup "AssignedTo" ymap)
+ status = fromMaybe "ERROR" (Map.lookup "Status" ymap)
+ client = fromMaybe "ERROR" (Map.lookup "ClientName" ymap)
+ filename = fromMaybe "ERROR" (Map.lookup "filename" ymap)
+
+formatClient :: Client -> Text
+formatClient c = T.concat [pad 10 (_assignee c), pad 7 (_status c), _clientname c, " (", _filename c, ")"]
+ where
+ pad x = T.justifyLeft x ' '
+
+printIfNonEmpty :: [Client] -> IO ()
+printIfNonEmpty = mapM_ (TIO.putStrLn . formatClient)
+
+main :: IO ()
+main = do
+ yamlcache <- decodeFile "/home/report/tmp/yamlcache.yaml"
+ args <- fmap (map T.pack) getArgs
+ let ymap = fromJust yamlcache -- fix that
+ cs = map toClient ymap
+ statusopen = cs
+ useropen = if null args then statusopen else filter (\m -> elem (_assignee m) args) statusopen
+ uoclients = filter (\m -> "Client/" `T.isPrefixOf` (_filename m) && T.find (=='/') (T.drop 7 (_filename m)) == Nothing) useropen
+ printIfNonEmpty (sortBy (comparing (CI.mk . _clientname) <> comparing _assignee <> flip (comparing (_status))) uoclients) -- Down