← Back to team overview

zeitgeist team mailing list archive

[Branch ~zeitgeist/zeitgeist/bluebird] Rev 228: Add Histogram extension

 

------------------------------------------------------------
revno: 228
committer: Michal Hruby <michal.mhr@xxxxxxxxx>
branch nick: bluebird
timestamp: Mon 2011-09-05 18:19:38 +0200
message:
  Add Histogram extension
added:
  extensions/histogram.vala
  src/ext-histogram.vala@
modified:
  src/Makefile.am
  src/extension-collection.vala


--
lp:~zeitgeist/zeitgeist/bluebird
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird

Your team Zeitgeist Framework Team is subscribed to branch lp:~zeitgeist/zeitgeist/bluebird.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== added file 'extensions/histogram.vala'
--- extensions/histogram.vala	1970-01-01 00:00:00 +0000
+++ extensions/histogram.vala	2011-09-05 16:19:38 +0000
@@ -0,0 +1,124 @@
+/* histogram.vala
+ *
+ * Copyright © 2011 Michal Hruby <michal.mhr@xxxxxxxxx>
+ *
+ * Based upon a Python implementation (2010-2011) by:
+ *  Siegfried-Angel Gevatter Pujals <siegfried@xxxxxxxxxxxx>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Zeitgeist
+{
+    [DBus (name = "org.gnome.zeitgeist.Histogram")]
+    public interface RemoteHistogram: Object
+    {
+        [DBus (signature = "a(xu)")]
+        public abstract Variant get_histogram_data () throws Error;
+    }
+
+    class Histogram: Extension, RemoteHistogram
+    {
+
+        private uint registration_id = 0;
+
+        construct
+        {
+            // This will be called after bus is acquired, so it shouldn't block
+            try
+            {
+                var connection = Bus.get_sync (BusType.SESSION, null);
+                registration_id = connection.register_object<RemoteHistogram> (
+                    "/org/gnome/zeitgeist/journal/activity", this);
+            }
+            catch (Error err)
+            {
+                warning ("%s", err.message);
+            }
+        }
+
+        public override void unload ()
+        {
+            try
+            {
+                var connection = Bus.get_sync (BusType.SESSION, null);
+                if (registration_id != 0)
+                {
+                    connection.unregister_object (registration_id);
+                    registration_id = 0;
+                }
+            }
+            catch (Error err)
+            {
+                warning ("%s", err.message);
+            }
+
+            debug ("%s, this.ref_count = %u", Log.METHOD, this.ref_count);
+        }
+
+        public Variant get_histogram_data () throws Error
+        {
+            var builder = new VariantBuilder (new VariantType ("a(xu)"));
+
+            string sql = """
+                SELECT strftime('%s', datetime(timestamp/1000, 'unixepoch'),
+                'start of day') AS daystamp,
+                COUNT(*)
+                FROM event
+                GROUP BY daystamp
+                ORDER BY daystamp DESC
+                """;
+
+            Sqlite.Statement stmt;
+            var database = engine.database;
+            unowned Sqlite.Database db = database.database;
+
+            int rc = db.prepare_v2 (sql, -1, out stmt);
+            database.assert_query_success (rc, "SQL error");
+
+            while ((rc = stmt.step ()) == Sqlite.ROW)
+            {
+                int64 t = stmt.column_int64 (0);
+                uint32 count = stmt.column_int (1);
+
+                builder.add ("(xu)", t, count);
+            }
+
+            if (rc != Sqlite.DONE)
+            {
+                string error_message = "Error in get_histogram_data: " +
+                    "%d, %s".printf (rc, db.errmsg ());
+                warning ("%s", error_message);
+                throw new EngineError.DATABASE_ERROR (error_message);
+            }
+
+            return builder.end ();
+        }
+
+    }
+
+    [ModuleInit]
+#if BUILTIN_EXTENSIONS
+    public static Type histogram_init (TypeModule module)
+    {
+#else
+    public static Type extension_register (TypeModule module)
+    {
+#endif
+        return typeof (Histogram);
+    }
+}
+
+// vim:expandtab:ts=4:sw=4

=== modified file 'src/Makefile.am'
--- src/Makefile.am	2011-09-05 10:27:02 +0000
+++ src/Makefile.am	2011-09-05 16:19:38 +0000
@@ -21,6 +21,7 @@
 extensions_VALASOURCES = \
 	ext-data-source-registry.vala \
 	ext-blacklist.vala \
+	ext-histogram.vala \
 	$(NULL)
 
 bluebird_VALASOURCES = \
@@ -59,7 +60,7 @@
 	$(VALA_V)$(VALAC) $(VALAFLAGS) -C -H zeitgeist-engine.h --library zeitgeist-engine $^
 	touch "$@"
 
-extensions_vala.stamp: zeitgeist-engine.vapi $(extensions_VALASOURCES)
+extensions_vala.stamp: zeitgeist-engine_vala.stamp $(extensions_VALASOURCES)
 	$(foreach ext_src,$(filter %.vala,$^),\
 		$(VALAC) $(VALAFLAGS) $(EXT_FLAGS) -C zeitgeist-engine.vapi $(ext_src) || exit 1;)
 	touch "$@"

=== added symlink 'src/ext-histogram.vala'
=== target is u'../extensions/histogram.vala'
=== modified file 'src/extension-collection.vala'
--- src/extension-collection.vala	2011-09-05 16:16:36 +0000
+++ src/extension-collection.vala	2011-09-05 16:19:38 +0000
@@ -45,7 +45,8 @@
             RegisterExtensionFunc[] builtins =
             {
                 data_source_registry_init,
-                blacklist_init
+                blacklist_init,
+                histogram_init
             };
 
             foreach (var func in builtins)
@@ -166,6 +167,7 @@
 #if BUILTIN_EXTENSIONS
     private extern static Type data_source_registry_init (TypeModule mod);
     private extern static Type blacklist_init (TypeModule mod);
+    private extern static Type histogram_init (TypeModule mod);
 #endif
 
 }