Skip to content

Instantly share code, notes, and snippets.

@mbusigin
Created March 23, 2014 23:18
Show Gist options
  • Save mbusigin/9731350 to your computer and use it in GitHub Desktop.
Save mbusigin/9731350 to your computer and use it in GitHub Desktop.
#!/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