Skip to content

Commit 2c54d67

Browse files
committed
Aggregating all data
1 parent 29e181a commit 2c54d67

File tree

2 files changed

+5007
-0
lines changed

2 files changed

+5007
-0
lines changed

collate.pl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env perl
2+
3+
#Aggregate CSV from several places
4+
5+
use strict;
6+
use warnings;
7+
8+
use v5.12;
9+
10+
use JSON;
11+
12+
use File::Slurp::Tiny qw(read_file);
13+
14+
my $provincias_content = read_file('poblacion-provincia-INE.csv');
15+
my @provincias = split("\n",$provincias_content);
16+
my @prov_names = split(",",$provincias[0]);
17+
my @prov_pop = split(",",$provincias[1]);
18+
19+
my %new_names = ( "Alicante/Alacant" => "Alicante",
20+
"Araba/Álava" => "Álava",
21+
"Bizkaia" => "Bilbao",
22+
"Castellón/Castelló" => "Castellón",
23+
"Gipuzkoa" => "Donostia",
24+
"Girona" => "Gerona",
25+
"Palmas" => "Las Palmas",
26+
"Valencia/València" => "Valencia");
27+
28+
my @columns = qw( contributions stars followers );
29+
30+
my %users;
31+
for my $p ( @prov_names ) {
32+
my $population = shift @prov_pop;
33+
my $name = $new_names{$p}?$new_names{$p}:$p;
34+
next if $name eq "Guadalajara"; #Problems with sampling
35+
my $file_contents = read_file("data/user-data-$name.json");
36+
next if !$file_contents;
37+
my $p_data = decode_json( $file_contents);
38+
39+
for my $u (@$p_data ) {
40+
if (! $users{$u->{'login'}} ) {
41+
for my $column ( @columns ) {
42+
if ( $u->{$column} ) {
43+
$users{$u->{'login'}}->{$column} += $u->{$column};
44+
}
45+
}
46+
$users{$u->{'login'}}->{'province'} = $name;
47+
}
48+
}
49+
}
50+
51+
say "user;province;",join(";",@columns);
52+
for my $k ( sort { $users{$b}->{'contributions'} <=> $users{$a}->{'contributions'} } keys %users ) {
53+
my @column_values;
54+
for my $column ( @columns ) {
55+
if ( $users{$k}->{$column} ) {
56+
push @column_values, $users{$k}->{$column};
57+
} else {
58+
push @column_values, 0;
59+
}
60+
}
61+
say "$k; $users{$k}->{'province'};", join(";", @column_values );
62+
}
63+

0 commit comments

Comments
 (0)