[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r16720: {torstatus} (ticket:98) Using linear weighted average instead of a nonwe (in torstatus/trunk: . geoip)
Author: kasimir
Date: 2008-09-01 15:12:13 -0400 (Mon, 01 Sep 2008)
New Revision: 16720
Modified:
torstatus/trunk/geoip/GeoIP.dat
torstatus/trunk/tns_update.pl
Log:
(ticket:98) Using linear weighted average instead of a nonweighted average
Modified: torstatus/trunk/geoip/GeoIP.dat
===================================================================
(Binary files differ)
Modified: torstatus/trunk/tns_update.pl
===================================================================
--- torstatus/trunk/tns_update.pl 2008-09-01 17:02:15 UTC (rev 16719)
+++ torstatus/trunk/tns_update.pl 2008-09-01 19:12:13 UTC (rev 16720)
@@ -105,8 +105,8 @@
{
# Don't die on errors
-eval
-{
+#eval
+#{
# Find the initial time
my $start_time = time();
@@ -470,6 +470,7 @@
{
$currentRouter{'bandwidthcounter'} += $num;
}
+ $currentRouter{'rh'} = \@readhistory;
$currentRouter{'readnumber'} = scalar(@readhistory);
}
@@ -506,6 +507,7 @@
{
$currentRouter{'bandwidthcounter'} += $num;
}
+ $currentRouter{'wh'} = \@writehistory;
$currentRouter{'writenumber'} = scalar(@writehistory);
}
@@ -600,6 +602,7 @@
{
$currentRouter{'bandwidthcounter'} += $num;
}
+ $currentRouter{'rh'} = \@readhistory;
$currentRouter{'readnumber'} = scalar(@readhistory);
}
@@ -635,6 +638,7 @@
{
$currentRouter{'bandwidthcounter'} += $num;
}
+ $currentRouter{'wh'} = \@writehistory;
$currentRouter{'writenumber'} = scalar(@writehistory);
}
}
@@ -642,14 +646,27 @@
close ($digestSocket);
}
- # Calculate the bandwidth
- my $divisor = 900*($currentRouter{'writenumber'} + $currentRouter{'readnumber'});
+ # Calculate the bandwidth using a linear weight moving average
+ #my $divisor = 900*($currentRouter{'writenumber'} + $currentRouter{'readnumber'});
+ my $n = ($currentRouter{'writenumber'} + $currentRouter{'readnumber'})/2;
+ my $divisor = (($n*($n+1))/2);
# Ensure that no division by zero occurs
if ($divisor == 0)
{
- $divisor = 172800;
+ $divisor = 96*97/2;
}
- $currentRouter{'BandwidthOBSERVED'} = $currentRouter{'bandwidthcounter'}/$divisor;
+ # Add up all of the values, weighting them
+ my $i = $n;
+ my @writehistory = reverse(@{$currentRouter{'wh'}});
+ my @readhistory = reverse(@{$currentRouter{'rh'}});
+ #print $currentRouter{'Fingerprint'} . "\n";
+ my $sum = 0;
+ foreach my $num (@writehistory)
+ {
+ $sum += ($num + $readhistory[$n - $i])/1800*$i;
+ $i--;
+ }
+ $currentRouter{'BandwidthOBSERVED'} = $sum/$divisor;
# Save the data to the MySQL database
$dbresponse->execute( $currentRouter{'nickname'},
@@ -861,7 +878,7 @@
$dbh->disconnect();
close($torSocket);
-};
+#};
if ($@) {
print "The TorStatus database was not updated properly. An error has occured. I will continue to try to update, however.\n";
}