Merge lp:~cando/zeitgeist/timezone_hell into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Stefano Candori
Status: Merged
Approved by: Seif Lotfy
Approved revision: 343
Merge reported by: Seif Lotfy
Merged at revision: not available
Proposed branch: lp:~cando/zeitgeist/timezone_hell
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 154 lines (+110/-3)
4 files modified
TODO (+0/-1)
extensions/histogram.vala (+3/-2)
test/dbus/Makefile.am (+1/-0)
test/dbus/histogram-test.py (+106/-0)
To merge this branch: bzr merge lp:~cando/zeitgeist/timezone_hell
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+84746@code.launchpad.net

Description of the change

This branch fixes the timezone problem in the histogram extension.
I've also added the test for checking this ( with the relative explanation.. :) ).

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Looking good!

review: Approve
lp:~cando/zeitgeist/timezone_hell updated
343. By Stefano Candori

Updated TODO list.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'TODO'
2--- TODO 2011-11-01 20:42:24 +0000
3+++ TODO 2011-12-08 13:43:34 +0000
4@@ -4,4 +4,3 @@
5 - Figure out why D-Bus test cases time out most of the time.
6 - Finish storage-monitor extension.
7 - Make histogram extension more generic.
8- - Fix time zone problems with histogram extension.
9
10=== modified file 'extensions/histogram.vala'
11--- extensions/histogram.vala 2011-09-25 15:58:52 +0000
12+++ extensions/histogram.vala 2011-12-08 13:43:34 +0000
13@@ -1,6 +1,7 @@
14 /* histogram.vala
15 *
16 * Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
17+ * Copyright © 2011 Stefano Candori <stefano.candori@gmail.com>
18 *
19 * Based upon a Python implementation (2010-2011) by:
20 * Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
21@@ -73,8 +74,8 @@
22 var builder = new VariantBuilder (new VariantType ("a(xu)"));
23
24 string sql = """
25- SELECT strftime('%s', datetime(timestamp/1000, 'unixepoch'),
26- 'start of day') AS daystamp,
27+ SELECT strftime('%s', datetime(timestamp/1000, 'unixepoch',
28+ 'localtime'), 'start of day') AS daystamp,
29 COUNT(*)
30 FROM event
31 GROUP BY daystamp
32
33=== modified file 'test/dbus/Makefile.am'
34--- test/dbus/Makefile.am 2011-10-29 14:09:14 +0000
35+++ test/dbus/Makefile.am 2011-12-08 13:43:34 +0000
36@@ -4,6 +4,7 @@
37 blacklist-test.py \
38 dsr-test.py \
39 engine-test.py \
40+ histogram-test.py \
41 monitor-test.py \
42 remote-test.py \
43 testutils.py \
44
45=== added file 'test/dbus/histogram-test.py'
46--- test/dbus/histogram-test.py 1970-01-01 00:00:00 +0000
47+++ test/dbus/histogram-test.py 2011-12-08 13:43:34 +0000
48@@ -0,0 +1,106 @@
49+#! /usr/bin/python
50+# -.- coding: utf-8 -.-
51+
52+# histogram-test.py
53+#
54+# Copyright © 2011 Stefano Candori <stefano.candori@gmail.com>
55+#
56+# This program is free software: you can redistribute it and/or modify
57+# it under the terms of the GNU Lesser General Public License as published by
58+# the Free Software Foundation, either version 2.1 of the License, or
59+# (at your option) any later version.
60+#
61+# This program is distributed in the hope that it will be useful,
62+# but WITHOUT ANY WARRANTY; without even the implied warranty of
63+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64+# GNU Lesser General Public License for more details.
65+#
66+# You should have received a copy of the GNU Lesser General Public License
67+# along with this program. If not, see <http://www.gnu.org/licenses/>.
68+
69+# Update python path to use local zeitgeist module
70+
71+import sys
72+import os
73+import time
74+import datetime
75+import calendar
76+import unittest
77+import gobject
78+
79+sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
80+from zeitgeist.client import ZeitgeistDBusInterface
81+from zeitgeist.datamodel import *
82+from testutils import RemoteTestCase, import_events
83+
84+#
85+# EXPLANATION OF THE TEST:
86+# The test checks if the histogram extension works well despite the
87+# ***timezone's hell***.
88+# For example the extension, for an user in the GMT+2 timezone, should count
89+# an event inserted on the 2011/12/24 at 1:30 AM as belonging to the day 24.
90+# The problem is that in the engine the events are inserted as UTC-relative:
91+# for the example our event is inserted for the day 2011/12/23 at 23:30 UTC.
92+# The Histogram extension must revert this when collecting data, and this test
93+# check this.
94+#
95+# ******************************************************************************
96+#
97+# In the test we create an event in the "borderline" time for the timezone and
98+# then we insert it in the engine as UCT-relative. After, we retrieve the data
99+# from the extension and finally we check that the event belong to the right day
100+#
101+
102+class HistogramTest(RemoteTestCase):
103+
104+ def __init__(self, methodName):
105+ super(HistogramTest, self).__init__(methodName)
106+ self.histogram = None
107+
108+ def setUp(self):
109+ # lazy import to get a chance to use the private bus
110+ import dbus
111+
112+ # We set up the connection lazily in order to wait for the
113+ # engine to come up
114+ super(HistogramTest, self).setUp()
115+ obj = dbus.SessionBus().get_object("org.gnome.zeitgeist.Engine",
116+ "/org/gnome/zeitgeist/journal/activity")
117+ self.histogram = dbus.Interface(obj, "org.gnome.zeitgeist.Histogram")
118+
119+ def _createEventOne(self):
120+ ev = Event.new_for_values(interpretation=Interpretation.ACCESS_EVENT,
121+ subject_uri="file://sisisisisisi")
122+ ev.manifestation = Manifestation.USER_ACTIVITY
123+
124+ if time.timezone < 0 :
125+ start_hour = 24 + int(time.timezone / 3600)
126+ else:
127+ start_hour = int(time.timezone / 3600) - 1
128+
129+ td = datetime.datetime.today()
130+ event_date = datetime.datetime(td.year, td.month, td.day, start_hour, 30)
131+ timestamp = calendar.timegm(event_date.timetuple())
132+
133+ ev.timestamp = timestamp * 1000
134+
135+ return ev, timestamp
136+
137+ def testGetHistogramData(self):
138+ ev, ev_timestamp = self._createEventOne();
139+
140+ inserted_ids = self.insertEventsAndWait([ev])
141+ self.assertEquals(1, len(inserted_ids))
142+
143+ h_data = self.histogram.GetHistogramData()
144+ self.assertEquals(1, len(h_data))
145+
146+ h_day_timestamp = h_data[0][0]
147+
148+ #Check if the inserted event belong to the right day!
149+ day_ev = datetime.date.fromtimestamp(ev_timestamp)
150+ start_day = datetime.date.fromtimestamp(h_day_timestamp)
151+ self.assertEquals(day_ev.day , start_day.day)
152+
153+if __name__ == "__main__":
154+ unittest.main()

Subscribers

People subscribed via source and target branches