Skip to content

Instantly share code, notes, and snippets.

@bessarabov
Created October 31, 2014 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bessarabov/f1016b1d25332e8150bb to your computer and use it in GitHub Desktop.
Save bessarabov/f1016b1d25332e8150bb to your computer and use it in GitHub Desktop.
#!/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