1
0
Fork 0

Reduced sample size

master
Ambrose Chua 2018-03-23 18:55:14 +08:00
parent 8b115eec15
commit c1824e6297
2 changed files with 14 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"math/rand"
) )
type geoRange struct { type geoRange struct {
@ -99,6 +100,7 @@ func main() {
} }
} }
// TODO: verify correctness
log.Println("Grouping latencies by country") log.Println("Grouping latencies by country")
odata := make(map[string][]int, 0) odata := make(map[string][]int, 0)
j := 0 j := 0
@ -113,9 +115,18 @@ func main() {
} }
cc := geo[j].CC cc := geo[j].CC
odata[cc] = append(odata[cc], ttl) if rand.Intn(100) == 0 {
odata[cc] = append(odata[cc], ttl)
}
} }
total := 0
for k, v := range odata {
log.Println("Country " + k + " has " + strconv.Itoa(len(v)) + " samples")
total += len(v)
}
log.Println("Total: " + strconv.Itoa(total))
log.Println("Encoding json") log.Println("Encoding json")
raw, err := json.Marshal(odata) raw, err := json.Marshal(odata)
if err != nil { if err != nil {

View File

@ -24,11 +24,6 @@ type portInfo struct {
TTL int `json:"ttl"` TTL int `json:"ttl"`
} }
type hostLatency struct {
IP uint32 `json:"ip"`
TTL int `json:"ttl"`
}
var flagIn = flag.String("in", "", "comma-seperated list of input files") var flagIn = flag.String("in", "", "comma-seperated list of input files")
var flagOut = flag.String("out", "latency.json", "output file") var flagOut = flag.String("out", "latency.json", "output file")
@ -62,14 +57,10 @@ func main() {
} }
log.Println("Reducing data to IP and latency") log.Println("Reducing data to IP and latency")
odata := make([]hostLatency, 0) odata := make(map[uint32]int, 0)
for _, o := range data { for _, o := range data {
ip := binary.BigEndian.Uint32(net.ParseIP(o.IP)[12:]) ip := binary.BigEndian.Uint32(net.ParseIP(o.IP)[12:])
h := hostLatency{ odata[ip] = o.Ports[0].TTL
IP: ip,
TTL: o.Ports[0].TTL,
}
odata = append(odata, h)
} }
log.Println("Encoding json") log.Println("Encoding json")