-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
72 lines (56 loc) · 1.14 KB
/
util.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"bufio"
"encoding/csv"
"fmt"
"io"
"log"
"os"
"time"
)
const (
timelayout = "2006-01-02 15:04:05"
)
func parseCSV(filename string) (queries []Query) {
csvFile, err := os.Open(filename)
checkError(err)
reader := csv.NewReader(bufio.NewReader(csvFile))
checkError(err)
lines, err := reader.ReadAll()
checkError(err)
for i, line := range lines {
if i == 0 {
continue
}
if err == io.EOF {
break
} else {
checkError(err)
}
startime, err := time.Parse(timelayout, line[1])
endtime, err := time.Parse(timelayout, line[2])
if err != nil {
fmt.Printf("record on line %v: incorrect time format\n", line)
continue
}
queries = append(queries, Query{
Hostname: line[0],
Starttime: startime,
Endtime: endtime,
})
}
return
}
// Map applies function f over an array of res to convert it to result timing
func Map(res []Result, f func(time.Duration) float64) []ResultTiming {
resm := make([]ResultTiming, len(res))
for i := range res {
resm[i] = ResultTiming{f(res[i].duration), res[i].count}
}
return resm
}
func checkError(err error) {
if err != nil {
log.Fatal(err)
}
}