photo-stats

statistics processor for the terminal
git clone https://git.clttr.info/photo-stats.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 4baa223cb9eef9e1f7a9bd62e466b73346141ffa
parent b0c20cbd65ef2587ffca943262a27a741f245810
Author: René Wagner <rwagner@rw-net.de>
Date:   Sun, 30 Aug 2020 20:30:08 +0200

allow skipping of lines with empty values

Diffstat:
MREADME.md | 1+
Mphosta.pl | 23+++++++++++++++++++----
2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -115,6 +115,7 @@ stats querying: -o <fields> : sort your output by the given fields (sequence matters!) in descending order allowed values: any comma separated combination of the values of -t and -s param and 'count' -r : sort in reverse (ascending) order + -e : skip lines with empty selected or grouping fields examples: phosta -E jpg,jpeg,tiff -D ~/Documents/stats.db -p ~/Pictures diff --git a/phosta.pl b/phosta.pl @@ -35,10 +35,11 @@ our $opt_n=undef; our $opt_o='count'; our $opt_r=0; our $opt_f=undef; +our $opt_e=0; getconfig($configfile); -getopts('vcrp:n:g:s:t:D:E:o:f:') or die "Invalid parameters provided! See 'phosta --help' for more details."; +getopts('vcrp:n:g:s:t:D:E:o:f:e') or die "Invalid parameters provided! See 'phosta --help' for more details."; validate() or die "Invalid parameters provided! See 'phosta --help' for more details."; my $dsn = "DBI:SQLite:dbname=$opt_D"; @@ -230,7 +231,6 @@ sub get_sql foreach (get_filters()) { - push @wherearray, @{$_}[0] . (@{$_}[1] =~ /!/ ? ' NOT' : '') . " LIKE '%@{$_}[2]%'"; } @@ -288,6 +288,19 @@ sub result_to_stdout { if (!defined($opt_n) || ($currentlines < $opt_n)) { + if ($opt_e) + { + my $skip = 1; + for (my $i=0; $i < (scalar @$_ - 2); $i++) + { + @$_[$i] eq '-' or $skip = 0; + } + if ($skip) + { + $skippedlines++; + next; + } + } $tb->row(@$_); $currentlines++; } @@ -314,12 +327,13 @@ sub result_to_stdout say ''; } - if (defined($opt_n)) + if (defined($opt_n) || $opt_e) { - say 'Showing '. color('bold'). "top $currentlines". color('reset'). ' results, skipping '. color('italic') . "$skippedlines lines".color('reset') .'.'; + say 'Showing '. color('bold'). "$currentlines". color('reset'). ' results, skipping '. color('italic') . "$skippedlines lines".color('reset') .'.'; } say 'A total of '. color('bold'). "$sum images". color('reset') .' matched your criteria.'; say ''; + if (scalar @$rows) { say $tb->draw; } } @@ -368,6 +382,7 @@ sub main::HELP_MESSAGE say ' -o <fields> : sort your output by the given fields (sequence matters!) in descending order'; say ' allowed values: any comma separated combination of the values of -t and -s param and \'count\''; say ' -r : sort in reverse (ascending) order'; + say ' -e : skip lines with empty selected or grouping fields'; say ''; say 'examples:'; say ' phosta -E jpg,jpeg,tiff -D ~/Documents/stats.db -p ~/Pictures';