package Ernad::Indat::Otria; use strict; use warnings; use base 'Ernad::Indat'; use Carp qw(confess); use Data::Dumper; use Ernad::Indat; use Ernad::Store; #use Ernad::Virif; 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) { warn "I don't know about your report '$repcode'."; next; } $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; my $birth_shoti=$e->{'p'}->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;