-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworldcup.go
68 lines (59 loc) · 1.1 KB
/
worldcup.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
package disttopk
import (
"compress/gzip"
"encoding/binary"
"fmt"
"os"
)
var _ = fmt.Println
type Request struct {
Timestamp uint32
ClientID uint32
ObjectID uint32
Size uint32
Method uint8
Status uint8
TypeName uint8
Server uint8
}
type WcFileSourceAdaptor struct {
KeyOnClient bool
}
func (this *WcFileSourceAdaptor) CacheFileNameSuffix() string {
s := ".wc"
if this.KeyOnClient {
s += ".client"
} else {
s += ".object"
}
return s
}
func (this *WcFileSourceAdaptor) FillMapFromFile(filename string, m map[uint32]map[int]float64) {
fmt.Println("Processing file", filename)
file, err := os.Open(filename) // For read access.
if err != nil {
panic(err)
}
defer file.Close()
gz, err := gzip.NewReader(file)
if err != nil {
//return
panic(fmt.Sprintln(err, filename))
}
defer gz.Close()
for err == nil {
r := &Request{}
err = binary.Read(gz, binary.LittleEndian, r)
s := uint32(r.Server)
mi, ok := m[s]
if !ok {
m[s] = make(map[int]float64)
mi = m[s]
}
if this.KeyOnClient {
mi[int(r.ClientID)] += 1
} else {
mi[int(r.ObjectID)] += 1
}
}
}