photo-stats

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

commit f58f535eeaec9d199a2d63ae2fd6ebe16972534a
parent b061e9c222703de6d96883eaa4263eb1b74a457d
Author: René Wagner <rwagner@rw-net.de>
Date:   Mon, 21 Sep 2020 20:19:17 +0200

WIP: -T param for disabling charts

Diffstat:
Mphosta.pl | 31++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/phosta.pl b/phosta.pl @@ -38,10 +38,11 @@ our $opt_r=0; our $opt_f=undef; our $opt_e=0; our $opt_W=80; +our $opt_T='auto'; getconfig(); -getopts('vcrp:n:g:s:t:D:E:o:f:eW:') or die "Invalid parameters provided! See 'phosta --help' for more details."; +getopts('vcrp:n:g:s:t:D:E:o:f:eW:T:') 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"; @@ -61,10 +62,10 @@ exit 0; sub validate { - my @group_params = ('year', 'month', 'week', 'hour'); + my @group_params = qw(year month week hour); !defined($opt_g) || $opt_g ~~ @group_params or return 0; - my @select_params = ('file', 'maker', 'model', 'lensmake', 'lens', 'aperture', 'exposuretime', 'iso', 'focallength', 'focallength35mm', ''); + my @select_params = qw(file maker model lensmake lens aperture exposuretime iso focallength focallength35mm); if (defined($opt_s)) { foreach (split (/,/, $opt_s)) @@ -89,6 +90,9 @@ sub validate $opt_E =~ /^([a-z]{2,4}){1,}(\,[a-z]{2,4}){0,}$/ or return 0; !defined($opt_f) || $opt_f =~ /^(,{0,1}[\w\-]{2,}(!){0,1}=[\w\-\s]{1,}){1,}$/ or return 0; + + my @table_params = qw(on off auto); + $opt_T ~~ @table_params or return 0; return 1; } @@ -103,6 +107,7 @@ sub writeconfig say $filehandle '$opt_D="'. $opt_D .'";'; say $filehandle '$opt_E="'. $opt_E .'";'; say $filehandle '$opt_W="'. $opt_W .'";'; + say $filehandle '$opt_T="'. $opt_T .'";'; close $filehandle; } @@ -312,8 +317,14 @@ sub query my ($limited_rows, $skippedlines) = limit_results($rows); print_filterinfo(scalar @$limited_rows, $skippedlines, $sum); - if (@$headers == 3) { result_to_graph($headers, $limited_rows, $sum); } - else { result_to_table($headers, $limited_rows, $sum); } + if ($opt_T eq 'off' || (@$headers == 3 and $opt_T eq 'auto') ) + { + result_to_graph($headers, $limited_rows, $sum); + } + else + { + result_to_table($headers, $limited_rows, $sum); + } } sub limit_results @@ -386,10 +397,13 @@ sub result_to_graph my $barwidth = POSIX::lround(($opt_W - 17) * 0.7); my $titlewidth = POSIX::lround(($opt_W - 17) * 0.3); my $chartformat = '%'.$titlewidth.'.'.$titlewidth.'s |%-'.$barwidth.'s| %5s (%s)'; - + + my $countcolumn = @$headers - 2; + my $percentcolumn = @$headers - 1; + foreach (@$rows) { - say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[1]), @$_[2], @$_[1]); + say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[$countcolumn]), @$_[$percentcolumn], @$_[$countcolumn]); } } @@ -455,6 +469,9 @@ sub main::HELP_MESSAGE say ' -e : skip lines with empty selected or grouping fields'; say ' -W <number> : define max char width of output, default: 80, a minimum of 50 is required for meaningful output'; say ' This option is automatically saved to the user config.'; + say ' -T <value> : show results as always as a table (on) or not (off) or auto (chart when single field is selected), default is auto'; + say ' allowed values: auto, on, off'; + say ' This option is automatically saved to the user config.'; say ''; say 'examples:'; say ' phosta -E jpg,jpeg,tiff -D ~/Documents/stats.db -p ~/Pictures';