-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollect.rkt
50 lines (43 loc) · 1.84 KB
/
collect.rkt
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
#lang racket
(provide run)
(define (filter-line line)
(and
(not (= (string-length line) 0))
(not (string=? line "Dynamic : ?"))
(not (string=? line "Unit : ()"))
(not (and (> (string-length line) 4) (string=? (substring line 0 5) "FILE:")))
(not (and (> (string-length line) 3) (string=? (substring line 1 3) ":\\"))) ))
(define (process-line line)
(if (and (> (string-length line) 8)
(string=? (substring line (- (string-length line) 8)) " Seconds"))
(substring line 0 (- (string-length line) 8))
(if (and (> (string-length line) 11)
(string=? (substring line 0 11) "time (sec):"))
(substring line 12)
line)))
(define (process-folder folder)
(let-values ([(progpath progname progisdir) (split-path folder)])
(string-join
(cons (path->string progname)
(append* (map
(lambda (file)
(map process-line
(filter
filter-line
(file->lines (build-path folder file)))))
(get-outfiles folder))))
",")))
(define (get-directories dir)
(map path->complete-path (filter (lambda (x) (string=? (substring (let-values ([(base name mbd) (split-path x)]) (path->string name)) 0 4) ".BM_")) (directory-list dir))))
(define (get-outfiles dir)
(map path->string (filter (lambda (x) (let-values ([(base name mbd) (split-path x)]) (and (string=? (substring (path->string name) 0 3) "out") (string=? (substring (path->string name) (- (string-length (path->string name)) 4)) ".txt")))) (directory-list dir))))
(define (run udir)
(let ([dir (expand-user-path udir)])
(current-directory dir)
(let* ([directories (get-directories dir)]
[lines (map process-folder directories)]
[outpath (build-path dir "results.csv")])
(if (file-exists? outpath)
(delete-file outpath)
'())
(display-lines-to-file lines outpath))))