Created
October 3, 2014 17:49
-
-
Save hectorgool/208e9a409dd88c521067 to your computer and use it in GitHub Desktop.
MondoDB reporte anual
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/local/bin/perl | |
use utf8; | |
use MongoDB; | |
use MongoDB::OID; | |
my %meses = ( | |
'01'=>'Enero', | |
'02'=>'Febrero', | |
'03'=>'Marzo', | |
'04'=>'Abril', | |
'05'=>'Mayo', | |
'06'=>'Junio', | |
'07'=>'Julio', | |
'08'=>'Agosto', | |
'09'=>'Septiembre', | |
'10'=>'Octubre', | |
'11'=>'Noviembre', | |
'12'=>'Deciembre' | |
); | |
my $total=0; | |
my $client = MongoDB::MongoClient->new(host => 'localhost:27017'); | |
my $db = $client->get_database( 'learninglocker' ); | |
my $statements = $db->get_collection( 'statements' ); | |
my $lrs = $statements->find({"lrs._id" => "54249d1569aca4c7798b4567"}); | |
my $result = $db->run_command([ | |
"distinct" => "statements", | |
"key" => "statement.object.definition.name.en-US", | |
"query" => {} | |
]); | |
for my $d ( @{ $result->{values} } ) { | |
push(@titulos, $d); | |
} | |
#print "Titulos\t"; | |
#foreach my $id (sort keys %meses) { | |
# print "$meses{$id}\t"; | |
#} | |
#print "\n"; | |
foreach my $t( @titulos ){ | |
#print "$t\t"; | |
foreach my $id (sort keys %meses) { | |
my $cantidades = $db->get_collection( 'statements' )->find( { | |
"statement.object.definition.name.en-US" => "$t", | |
'$where' => "return this.created_at.getMonth() == $id" | |
} )->count; | |
$total += $cantidades; | |
print "$cantidades\t"; | |
} | |
print "\n"; | |
} | |
print "\ntotal: $total\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment