photo-stats

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

commit 2205a6c5e5bcb48c4c5aec9f4d7c6e8a064c233e
parent fe942a13891f7a0fbe7432b0c50ed2f6767d7267
Author: René Wagner <rwagner@rw-net.de>
Date:   Mon, 17 Aug 2020 18:57:39 +0200

use control flow or instead if where suitable

Diffstat:
Mphosta.pl | 21++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/phosta.pl b/phosta.pl @@ -49,7 +49,7 @@ if ( !-e $opt_D ) { create_db($opt_D) or die 'database could not be created'; } writeconfig($configfile); -if ( $opt_p ne '' ) { +if ($opt_p ne '') { populate(); exit 0; } @@ -61,14 +61,14 @@ exit 0; sub validate { my @group_params = ('year', 'month', 'week', 'hour'); - if (defined($opt_g) && ! ($opt_g ~~ @group_params) ) { return 0; } + !defined($opt_g) || $opt_g ~~ @group_params or return 0; my @select_params = ('maker', 'model', 'lensmake', 'lens', 'aperture', 'exposuretime', 'iso', 'focallength', 'focallength35mm', ''); if (defined($opt_s)) { foreach (split (/,/, $opt_s)) { - if ( !($_ ~~ @select_params) ) { return 0; } + $_ ~~ @select_params or return 0; } } @@ -77,14 +77,14 @@ sub validate { foreach (split (/,/, $opt_o)) { - if ( !($_ ~~ @order_params)) { return 0; }; + $_ ~~ @order_params or return 0; } } - if (defined($opt_n) && (!looks_like_number($opt_n) || $opt_n < 1)) { return 0; } + !defined($opt_n) || !looks_like_number($opt_n) || $opt_n > 0 or return 0; - if (defined($opt_t) && $opt_t !~ /^([0-9]{8}){0,1}\-([0-9]{8}){0,1}$/) { return 0; } + !defined($opt_t) || $opt_t =~ /^([0-9]{8}){0,1}\-([0-9]{8}){0,1}$/ or return 0; - if ($opt_E !~ /^([a-z]{2,4}){1,}(\,[a-z]{2,4}){0,}$/) { return 0; } + $opt_E =~ /^([a-z]{2,4}){1,}(\,[a-z]{2,4}){0,}$/ or return 0; return 1; } @@ -224,9 +224,11 @@ sub query my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr; my $total_count = $dbh->selectrow_array("SELECT count(file) from photos"); + say "Querying database $opt_D with $total_count entries..."; say ''; - + $total_count > 0 or return; + if ($opt_v) { say '### SQL Statement: '. get_sql($opt_s, $opt_g, $opt_o, $opt_t); } my $stmt = $dbh->prepare(get_sql($opt_s, $opt_g, $opt_o, $opt_t)); $stmt->execute(); @@ -320,6 +322,7 @@ sub main::HELP_MESSAGE say ' -t <range> : only take images into account which have been taken in the given timerange'; say ' <range> must be specified as \'YYYYMMDD-YYYYMMDD\', you can omit one value'; say ' -n <number> : limit the resultset to <number> of lines'; - say ' -o <fields> : sort your output by the given fields (sequence matters!)'; + 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'; }