forked from phoreproject/phore-seeder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine.pl
65 lines (59 loc) · 1.19 KB
/
combine.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl -w
use strict;
sub loadFile {
my ($file) = @_;
my %ret;
my $max = 0;
open FILE,$file;
while (<FILE>) {
my ($addr,$p2h,$p8h,$p1d,$p1w,$p1m) = split(/\s+/,$_);
if ($p1m =~ /\A([1-9.]+)%\Z/) {
my $x = $1*0.01;
$max=$x if ($x > $max);
$ret{$addr} = $x;
}
}
for my $k (keys %ret) {
$ret{$k} /= $max;
}
close FILE;
return \%ret;
}
sub merge {
my ($a,$b) = @_;
return 1-(1-$a)*(1-$b);
}
sub combine {
my ($f1,$f2) = @_;
my %ret;
for my $k1 (keys %{$f1}) {
if (defined $f2->{$k1}) {
$ret{$k1} = merge($f1->{$k1}, $f2->{$k1});
} else {
$ret{$k1} = merge($f1->{$k1}, 0);
}
}
for my $k2 (keys %{$f2}) {
if (!defined $f1->{$k2}) {
$ret{$k2} = merge(0, $f2->{$k2});
}
}
return \%ret;
}
my $res;
my $n=0;
for my $file (@ARGV) {
my $r = loadFile($file);
if ($res) {
$res = combine($res,$r);
} else {
$res = $r;
}
$n++;
}
for my $addr (sort { $res->{$b} <=> $res->{$a} } (keys %{$res})) {
if ($addr =~ /\A(\d+)\.(\d+)\.(\d+)\.(\d+):8765/) {
my $a = $1*0x1000000 + $2*0x10000 + $3*0x100 + $4;
printf "0x%08x %s %g%%\n",$a,$addr,(1-((1-$res->{$addr}) ** (1/$n)))*100;
}
}