From 3080d9de45809a69520d664d84a5f11d1a1dd8a1 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 28 Oct 2013 13:36:04 +0100 Subject: [PATCH] createindex: Top 10 artists --- toys/createindex | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/toys/createindex b/toys/createindex index 8f3464c..0b2ec41 100755 --- a/toys/createindex +++ b/toys/createindex @@ -619,7 +619,57 @@ do done unset line genre count rest genres counts maxgenrelen maxcountlen -' +echo ' + +Top 10 artists:' +maxartistlen=6 +maxcountlen=5 +unset counts artists +echo ' + SELECT artist, + COUNT(*) + FROM tags + WHERE artist NOT NULL + GROUP BY artist + ORDER BY COUNT(*) DESC + LIMIT 10; + +SELECT "AtOM:NoMoreFiles";' >&3 + +read -u4 line +until [[ $line == AtOM:NoMoreFiles ]] +do + artist="${line%%::AtOM:SQL:Sep::*}" + rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + count="${rest%%::AtOM:SQL:Sep::*}" + counts+=( "$count" ) + artists+=( "$artist" ) + maxcountlen=$(( ${#count} > maxcountlen ? ${#count} : maxcountlen )) + maxartistlen=$(( ${#artist} > maxartistlen ? ${#artist} : maxartistlen )) + read -u4 line +done +head=$( + printf "| # | %'${maxcoutlen}s | %-${maxartistlen}s |" \ + Count Artist +) +sep=${head//[^|]/-} +sep=${sep//\|/+} +echo "$sep" +echo "$head" +echo "$sep" +for id in ${!artists[@]} +do + printf "| %2i | %'${maxcountlen}i | %-${maxartistlen}s |\n" \ + $(( id + 1 )) \ + "${counts[id]}" \ + "${artists[id]}" + echo "$sep" +done +unset line artist count rest artists counts maxartistlen maxcountlen + +echo ' + +File formats:' echo ' SELECT COUNT(*),SUM(size) FROM source_files