commit ea82a54e416ef2800c1cf72b76c3a1e3ddbad1fd
parent b5f7004e0b82808f07c8fa504cbcf8840ed2160e
Author: Jaromil <jaromil@dyne.org>
Date:   Tue,  3 Nov 2015 03:06:39 +0100
new ascii stats processing from stdin
Diffstat:
3 files changed, 59 insertions(+), 45 deletions(-)
diff --git a/src/jaro b/src/jaro
@@ -730,6 +730,10 @@ main() {
             exitcode=$?
             ;;
 
+    stats)  stats ${PARAM} | sort -n
+            exitcode=$?
+            ;;
+
     edit|vim)   jarovim ${PARAM}    ;;
     open)       open_folder ${PARAM}  ;;
     preview)    preview_file ${PARAM} ;;
@@ -820,11 +824,6 @@ main() {
         exitcode=$?
         ;;
 
-    crypt)
-        crypt_queue ${PARAM}
-        exitcode=$?
-        ;;
-
     smtp)
         smtp_send ${PARAM}
         exitcode=$?
diff --git a/src/zlibs/search b/src/zlibs/search
@@ -112,7 +112,6 @@ search() {
     _results=""
 
     ztmp
-    # hard limit for list of file results is 100MB here
     nm search --output=files ${=PARAM} >> $ztmpfile
     search_results=(`cat $ztmpfile`)
     
@@ -121,7 +120,7 @@ search() {
         return 1
     }
 
-    act "${#search_results} emails found"
+    notice "${#search_results} matches found"
 }
 
 
diff --git a/src/zlibs/stats b/src/zlibs/stats
@@ -22,57 +22,73 @@
 
 
 
-
 stats() {
+    fn stats $*
+
     # make index of all maildirs
-    notice "Maildirs statistics"
-    case ${PARAM[1]} in
+    notice "Computing statistics on stdin"
+    typeset -A count
+    num=0
+
+    case $1 in
 
 	timecloud) timecloud ;;
 
 	weeks) weeks ;;
 
-	*) # simple stats
-	    typeset -al tot
-	    typeset -alU fold
-	    list_maildirs
-	    oldpfx=""
-	    grandtot=0
-	    for i in ${maildirs}; do
+        email*)
+            _email=""
+	    for i in "${(f)$(cat)}"; do
+                _email=${i[(ws:@:)-1]/>/}
+                num=${count[$_email]:-0}
+                count[$_email]=$(( $num + 1 ))
+	    done
+
+            ;;            
+	folder*) # simple stats
+	    #list_maildirs
+            #for i in ${maildirs}; do
+
+            _folder=""
+            
+	    for i in `cat`; do
+                _folder=${i[(ws:/:)-3]}
+                
 		# find maildir prefixes
-		pfx="${i[(ws:.:)1]}"
+		# pfx="${_folder[(ws:.:)1]}"
 		# is it a new prefix?
-		{ test "$pfx" = "$oldpfx" } && { continue }
-		oldpfx=$pfx
-
-		fold+=($pfx)
-		# how big?
-		tot+=("`${=find} $MAILDIRS/$pfx* -type f | wc -l`")
-		grandtot="$(( $grandtot + ${tot[${#tot}]} ))"
-	    done
-	    # calculate screen size and bigger tot
-	    maxtot=0
-	    for x in $tot; do # find max
-		if [ $x -gt $maxtot ]; then
-		    maxtot=$x; fi
+                num=${count[$_folder]:-0}
+                count[$_folder]=$(( $num + 1 ))
 	    done
 
-	    c=0
-	    for f in ${fold}; do
-		c=$(( $c + 1 ))
-		sbar=""
-	    # Euclides: cols : x = maxtot : tot
-		cols=$(( $COLUMNS - 20 ))
-		bar=$(( $cols * ${tot[$c]} ))
-		bar=$(( $bar / $maxtot ))
-		for b in {0..$bar}; do sbar="${sbar}#"; done
-		print " ${tot[$c]}\t$sbar ${fold[$c]}"
-	    done
-	    notice "Total maildirs: ${#fold}"
-	    act "Total e-mails stored: ${grandtot}"
-	    act "Storage occupation: `du -hs $MAILDIRS | awk '{print $1}'`"
 	    ;;
+
+        *)
+            error "Stats type not specified"
+            return 1
+            ;;
     esac
+
+    # calculate screen size and bigger tot
+    maxtot=0
+    for x in ${(v)count}; do # find max
+	if [ $x -gt $maxtot ]; then
+	    maxtot=$x; fi
+    done
+
+    for k in ${(k)count}; do
+        v=${count[$k]}
+	sbar=""
+	# Euclides: cols : x = maxtot : tot
+	cols=$(( $COLUMNS - 20 ))
+	bar=$(( $cols * $v ))
+	bar=$(( $bar / $maxtot ))
+	for b in {0..$bar}; do sbar="${sbar}#"; done
+	print " $v\t$sbar $k"
+    done
+    notice "Total: ${#count}"
+    
+
     return 0
 }