provide Statistics::Descriptive callback for repeatable values
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 31 Mar 2011 18:27:47 +0000 (20:27 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 31 Mar 2011 18:28:15 +0000 (20:28 +0200)
Makefile.PL
bin/debian-install.sh
lib/MojoFacets/Data.pm
public/code/issn.listprice.pl

index 8a56459..29d5e24 100755 (executable)
@@ -12,6 +12,7 @@ requires 'JSON';
 requires 'HTML::TableExtract';
 requires 'File::Path';
 requires 'Text::Unaccent::PurePerl';
+requires 'Statistics::Descriptive';
 
 features(
        'profile' => [
index 4836cdc..019f9e6 100755 (executable)
@@ -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
index 7782ba3..c6110d5 100644 (file)
@@ -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;
        }
 }
 
index 080e615..a87e526 100644 (file)
@@ -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];
 });