Created
October 24, 2013 20:00
-
-
Save tomtwo/7143962 to your computer and use it in GitHub Desktop.
Process output from TOSSIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import sys | |
from array import array | |
# Possible input lines: | |
# | |
# Creating noise model for X | |
# Creating node X to boot at Y | |
# DEBUG (X): RadioCountToLedsC: timer fired, counter is Y. | |
# DEBUG (X): RadioCountToLedsC: packet sent. | |
# DEBUG (X): Received packet of length Y | |
# | |
# Declare array to store data | |
d = [] | |
sent = [] | |
recv = [] | |
f = open("test.out", "r") | |
for line in f: | |
s = line.split() | |
if (len(s) > 0): | |
if (s[0] == "Creating"): | |
if (s[1] == "node"): | |
node_id = int(s[2]) | |
d.insert(node_id, { | |
"id": node_id, | |
"boot_time": int(s[6]), | |
"sent": 0, | |
"recv": 0 | |
}) | |
if (s[0] == "DEBUG"): | |
node_id = int(s[1].replace(")", "").replace("(", "").replace(":", "")) | |
if (s[2] == "RadioCountToLedsC:"): | |
if (s[3] == "timer"): | |
counter = int(s[7].replace(".", "")) | |
if (s[3] == "packet"): | |
d[node_id - 1]["sent"] += 1 | |
if (s[2] == "Received"): | |
packet_length = int(s[6].replace(".", "")) | |
d[node_id - 1]["recv"] += 1 | |
total_sent = 0 | |
total_recv = 0 | |
for node in d: | |
print "Node ",node["id"],": sent ",node["sent"],", received ",node["recv"],"" | |
total_sent += node["sent"] | |
total_recv += node["recv"] | |
# Convert to floats for percenting | |
total_sent = float(total_sent) | |
total_recv = float(total_recv) | |
num_nodes = len(d) | |
recv_avg = total_recv / (num_nodes - 1) | |
success_rate = recv_avg / total_sent | |
print "Totals:", total_sent, "sent,", total_recv, "received (",round(success_rate * 100, 1),"%)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment