Skip to content

Instantly share code, notes, and snippets.

@tomtwo
Created October 24, 2013 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomtwo/7143962 to your computer and use it in GitHub Desktop.
Save tomtwo/7143962 to your computer and use it in GitHub Desktop.
Process output from TOSSIM
#! /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