Skip to content

Commit

Permalink
homework2 what went wrong exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
RAHMI Saïd committed May 3, 2019
1 parent fe1c719 commit f683acb
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions week2/homework/LogAnalysis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,30 @@ time (LogMessage _ ts _) = ts
time (LogMessage (Error _) ts _) = ts

build :: [LogMessage] -> MessageTree
build [] = Leaf
build = foldr insert Leaf
{--timestamp :: LogMessage -> Maybe TimeStamp
timestamp (Unknown _) = Nothing
timestamp (LogMessage t _ _) = case t of
(Error _) -> Just time
Info -> Just time
Warning -> Just time--}
build [] = Leaf
build logs = foldr insert Leaf logs

inOrder :: MessageTree -> [LogMessage]
inOrder Leaf = []
inOrder (Node left msg right) = inOrder left ++ (msg : inOrder right)

whatWentWrong :: [LogMessage] -> [String]
whatWentWrong = map message . filter (severe 50) . inOrder . build

message :: LogMessage -> String
message (Unknown _) = []
message (LogMessage _ _ msg) = msg

severe :: Int -> LogMessage -> Bool
severe minLvl (Unknown _) = False
severe minLvl (LogMessage mType _ _) = case mType of
(Error lvl) -> lvl > minLvl
otherwise -> False


{--severe minLvl (LogMessage Info _ _) = False
severe minLvl (LogMessage Warning _ _) = False
severe minLvl (Unknown _) = False
severe minLvl (LogMessage (Error lvl) _ _)
| lvl > minLvl = True
| otherwise = False--}

0 comments on commit f683acb

Please sign in to comment.