about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-03 11:01:35 +0000
committerEric Wong <e@80x24.org>2015-12-13 12:37:31 +0000
commit8b2ac38c6483eb396b2966531a82b15603958adf (patch)
treeea49c45ce392af2f058133c543865ae5be80a454
parent1a7ebe167dbb13e791b901a13c804e13c5e59365 (diff)
downloaddtas-8b2ac38c6483eb396b2966531a82b15603958adf.tar.gz
These are the same stats used by the mpd "stats" command.
-rw-r--r--lib/dtas/mlib.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb
index 34c0c82..c7ea1df 100644
--- a/lib/dtas/mlib.rb
+++ b/lib/dtas/mlib.rb
@@ -341,7 +341,6 @@ class DTAS::Mlib
 
     # success
     load_tags
-    require 'yaml'
     @tag_rmap = @tag_map.invert
     if found[:tlen] == DM_DIR
       emit_recurse(found)
@@ -353,6 +352,27 @@ class DTAS::Mlib
     end
   end
 
+  def count_distinct(tag)
+    s = 'SELECT COUNT(DISTINCT(val_id)) FROM comments WHERE tag_id = ?'
+    @db.fetch(s, @tag_map[tag]).single_value
+  end
+
+  def count_songs
+    @db.fetch('SELECT COUNT(*) FROM nodes WHERE tlen >= 0').single_value
+  end
+
+  def db_playtime
+    @db.fetch('SELECT SUM(tlen) FROM nodes WHERE tlen >= 0').single_value
+  end
+
+  def stats
+    %w(artist album).each do |k|
+      puts "#{k}s: #{count_distinct(k)}"
+    end
+    puts "songs: #{count_songs}"
+    puts "db_playtime: #{db_playtime}"
+  end
+
   def path_of(node)
     return '/' if node[:name] == ''
     parts = [ node[:name], '' ]