Skip to content

Commit ae78062

Browse files
author
HirotoShioi
committed
Implement stats command
1 parent 5c3ce0c commit ae78062

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Zendesk.hs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import qualified Data.ByteString.Char8 as B8
1919
import qualified Data.ByteString.Lazy as BL
2020
import Data.Map.Strict (Map)
2121
import Data.Monoid ((<>))
22+
import Data.List (group, sort)
2223
import Data.Text (Text)
2324
import qualified Data.Text as T
2425
import qualified Data.Text.Encoding as T
@@ -97,8 +98,8 @@ main = do
9798
putStrLn "Process finished, please see the following url"
9899
putStrLn $ "https://iohk.zendesk.com/agent/tickets/" <> idNumber
99100
-- Count assigned tickets
100-
[ "countAssigned" ] -> do
101-
T.putStrLn $ "Classifier is going to count tickets assign to: " <> cfgEmail cfg
101+
[ "showStats" ] -> do
102+
T.putStrLn $ "Classifier is going to gather ticket information assigned to: " <> cfgEmail cfg
102103
printWarning
103104
tickets <- listAssignedTickets cfg agentId
104105
printTicketCountMessage tickets (cfgEmail cfg)
@@ -107,8 +108,8 @@ main = do
107108
T.putStrLn $ "Classifier is going to process tickets assign to: " <> cfgEmail cfg
108109
printWarning
109110
tickets <- listAssignedTickets cfg agentId
110-
printTicketCountMessage tickets (cfgEmail cfg)
111111
let filteredTicketIds = filterAnalyzedTickets tickets
112+
putStrLn $ "There are " <> show (length filteredTicketIds) <> " unanalyzed tickets."
112113
putStrLn "Processing tickets, this may take hours to finish."
113114
mapM_ (processTicketAndId cfg agentId) filteredTicketIds
114115
putStrLn "All the tickets has been processed."
@@ -120,7 +121,7 @@ main = do
120121
LT.putStrLn res
121122
_ -> do
122123
let cmdItem = [ "processTicket <id> : Process single ticket of id"
123-
, "listAssigned : Print list of ticket Ids that agent has been assigned"
124+
, "showStats : Print list of ticket Ids that agent has been assigned"
124125
, "processTickets : Process all the tickets i.e add comments, tags. WARNING:" <>
125126
"This is really long process, please use with care"
126127
, "raw_request <url> : Request raw request to the given url"]
@@ -138,10 +139,21 @@ printTicketCountMessage tickets email = do
138139
putStrLn "Done!"
139140
T.putStrLn $ "There are currently " <> tshow ticketCount
140141
<> " tickets in the system assigned to " <> email
141-
putStrLn "Filtering analyzed tickets.."
142142
let filteredTicketCount = length $ filterAnalyzedTickets tickets
143143
putStrLn $ show (ticketCount - filteredTicketCount) <> " tickets has been analyzed."
144-
putStrLn $ show filteredTicketCount <> " tickets are not analyzed yet."
144+
putStrLn $ show filteredTicketCount <> " tickets are not analyzed."
145+
putStrLn "Below are statistics:"
146+
let tagGroups = sortTickets tickets
147+
mapM_ (\(tag, count) -> T.putStrLn $ tag <> ": " <> tshow count) tagGroups
148+
149+
-- | Sort the ticket so we can see the statistics
150+
sortTickets :: [ TicketInfo ] -> [ (Text, Int) ]
151+
sortTickets ts =
152+
let extractedTags = foldr (\TicketInfo{..} acc -> ticketTags <> acc) [] ts -- Extract tags from tickets
153+
filteredTags = filter (`notElem` ["s3", "s2", "cannot-sync"]) extractedTags -- Filter tags
154+
groupByTags :: [ Text ] -> [(Text, Int)]
155+
groupByTags ts = map (\l@(x:xs) -> (x, length l)) (group $ sort ts) -- Group them
156+
in groupByTags filteredTags
145157

146158
-- | Read CSV file and setup knowledge base
147159
setupKnowledgebaseEnv :: FilePath -> IO [ Knowledge ]

0 commit comments

Comments
 (0)