mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-11-18 12:05:11 +00:00
Scripts for manipulating and calculating statistics from .csc files
This commit is contained in:
parent
bb8377dfee
commit
4633e2fcfd
54
tools/csc/csc-compute-neighbor-stats
Executable file
54
tools/csc/csc-compute-neighbor-stats
Executable file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
$num = 0;
|
||||
$override_range = $ARGV[0];
|
||||
|
||||
# Go through the .csc file; find the transmission range and all the
|
||||
# nodes' x and y coordinates.
|
||||
while(<STDIN>) {
|
||||
if(/\<transmitting_range\>([\d.]+)\<\//) {
|
||||
$range = $1;
|
||||
}
|
||||
|
||||
if(/\<x\>([\d.]+)\</) {
|
||||
$x[$num] = $1;
|
||||
}
|
||||
if(/\<y\>([\d.]+)\</) {
|
||||
$y[$num] = $1;
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
print "Range $range num $num override range $override_range\n";
|
||||
|
||||
if($override_range) {
|
||||
$range = $override_range;
|
||||
}
|
||||
|
||||
$no_neighbors = 0;
|
||||
$all_neighbors = 0;
|
||||
$total_neighbors = 0;
|
||||
# Go through all nodes, find how many are in their range.
|
||||
for($i = 0; $i < $num; $i++) {
|
||||
$neighbors = 0;
|
||||
for($j = 0; $j < $num; $j++) {
|
||||
if($i != $j) {
|
||||
if(($x[$i] - $x[$j]) * ($x[$i] - $x[$j]) +
|
||||
($y[$i] - $y[$j]) * ($y[$i] - $y[$j]) <=
|
||||
$range * $range) {
|
||||
$neighbors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($neighbors == 0) {
|
||||
$no_neighbors++;
|
||||
}
|
||||
if($neighbors == $num - 1) {
|
||||
$all_neighbors++;
|
||||
}
|
||||
$total_neighbors += $neighbors;
|
||||
}
|
||||
print "Num nodes $num, average neighbors " . ($total_neighbors / $num) .
|
||||
", $no_neighbors nodes (" . (100 * $no_neighbors / $num) .
|
||||
"%) have no neighbors, $all_neighbors (" . (100 * $all_neighbors / $num) .
|
||||
"%) have all nodes as neighbors\n";
|
||||
|
29
tools/csc/csc-create-range-success
Executable file
29
tools/csc/csc-create-range-success
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
|
||||
$csc = $ARGV[0];
|
||||
$range = $ARGV[1];
|
||||
$success = $ARGV[2];
|
||||
|
||||
if(!$success) {
|
||||
print "takes a .csc file as input, creates a .csc file with a given tx range and reliability\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
open(F, $csc);
|
||||
|
||||
$csc =~ s/\.csc/-$range-$success.csc/g;
|
||||
|
||||
open(O, "> $csc");
|
||||
|
||||
while(<F>) {
|
||||
if(m-\<transmitting_range\>[\d.]+\</transmitting_range\>-) {
|
||||
print O "<transmitting_range>$range</transmitting_range>\n";
|
||||
} elsif(m-\<interference_range\>[\d.]+\</interference_range\>-) {
|
||||
print O "<interference_range>" . ($range * 2) . "</transmitting_range>\n";
|
||||
} elsif(m-\<success_ratio_rx\>[\d.]+\</success_ratio_rx\>-) {
|
||||
print O "<success_ratio_rx>$success</success_ratio_rx>\n";
|
||||
} else {
|
||||
print O;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user