-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathcollate.pl
executable file
·63 lines (51 loc) · 1.62 KB
/
collate.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
#!/usr/bin/env perl
#Aggregate CSV from several places
use strict;
use warnings;
use v5.12;
use JSON;
use File::Slurp::Tiny qw(read_file);
my $provincias_content = read_file('poblacion-provincia-INE.csv');
my @provincias = split("\n",$provincias_content);
my @prov_names = split(",",$provincias[0]);
my @prov_pop = split(",",$provincias[1]);
my %new_names = ( "Alicante/Alacant" => "Alicante",
"Araba/Álava" => "Álava",
"Bizkaia" => "Bilbao",
"Castellón/Castelló" => "Castellón",
"Gipuzkoa" => "Donostia",
"Girona" => "Gerona",
"Palmas" => "Las Palmas",
"Valencia/València" => "Valencia");
my @columns = qw( contributions stars followers );
my %users;
for my $p ( @prov_names ) {
my $population = shift @prov_pop;
my $name = $new_names{$p}?$new_names{$p}:$p;
next if $name eq "Guadalajara"; #Problems with sampling
my $file_contents = read_file("data/user-data-$name.json");
next if !$file_contents;
my $p_data = decode_json( $file_contents);
for my $u (@$p_data ) {
if (! $users{$u->{'login'}} ) {
for my $column ( @columns ) {
if ( $u->{$column} ) {
$users{$u->{'login'}}->{$column} += $u->{$column};
}
}
$users{$u->{'login'}}->{'province'} = $name;
}
}
}
say "user;province;",join(";",@columns);
for my $k ( sort { $users{$b}->{'contributions'} <=> $users{$a}->{'contributions'} } keys %users ) {
my @column_values;
for my $column ( @columns ) {
if ( $users{$k}->{$column} ) {
push @column_values, $users{$k}->{$column};
} else {
push @column_values, 0;
}
}
say "$k; $users{$k}->{'province'};", join(";", @column_values );
}