photo-stats

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

commit b061e9c222703de6d96883eaa4263eb1b74a457d
parent ac008c8ac62981371bf64c17fc87f3daf6a48dc6
Author: René Wagner <rwagner@rw-net.de>
Date:   Sat, 12 Sep 2020 22:01:01 +0200

introduce -W param to limit output width

Diffstat:
MREADME.md | 2++
Mphosta.pl | 17+++++++++++++----
2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -38,6 +38,8 @@ You can add different folders one by another to the database, the import will ta After you've added some data, you can query different statistics which might be interesting. There are no predefined stats, instead you have the option to adjust the output to your needs using the different params. +For a complete list of params and example querys use `phosta --help` or have a look at the [wiki](https://man.sr.ht/~rwa/photo-workflow/index.md). + ### example output The output will be shown as a bar graph when you select only one output column: ``` diff --git a/phosta.pl b/phosta.pl @@ -37,10 +37,11 @@ our $opt_o='count'; our $opt_r=0; our $opt_f=undef; our $opt_e=0; +our $opt_W=80; getconfig(); -getopts('vcrp:n:g:s:t:D:E:o:f:e') or die "Invalid parameters provided! See 'phosta --help' for more details."; +getopts('vcrp:n:g:s:t:D:E:o:f:eW:') 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"; @@ -80,7 +81,8 @@ sub validate $_ ~~ @order_params or return 0; } } - !defined($opt_n) || !looks_like_number($opt_n) || $opt_n > 0 or return 0; + (!defined($opt_n) || (looks_like_number($opt_n) && $opt_n > 0)) or return 0; + (looks_like_number($opt_W) && $opt_W >= 50) or return 0; !defined($opt_t) || $opt_t =~ /^([0-9]{8}){0,1}\-([0-9]{8}){0,1}$/ or return 0; @@ -100,6 +102,7 @@ sub writeconfig open(my $filehandle, '>', $configfile) or die "Could not open file '$configfile': $!"; say $filehandle '$opt_D="'. $opt_D .'";'; say $filehandle '$opt_E="'. $opt_E .'";'; + say $filehandle '$opt_W="'. $opt_W .'";'; close $filehandle; } @@ -380,9 +383,13 @@ sub result_to_graph { my ( $headers, $rows, $sum ) = @_; + 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)'; + foreach (@$rows) { - say sprintf("%20s | %-50s | %5s (%s)", @$_[0], "*"x(50/$sum*@$_[1]), @$_[2], @$_[1]); + say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[1]), @$_[2], @$_[1]); } } @@ -390,7 +397,7 @@ sub result_to_table { my ( $headers, $rows, $sum, $skippedlines ) = @_; - my $tb = Text::SimpleTable::AutoWidth->new(); + my $tb = Text::SimpleTable::AutoWidth->new('max_width' => $opt_W); $tb->captions($headers); foreach (@$rows) @@ -446,6 +453,8 @@ sub main::HELP_MESSAGE say ' allowed values: any comma separated combination of the values of -t and -s param and \'count\''; say ' -r : sort in reverse (ascending) order, default is descending order'; 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 ''; say 'examples:'; say ' phosta -E jpg,jpeg,tiff -D ~/Documents/stats.db -p ~/Pictures';