From c8b7eb80f8fcdb1b2ab153982124e45c74904157 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 31 Mar 2011 20:27:47 +0200 Subject: [PATCH] provide Statistics::Descriptive callback for repeatable values --- Makefile.PL | 1 + bin/debian-install.sh | 2 +- lib/MojoFacets/Data.pm | 9 +++++++-- public/code/issn.listprice.pl | 6 ++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 8a56459..29d5e24 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,6 +12,7 @@ requires 'JSON'; requires 'HTML::TableExtract'; requires 'File::Path'; requires 'Text::Unaccent::PurePerl'; +requires 'Statistics::Descriptive'; features( 'profile' => [ diff --git a/bin/debian-install.sh b/bin/debian-install.sh index 4836cdc..019f9e6 100755 --- a/bin/debian-install.sh +++ b/bin/debian-install.sh @@ -1,3 +1,3 @@ #!/bin/sh -x -sudo apt-get install libhtml-tableextract-perl libjson-perl libmodule-install-perl +sudo apt-get install libhtml-tableextract-perl libjson-perl libmodule-install-perl libstatistics-descriptive-perl diff --git a/lib/MojoFacets/Data.pm b/lib/MojoFacets/Data.pm index 7782ba3..c6110d5 100644 --- a/lib/MojoFacets/Data.pm +++ b/lib/MojoFacets/Data.pm @@ -15,6 +15,7 @@ use Time::HiRes qw(time); use File::Path qw(mkpath); use Text::Unaccent::PurePerl; use Digest::MD5; +use Statistics::Descriptive; use MojoFacets::Import::File; use MojoFacets::Import::HTMLTable; @@ -649,7 +650,7 @@ sub __commit_end { sub lookup { warn "# lookup ",dump @_; - my ( $vals, $on_path, $on_col, $code ) = @_; + my ( $vals, $on_path, $on_col, $code, $stat_code ) = @_; die "code is not sub{ ... } but ", dump $code unless ref $code eq 'CODE'; if ( ! exists $loaded->{$on_path} ) { @@ -681,12 +682,16 @@ sub lookup { #warn "XXX ",dump $lookup_path_col->{$on_path}->{$on_col}; } + my $stat; + $stat = Statistics::Descriptive::Full->new() if $stat_code; + foreach my $v ( @$vals ) { foreach my $i ( @{ $lookup_path_col->{$on_path}->{$on_col}->{$v} } ) { $on = $items->[$i]; #warn "XXX lookup code $v $i ",dump $on; - $code->(); + $code->($stat); } + $stat_code->( $stat ) if $stat_code; } } diff --git a/public/code/issn.listprice.pl b/public/code/issn.listprice.pl index 080e615..a87e526 100644 --- a/public/code/issn.listprice.pl +++ b/public/code/issn.listprice.pl @@ -1,4 +1,10 @@ lookup($row->{issn}, 'nabava', => 'issn', sub { push @{ $update->{listprice} }, $on->{listprice}; + shift->add_data( $on->{listprice} ); +},sub { + my $stat = shift; + $update->{price_min} = $stat->min; +# $update->{price_max} = $stat->max; + $update->{price_check} = $stat->min * 5 - $row->{cijena}->[0]; }); -- 2.20.1