Created
October 31, 2014 22:46
-
-
Save bessarabov/f1016b1d25332e8150bb 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 | |
use strict; | |
use warnings FATAL => 'all'; | |
use feature 'say'; | |
use utf8; | |
use open qw(:std :utf8); | |
use Bessarabv::Sleep; | |
use Class::Date qw(date now); | |
use List::Util qw(sum); | |
use Perl6::Form; | |
sub mean { | |
return sum(@_)/@_; | |
} | |
sub main { | |
my $d_start = date('2014-01-01'); | |
my $d_end = now(); | |
my $bs = Bessarabv::Sleep->new(); | |
my $data = {}; | |
my $d = $d_start; | |
while ($d <= $d_end) { | |
eval { | |
push @{$data->{$d->day_of_week()}}, | |
$bs->get_sleep_hours($d->strftime('%Y-%m-%d')); | |
}; | |
warn $@ if $@; | |
$d += '1D'; | |
} | |
say ''; | |
my @week = qw(вс пн вт ср чт пт сб); | |
foreach (1..6, 0) { | |
print form " {<<}{>>}", | |
$week[$_], | |
sprintf("%0.1f", mean(@{$data->{$_}})) | |
; | |
} | |
say ''; | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment