git.shiar.nl
/
sc2-widget
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
237a312
)
merge ladders of multiple profiles
author
Mischa POSLAWSKY
<perl@shiar.org>
Sat, 11 May 2019 13:44:24 +0000
(15:44 +0200)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Sat, 11 May 2019 13:44:24 +0000
(15:44 +0200)
getsc2clan
patch
|
blob
|
history
diff --git
a/getsc2clan
b/getsc2clan
index 498d0a31622d2b88f6087a5cf461d3972368f78b..6e98d60808e5864c9574be47e20dc8182fbccba1 100755
(executable)
--- a/
getsc2clan
+++ b/
getsc2clan
@@
-6,12
+6,12
@@
use utf8;
use Data::Dump qw( pp );
use LWP::Authen::OAuth2;
use JSON qw( decode_json );
use Data::Dump qw( pp );
use LWP::Authen::OAuth2;
use JSON qw( decode_json );
-use List::
Util qw( all
);
+use List::
MoreUtils qw( all part
);
-my ($profile
id, @clanmatches) = @ARGV; # clan host and name
s
-$profileid and $profileid =~ /\A\d+\z/
- or die "Usage: $0 <profile id> [<clan name>...]\n";
-my ($clanmatch) = map { $_ && qr/\A(?:$_)\z/i } join '|', @
clanmatches
;
+my ($profile
s, $clanmatches) = part { /\D/ } @ARGV; # separate number
s
+@{$profiles}
+ or die "Usage: $0 <profile id>
...
[<clan name>...]\n";
+my ($clanmatch) = map { $_ && qr/\A(?:$_)\z/i } join '|', @
{$clanmatches}
;
my %auth = do './.blizzard.passwd.pl' or die "no auth setup: $!\n";
my $bliz = LWP::Authen::OAuth2->new(%auth,
my %auth = do './.blizzard.passwd.pl' or die "no auth setup: $!\n";
my $bliz = LWP::Authen::OAuth2->new(%auth,
@@
-28,9
+28,15
@@
sub blizget {
return decode_json($json);
}
return decode_json($json);
}
-# find largest group consisting entirely of clan members
# prefer deprecated interface to prevent costly ladder search
# prefer deprecated interface to prevent costly ladder search
-my $ladderdata = blizget(legacy => profile => 2 => 1 => $profileid => 'ladders');
+my @ladderdata = map {
+ blizget(legacy => profile => 2 => 1 => $_ => 'ladders')
+} @{$profiles};
+my %ladders = (
+ map { $_->{ladder}->[0]->{ladderId} => $_ } # unique
+ grep { $_->{ladder}->[0]->{division} }
+ map { $_->{currentSeason}->@* } @ladderdata
+);
my @ladders = (
sort {
$b->{ladder}->[0]->{wins}+$b->{ladder}->[0]->{losses} <=>
my @ladders = (
sort {
$b->{ladder}->[0]->{wins}+$b->{ladder}->[0]->{losses} <=>
@@
-40,9
+46,9
@@
my @ladders = (
!$clanmatch or
all { $_->{clanName} =~ $clanmatch } $_->{characters}->@*
} # members
!$clanmatch or
all { $_->{clanName} =~ $clanmatch } $_->{characters}->@*
} # members
- grep { $_->{ladder}->[0]->{division} }
- $ladderdata->{currentSeason}->@*
+ values %ladders
) or die "No matching groups found\n";
) or die "No matching groups found\n";
+
my (@members, %memberidx);
$memberidx{ $_->{id} } //= push(@members, $_) && $#members
for map { $_->{characters}->@* } @ladders;
my (@members, %memberidx);
$memberidx{ $_->{id} } //= push(@members, $_) && $#members
for map { $_->{characters}->@* } @ladders;