photo-stats

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/photo-stats.git
Log | Files | Refs | README | LICENSE

commit e0e9d2639cad4e5e8d062b8b84a8a40542ffed6a
parent 83298c0db33cbc41cd79f80ce8e518dc1ccc82df
Author: René Wagner <rwa@noreply@clttr.info>
Date:   Tue, 22 Jun 2021 21:55:50 +0200

Merge pull request 'introduce -T param' (#9) from table_param into master

Reviewed-on: https://src.clttr.info/rwa/photo-stats/pulls/9

Diffstat:
Mphosta | 42+++++++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/phosta b/phosta @@ -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"; @@ -64,7 +65,7 @@ sub validate my @group_params = ('year', 'month', 'week', 'hour'); !defined($opt_g) || grep /$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,7 +107,8 @@ sub writeconfig say $filehandle '$opt_D="'. $opt_D .'";'; say $filehandle '$opt_E="'. $opt_E .'";'; say $filehandle '$opt_W="'. $opt_W .'";'; - close $filehandle; + say $filehandle '$opt_T="'. $opt_T .'";'; + close $filehandle; } sub getaliases @@ -317,8 +322,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 @@ -391,10 +402,27 @@ 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]); + # join columns for display before the chart + if ( @$headers >= 4) + { + # TODO: give remaining columns more room if first columns are shorter + # TODO: remove trailing whitespace + my $titlecolumns = @$headers - 2; + my $columnwidth = POSIX::lround($titlewidth / $titlecolumns); + my $title = ''; + for (my $i = 0; $i < $titlecolumns; $i++) + { + $title = $title . ((length(@$_[$i]) > $columnwidth) ? substr(@$_[$i], 0, $columnwidth-1).'~ ' : @$_[$i] . ' '); + } + @$_[0] = $title; + } + say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[$countcolumn]), @$_[$percentcolumn], @$_[$countcolumn]); } }