Created
March 23, 2014 23:18
-
-
Save mbusigin/9731350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -W | |
# From populationpyramid.net's data source https://github.com/madewulf/PopulationPyramid.net/tree/master/static/data/generated | |
# Takes the JSON as stdin, returns a CSV with the M/O ratio | |
use strict; | |
use JSON; | |
use Data::Dumper; | |
my $json = JSON->new; | |
my $f; | |
while( <> ) { $f .= $_ } | |
my $years = $json->decode( $f ); | |
foreach my $year (sort keys %{$years}) | |
{ | |
# print Dumper( $years->{$year} ); | |
my $total = 0; | |
foreach my $k (keys %{$years->{$year}->{'female'}}) | |
{ | |
$total += $years->{$year}->{'female'}->{$k}; | |
} | |
foreach my $k (keys %{$years->{$year}->{'male'}}) | |
{ | |
$total += $years->{$year}->{'male'}->{$k}; | |
} | |
my $m = $years->{$year}->{'male'}->{'9'} + $years->{$year}->{'male'}->{'10'} + | |
$years->{$year}->{'female'}->{'9'} + $years->{$year}->{'female'}->{'10'}; | |
my $o = $years->{$year}->{'male'}->{'13'} + $years->{$year}->{'male'}->{'14'} + | |
$years->{$year}->{'female'}->{'13'} + $years->{$year}->{'female'}->{'14'}; | |
my $mo = $m / $o; | |
$year .= '-01-01'; | |
print "$year,$total,$m,$o,$mo\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment