[Extracting violation and critical violation counts for inspections Dino Morelli **20150119205703 Ignore-this: c9d266a04ba9c07c1d9557a051f55d28 This has been added everywhere from scraping to the finished documents for our db. ] hunk ./TODO 19 -- Ksdl.InspSource.NcWake - - Need to get more data from here for each inspection: - - Violations and critical violations hunk ./src/Ksdl/Database/Inspection.hs 41 + , "violations" .= I.violations insp + , "crit_violations" .= I.crit_violations insp hunk ./src/Ksdl/InspSource/NcWake.hs 7 -import Data.List ( intercalate, isPrefixOf ) +import Data.List ( intercalate, isInfixOf, isPrefixOf ) hunk ./src/Ksdl/InspSource/NcWake.hs 64 - "" + "" -- Will fill in _id later, once this record is complete hunk ./src/Ksdl/InspSource/NcWake.hs 70 + violCount + critCount hunk ./src/Ksdl/InspSource/NcWake.hs 93 + -- This code is for extracting the violations data. Tricky! + + -- Table containing the violations + vtable = (dropWhile (~/= "")) $ tags + + -- Each violations table row. Each of these has 3 tdS + allRowsInViolsTable = partitions (~== "") vtable + + -- Discard the first row, it's display labels + allRowsMinusHeader = tail $ allRowsInViolsTable + + -- Discard the rows after the last violation + vrows = takeWhile isViol allRowsMinusHeader + isViol tags' = length (filter (~== "General Comments") tags') == 0 + + -- Extract the violations and critical-ness from the remaining tags + vs = map extractViolation vrows + + -- Count them up + critCount = length . filter fst $ vs + violCount = length vs + + +{- This code is pulling the violation full text which we are + discarding at this time. But if we want it in the future, it's + already being extracted here. +-} +extractViolation :: [Tag String] -> (Bool, String) +extractViolation tags = (crit, text) + where + crit = isInfixOf "red" $ fromAttrib "style" $ tags !! 6 + text = fromTagText $ tags !! 7 + + hunk ./src/Ksdl/Inspection.hs 34 + , violations :: Int + , crit_violations :: Int hunk ./src/Ksdl/Inspection.hs 74 -displayInspection (Inspection i src n a (y:m:d:_) sc _ _) = - printf mask i (unpack n) y m d sc src (unpack a) +displayInspection (Inspection i src n a (y:m:d:_) sc viol crit _ _) = + printf mask i (unpack n) y m d sc viol crit src (unpack a) hunk ./src/Ksdl/Inspection.hs 80 - , " %s | %4d-%02d-%02d %f | %s" + , " %s | %4d-%02d-%02d %f %d/%d | %s" hunk ./testsuite/InspectionUUID.hs 36 + , violations = 10 + , crit_violations = 3 hunk ./testsuite/NameWords.hs 48 - return $ Inspection "" "" name' "" [] 0.0 False "" + return $ Inspection "" "" name' "" [] 0.0 0 0 False ""