From: wbudic Date: Fri, 19 Oct 2018 22:36:45 +0000 (+1100) Subject: made selectSQL function and added Linux magic of providing processes info. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=139841f29fcb54d003faa36bc8ab689c78855906;p=LifeLog.git made selectSQL function and added Linux magic of providing processes info. --- diff --git a/htdocs/cgi-bin/stats.cgi b/htdocs/cgi-bin/stats.cgi index f80d104..04acdbe 100755 --- a/htdocs/cgi-bin/stats.cgi +++ b/htdocs/cgi-bin/stats.cgi @@ -42,39 +42,38 @@ print $q->start_html(-title => "Personal Log Data Stats", my $tbl = ''; -my $sth = $dbh->prepare( 'select count(rowid) from LOG;' ); -my $rv = $sth->execute() or die or die "

Error->"& $DBI::errstri &"

"; +my $log_rc = selectSQL('select count(rowid) from LOG;'); +my $stm = "SELECT count(date) from LOG where date>=date('now','start of year');"; +my $log_this_year_rc = selectSQL($stm); -my @row = $sth->fetchrow_array(); - -my $log_rc = $row[0]; -$sth->finish; +my $id_expense = selectSQL('SELECT ID from CAT where name like "Expense";'); +my $id_income = selectSQL('SELECT ID from CAT where name like "Income";'); +$stm = 'SELECT sum(ammount) from LOG where date>=date("now","start of year") + AND ID_CAT = '.$id_expense.';'; +my $expense = sprintf("%.2f",selectSQL($stm)); -my $stm = "SELECT count(date) from LOG where date>=date('now','start of year');"; -$sth = $dbh->prepare( $stm ); -$sth->execute(); -@row = $sth->fetchrow_array(); -my $log_this_year_rc = $row[0]; -$sth->finish; - -$stm = "SELECT sum(ammount) from LOG where date>=date('now','start of year');"; -$sth = $dbh->prepare( $stm ); -$sth->execute(); -@row = $sth->fetchrow_array(); -my $sum = sprintf("%.2f",$row[0]); -$sth->finish; +$stm = 'SELECT sum(ammount) from LOG where date>=date("now","start of year") + AND ID_CAT = '.$id_income.';'; +my $income = sprintf("%.2f",selectSQL($stm)); +my $revenue = big_money($income - $expense); my $hardware_status =`inxi -b -c0`; $hardware_status =~ s/\n//g; +my $prc = 'ps -eo size,pid,user,command --sort -size | awk \'{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }\''; +my $processes = `$prc | sort -u -r -`; $tbl = $tbl . ' - + + + @@ -82,10 +81,29 @@ $hardware_status =~ s/\n//g; print '
' . $tbl .'
'; print '

Server Info

' . $hardware_status .'
'; +print '

Processes Info

' . $processes .'
i
'; print $q->end_html; -$sth->finish; $dbh->disconnect(); exit; +sub selectSQL{ + + + my $sth = $dbh->prepare( @_ ); + $sth->execute(); + my @row = $sth->fetchrow_array(); + $sth->finish; + +return $row[0]; +} + +sub big_money { + my $number = sprintf("%.2f", shift @_); + # Add one comma each time through the do-nothing loop + 1 while $number =~ s/^(-?\d+)(\d\d\d)/$1,$2/; + # Put the dollar sign in the right place + $number =~ s/^(-?)/$1\$/; +return $number; +} ### CGI END
Personal Log Data Stats
Number of Records:'. $log_rc.'
No. of Records This Year:'. $log_this_year_rc.'
# Sum For Year '.$today->year(). - ':'.$sum.'
# Sum of Expenses For Year '.$today->year(). + ''.$expense.'
# Sum of Income For Year '.$today->year(). + ''.$income.'
Revenue For Year '.$today->year(). + ''.$revenue.'
'.$database.''. (uc format_bytes($stat[7], bs => 1000)).'