plotter.nim
1 import os 2 import strutils, sequtils 3 import ggplotnim 4 5 var 6 time: seq[int] 7 latency: seq[int] 8 bandwidth: seq[int] 9 10 for l in lines(paramStr(1)): 11 if "BW:" in l: 12 bandwidth.add(parseInt(l.split({' ', ':'})[^1].split(".")[0])) 13 if "DUPS:" in l: continue 14 if "milliseconds" notin l: continue 15 16 let splitted = l.split({' ', ':'}) 17 time.add(splitted[^4].parseInt) 18 latency.add(splitted[^1].parseInt) 19 20 echo "BW: ", foldl(bandwidth, a + b, 0) 21 #var 22 # time = @[0, 0, 0, 5, 5, 5, 9, 9] 23 # latency = @[300, 500, 600, 100, 500, 600, 800, 900] 24 25 var df = toDf(time, latency) 26 27 let minTime = df["time", int].min 28 29 df = df 30 .mutate(f{"time" ~ float(`time` - minTime) / 1000000000}) 31 .arrange("time").groupBy("time") 32 .summarize(f{int: "amount" << int(size(col("latency")))}, 33 f{int -> int: "maxLatencies" << max(col("latency"))}, 34 f{int -> int: "meanLatencies" << mean(col("latency"))}, 35 f{int -> int: "minLatencies" << min(col("latency"))}) 36 37 let 38 maxLatency = df["maxLatencies", int].max 39 maxTime = df["time", float].max 40 maxAmount = df["amount", int].max 41 factor = float(maxLatency) / float(maxAmount) 42 43 df = df.filter(f{`time` < maxTime - 3}).mutate(f{"scaled_amount" ~ `amount` * factor}) 44 45 df.writeCsv("/tmp/df.csv") 46 47 echo "Average max latency: ", df["maxLatencies", int].mean 48 echo "Average mean latency: ", df["meanLatencies", int].mean 49 echo "Average min latency: ", df["minLatencies", int].mean 50 echo "Average received count: ", df["amount", int].mean 51 echo "Minimum received count: ", df["amount", int].min 52 53 let sa = secAxis(name = "Reception count", trans = f{1.0 / factor}) 54 ggplot(df, aes("time", "maxLatencies")) + 55 geom_line(aes("time", y = "scaled_amount", color = "Amount")) + 56 ylim(0, maxLatency) + 57 ggtitle(paramStr(2)) + 58 legendPosition(0.8, -0.2) + 59 scale_y_continuous(name = "Latency (ms)", secAxis = sa) + 60 geom_line(aes("time", y = "maxLatencies", color = "Max")) + 61 geom_line(aes("time", y = "meanLatencies", color = "Mean")) + 62 geom_line(aes("time", y = "minLatencies", color = "Min")) + 63 ggsave("test.svg", width = 640.0 * 2, height = 480 * 1.5)