#!/usr/bin/perl -w
use strict;
use warnings;
use Orkut;

use InternetStats;

my $orkutstats= $o->GetStats();
my $inetstats= GetInetStats();

PrintOrkutStats($orkutstats, $inetstats, 363595);

exit(0);

sub PrintOrkutStats {
    my ($orkutstats, $inetstats, $totalorkut)= @_;
    my $orkutpct= $totalorkut/100;
    my %orkutters;
    my %popperorkut;
    my %inetperorkut;
    for my $c (keys %{$orkutstats->{country}}) {
        $orkutters{$c}= $orkutstats->{country}{$c}*$orkutpct;
        $popperorkut{$c}= $inetstats->{lc($c)}{population} / ($orkutstats->{country}{$c}*$orkutpct);
        $inetperorkut{$c}= $inetstats->{lc($c)}{internetusers} / ($orkutstats->{country}{$c}*$orkutpct);
    }
    print "inhabitants per orkutter/ orkutters per million population\n";
    for (sort {$popperorkut{$a} <=> $popperorkut{$b}} keys %popperorkut) {
        printf("%s %s %s\n", fmt($popperorkut{$_}), fmt(1000000/$popperorkut{$_}), $_);
    }
    print "\n\n";
    print "internetters per orkutter/ orkutters per million internetters\n";
    for (sort {$inetperorkut{$a} <=> $inetperorkut{$b}} keys %inetperorkut) {
        printf("%s %s %s\n", fmt($inetperorkut{$_}), fmt(1000000/$inetperorkut{$_}), $_);
    }
    print "\n\n";
    print "orkutters\n";
    for (sort {$orkutters{$a} <=> $orkutters{$b}} keys %orkutters) {
        printf("%s %s\n", fmt($orkutters{$_}), $_);
    }

    print "\n\n";
}
sub fmt {
    my $val= sprintf("%d", shift);
    return "[silver]".("_" x (9-length($val)) )."[/silver]$val";
}
