Algorithm-Classifier-IsolationForest

 view release on metacpan or  search on metacpan

lib/Algorithm/Classifier/IsolationForest/App/Command/streamd.pm  view on Meta::CPAN

# Args: none.  Reads $OPT{'model_dir'} and $OPT{'keep'}, and is only
# called when --keep is set.
#
# Returns: 1, or an empty return when the model directory cannot be
# opened -- pruning is housekeeping, so it never takes the daemon down.
#
# Example:
#   _prune_models() if defined $OPT{'keep'};
sub _prune_models {
	opendir( my $dh, $OPT{'model_dir'} ) or return;
	my @models = sort { ( stat($a) )[9] <=> ( stat($b) )[9] }
		map { File::Spec->catfile( $OPT{'model_dir'}, $_ ) }
		grep { /\Aoiforest-.*\.json\z/ } readdir($dh);
	closedir $dh;
	while ( scalar @models > $OPT{'keep'} ) {
		my $old = shift @models;
		unlink $old and _log( 'pruned ' . $old );
	}
	return 1;
} ## end sub _prune_models



( run in 2.298 seconds using v1.01-cache-2.11-cpan-500dd33cbaf )