From c1824e62973aa945613f412f7a550968ce32f6a8 Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Fri, 23 Mar 2018 18:55:14 +0800 Subject: [PATCH] Reduced sample size --- country.go | 13 ++++++++++++- latency.go | 13 ++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/country.go b/country.go index 2969f50..3ccb350 100644 --- a/country.go +++ b/country.go @@ -9,6 +9,7 @@ import ( "os" "strconv" "strings" + "math/rand" ) type geoRange struct { @@ -99,6 +100,7 @@ func main() { } } + // TODO: verify correctness log.Println("Grouping latencies by country") odata := make(map[string][]int, 0) j := 0 @@ -113,9 +115,18 @@ func main() { } 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") raw, err := json.Marshal(odata) if err != nil { diff --git a/latency.go b/latency.go index 468fba7..9a6b5c1 100644 --- a/latency.go +++ b/latency.go @@ -24,11 +24,6 @@ type portInfo struct { 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 flagOut = flag.String("out", "latency.json", "output file") @@ -62,14 +57,10 @@ func main() { } log.Println("Reducing data to IP and latency") - odata := make([]hostLatency, 0) + odata := make(map[uint32]int, 0) for _, o := range data { ip := binary.BigEndian.Uint32(net.ParseIP(o.IP)[12:]) - h := hostLatency{ - IP: ip, - TTL: o.Ports[0].TTL, - } - odata = append(odata, h) + odata[ip] = o.Ports[0].TTL } log.Println("Encoding json")