package Ernad::Otria; use strict; use warnings; use base 'Ernad'; use Carp qw(confess); use Data::Dumper; use Ernad::Indat; use Ernad::Store; #use Ernad::Virif; #use Ernad::Report; ## not used yet sub call_on_all_reports { my $i=shift; my $e=$i->{'e'} // $main::e // confess "I need an erimp here."; my $fun_ref=shift; my $order_ref=shift; #my $only_do_repcode=shift // ''; ## curpu first, then curse my @repcodes=shuffle $e->list_repcodes(); #push(@repcodes,shuffle $e->get_curse_repcodes()); foreach my $repcode (@repcodes) { #if($only_do_repcode and ($repcode ne $only_do_repcode)) { # $e->echo(__LINE__,"I skip $repcode because I only to $only_do_repcode."); # next; #} &{$fun_ref}($repcode,@_); } } ## used at unleash sub call_by_lafise { my $i=shift; my $e=$i->{'e'} // $main::e // confess "I need an erimp here."; my $fun_ref=shift; #my $only_do_repcode=shift // ''; ## curpu first, then curse my @repcodes=@{$i->by_lafise()}; #push(@repcodes,shuffle $e->get_curse_repcodes()); foreach my $repcode (@repcodes) { #if($only_do_repcode and ($repcode ne $only_do_repcode)) { # $e->echo(__LINE__,"I skip $repcode because I only to $only_do_repcode."); # next; #} &{$fun_ref}($repcode,@_); } } ## returns arrayref sub by_lafise { my $i=shift; my $e=$i->{'e'} // $main::e // confess "I need an erimp here."; my $repcodes=$e->{'r'}->list(); ## common reference time for the age my $now=time; my $crits={}; foreach my $repcode (@$repcodes) { $crits->{$repcode}=$e->{'p'}->lafise($repcode,$now); } my @sorted_repcodes=sort {$crits->{$b} <=> $crits->{$a}} (@$repcodes); return \@sorted_repcodes; } ## returns arrayref sub by_last_update { my $i=shift; my $e=$i->{'e'} // $main::e // confess "I need an erimp here."; my $repcodes=$e->{'r'}->list(); my $now=time; my $crits={}; foreach my $repcode (@$repcodes) { $crits->{$repcode}=$e->{'p'}->lafise($repcode,$now); } my @sorted_repcodes=sort {$crits->{$b} <=> $crits->{$a}} (@$repcodes); return \@sorted_repcodes; } # # sub update { # my $i=shift; # my $e=$main::e // confess "I need an erimp here."; # my $otria=$i->load(); # my $hash=$otria->{'hash'} // {}; # my $repcodes={}; # my $do_save=0; # my @reports=$e->list_repcodes(); # foreach my $repcode (@reports) { # my $rerc=$e->{'report'}->{$repcode}; # if(not $rerc) { # $e->{'r'}->load($repcode); # $rerc=$e->{'report'}->{$repcode}; # } # if(not $rerc) { # confess "I don't know about your report '$repcode'."; # } # $repcodes->{$repcode}=1; # if($otria->{'hash'}->{$repcode}) { # ## this really should need no renewal # next; # } # my $v=Ernad::Virif->new(); # my $birth_shoti=$v->birth_shoti($repcode) // next; # ## we only save if the birth_shoti exists, see line above # $do_save=1; # $otria->{'hash'}->{$repcode}=$birth_shoti; # } # ## reverse check # foreach my $repcode (keys %{$otria->{'hash'}}) { # if(not $repcodes->{$repcode}) { # delete $otria->{'hash'}->{$repcode}; # $do_save=1; # } # } # if($do_save) { # ## make a list # my $count=0; # my $hash=$otria->{'hash'}; # ## a hash to prevent duplication # my $seen; # foreach my $repcode (sort {$hash->{$b} cmp $hash->{$a}} # keys %{$otria->{'hash'}}) { # if($seen->{$repcode}) { # next; # } # $otria->{'list'}->[$count++]=$repcode; # $seen->{$repcode}=1; # } # &Ernad::Store::save($otria,$i->{'file'}->{'otria'}); # } # } # # sub load { # my $i=shift; # my $json=$i->{'file'}->{'otria'}; # if(not -f $json) { # return {}; # } # my $out=&Ernad::Store::load($json); # return $out; # } 1;