forked from ucsd-progsys/nanomaly
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImportSeminal.hs
52 lines (45 loc) · 1.51 KB
/
ImportSeminal.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE RecordWildCards #-}
module ImportSeminal where
import qualified Data.ByteString.Lazy as LB
import Data.Char
import Data.Csv
import qualified Data.Vector as V
import System.Directory
import System.FilePath
import "Glob" System.FilePath.Glob
import Text.Printf
data ProgramSet =
PS { student_id :: Int
, hw :: Int
, prob :: String
, group_begin :: String
, group_end :: String
, error_category :: String
}
deriving (Show)
instance FromNamedRecord ProgramSet where
parseNamedRecord r
= PS <$> r .: "student_id"
<*> r .: "hw"
<*> r .: "prob"
<*> r .: "group_begin"
<*> r .: "group_end"
<*> r .: "error_category"
toFilePath :: ProgramSet -> FilePath
toFilePath PS {..}
= printf "STUDENT%02d/hw%d%s/Comp/%s-*"
student_id
hw
(if null prob then "" else "-" ++ prob)
group_begin
parseFile :: FilePath -> IO [ProgramSet]
parseFile f = decodeByName <$> LB.readFile f >>= \case
Left e -> error e
Right (_, v) -> return (V.toList v)
filterTypeMismatch :: [ProgramSet] -> [ProgramSet]
filterTypeMismatch = filter (\PS {..} -> map toLower error_category == "type mismatch")
-- ps <- filterTypeMismatch <$> parseFile "Downloads/error_grouping/NanoML-Table 1.csv"
-- forM_ ps $ \p -> do { fs <- glob ("Downloads" </> toFilePath p); forM_ fs $ \f -> copyFile f ("Source/nanoml/data/seminal" </> takeFileName f) }