package Ernad::ReportNew; use strict; use warnings; use base 'Ernad'; use Carp qw(confess); use Data::Dumper; use File::Path; use Ernad::Dates; sub get_oldest_sent_date { my $r=shift; ## the modern way to do it. if(not $r->{'rerc'} and defined($r->{'e'}->{'repcode'})) { $r->{'rerc'}=$r->{'e'}->{'report'}->{$r->{'e'}->{'repcode'}}; } my $e=$r->{'e'} // $main::e // confess "Where is my erimp?"; my $rerc=$e->{'report'}->{$r->{'repcode'}}; if(not defined($rerc)) { confess "I need a rerc defined here."; } my $sent_dir=$rerc->{'dir'}->{'sent'} // confess "I need this here"; if(not -d $sent_dir) { $e->echo(__LINE__,"I create $sent_dir"); mkpath($sent_dir); } ## should return undef if nothing there my $oldest_sent_date=$e->{'d'}->oldest_issuedate($sent_dir); $r->{'date'}->{'oldest_sent'}=$oldest_sent_date; return $oldest_sent_date; } ## <-- used in update_models sub age { my $r=shift; ## the oldest date is undefined when there is no issue my $sent_date=$r->get_oldest_sent_date() // return 0; my $today=&Ernad::Dates::today(); my $age=&Ernad::Dates::diff_dates($sent_date,$today); $r->{'age'}=$age; return $age; } ## there is also a $e->{seedable} sub seed_file { my $r=shift; my $repcode=shift // confess "I need a repcode here"; my $e=$r->{'e'} // $main::e // confess "Where is my erimp?"; ## FixMe: this should be somewhere else my $ids_file=$e->{'dir'}->{'seed_conf'}.'/'.$r->{'repcode'}.'.txt'; ## just check that the file is there if(-f $ids_file and not -z $ids_file) { return $ids_file; } return 0; } sub scratch { my $r=shift; my $path=$r->{'path'}; if(not -d $path) { return 0; } use File::Find; # sub wanted { -f $File::Find::name && print $File::Find::name && return 1 } sub wanted { -f $File::Find::name && unlink $File::Find::name } my @files=find(\&wanted, $path); } ## used as an otria crit, the yyyymmdd . age of first select of last issue ## padded by zeros sub lafise { my $r=shift; my $repcode=shift // confess "I need a repcode here."; ## reference date, should be now but has to be give externally my $base_time=shift; my $format='%0'.length($base_time).'d'; if(not $base_time=int($base_time)) { confess "I need a base time to calculate my 2nd part, try \$now"; } my $e=$r->{'e'} // $main::e // confess "Where is my erimp?"; my $rerc=$e->{'report'}->{$repcode}; if(not $rerc) { ## no need to run ->load() $e->{'r'}->setup($repcode); $rerc=$e->{'report'}->{$repcode} // confess "I can't get to report $repcode"; } my $select_dir=$rerc->{'dir'}->{'selected'}; ## first instance of the latest issue my $fila_fufi=$e->{'d'}->fila($select_dir); ## reports that have not started are at the end of the lafise otria if(not $fila_fufi) { return 0; } my $issuedate=$e->{'f'}->issuedate($fila_fufi); my $tist=$e->{'f'}->tist($fila_fufi); my $ago=$base_time-$tist; if($ago < 0) { confess "I can't have a negative ago."; } my $formed_ago=sprintf($format,$ago); my $lafise=&Ernad::Dates::numeric($issuedate).$formed_ago; return $lafise } # # some potentially useful functions from Erimp # ### Set the issuedates that can be used in a subject report. This ### excludes issuedates for which no allport issue has been sent. #sub get_report_issuedates { # my $e=shift; # if($e->{'namfi'}) { # confess "get_report_issuedates() must be replaced by get_available_issuedates()."; # } # my $renew=shift // ''; # if(not $renew and defined($e->{'report_issuedates'})) { # return $e->{'report_issuedates'}; # } # my $allport_sent_dir=$e->{'dir'}->{'allport_sent'} # or confess "I need an allport_sent directory here"; # if(not -d $allport_sent_dir) { # confess "I have no such allport_set_dir $allport_sent_dir."; # } # my $report_issuedates=&Ernad::Common::list_issues_in_dir($allport_sent_dir); # $e->{'report_issuedates'}=$report_issuedates; # return $report_issuedates; #} # #sub get_available_issuedates { # my $e=shift; # my $renew=shift // ''; # if(not $renew and defined($e->{'available_issuedates'})) { # return $e->{'available_issuedates'}; # } # my $report_issuedates; # my $available_dir=$e->{'dir'}->{'available'} # // confess "I ;;need an available directory here."; # if(not -d $available_dir) { # confess "I have no such directory: '$available_dir'."; # } # $report_issuedates=&Ernad::Common::list_issues_in_dir($available_dir); # $e->{'report_issuedates'}=$report_issuedates; # return $report_issuedates; #} # sub is_done { # my $e=shift; # my $repcode=shift # or confess "I need a repccode here.\n"; # my $issuedate=shift # or confess "I need an issuedate here.\n"; # my $report_dir=$e->{'report'}->{$repcode}->{'path'} # or confess "I need a report_dir here"; # my $sent_dir=$report_dir.'/'.$e->{'const'}->{'sent_dir'}; # foreach my $ext ('.amf.xml','.amf.xml.gz') { # my $glob=$sent_dir.'/'.$issuedate.'_*'.$ext; # $e->echo(__LINE__,"I am looking for '$glob'",4); # my @files=glob($glob); # my $file=$files[0] and return 1; # } # return 0; # } 1;