[hamster-applet] glueing facts on shortswitches
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet] glueing facts on shortswitches
- Date: Tue, 19 Jan 2010 15:38:55 +0000 (UTC)
commit 55e881465ca0a0516e88191bc5f101976d7ea565
Author: Toms Bauģis <toms baugis gmail com>
Date: Tue Jan 19 15:38:29 2010 +0000
glueing facts on shortswitches
hamster/applet.py | 8 +-------
hamster/db.py | 44 +++++++++++++++++++++++++++++++++-----------
hamster/storage.py | 3 +++
3 files changed, 37 insertions(+), 18 deletions(-)
---
diff --git a/hamster/applet.py b/hamster/applet.py
index 8184e53..cdbeeff 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -240,8 +240,6 @@ class HamsterApplet(object):
self.timeout_enabled = conf.get("enable_timeout")
self.notify_on_idle = conf.get("notify_on_idle")
self.notify_interval = conf.get("notify_interval")
- self.day_start = conf.get("day_start_minutes")
- self.day_start = dt.time(self.day_start / 60, self.day_start % 60) # it comes in as minutes
self.workspace_tracking = conf.get("workspace_tracking")
runtime.dispatcher.add_handler('conf_changed', self.on_conf_changed)
@@ -349,13 +347,10 @@ class HamsterApplet(object):
"""sets up today's tree and fills it with records
returns information about last activity"""
- today = (dt.datetime.now() - dt.timedelta(hours = self.day_start.hour,
- minutes = self.day_start.minute)).date()
-
self.treeview.detach_model()
self.treeview.clear()
- facts = runtime.storage.get_facts(today)
+ facts = runtime.storage.get_todays_facts()
if facts and facts[-1]["end_time"] == None:
self.last_activity = facts[-1]
else:
@@ -673,7 +668,6 @@ class HamsterApplet(object):
elif key == "notify_interval":
self.notify_interval = value
elif key == "day_start_minutes":
- self.day_start = dt.time(value / 60, value % 60)
self.load_day()
self.update_label()
elif key == "workspace_tracking":
diff --git a/hamster/db.py b/hamster/db.py
index b856985..ed9f743 100644
--- a/hamster/db.py
+++ b/hamster/db.py
@@ -331,14 +331,7 @@ class Storage(storage.Storage):
return grouped_facts
def __get_last_activity(self):
- from configuration import conf
- day_start = conf.get("day_start_minutes")
- day_start = dt.time(day_start / 60, day_start % 60)
-
- today = (dt.datetime.now() - dt.timedelta(hours = day_start.hour,
- minutes = day_start.minute)).date()
- facts = self.__get_facts(today)
-
+ facts = self.__get_todays_facts()
last_activity = None
if facts and facts[-1]["end_time"] == None:
last_activity = facts[-1]
@@ -513,9 +506,14 @@ class Storage(storage.Storage):
# if we are working on +/- current day - check the last_activity
-
if (dt.datetime.now() - start_time <= dt.timedelta(days=1)):
- previous = self.__get_last_activity()
+
+ # pull in previous facts
+ facts = self.__get_todays_facts()
+
+ previous = None
+ if facts and facts[-1]["end_time"] == None:
+ previous = facts[-1]
if previous and previous['start_time'] < start_time:
# check if maybe that is the same one, in that case no need to restart
@@ -529,7 +527,23 @@ class Storage(storage.Storage):
if not previous["description"] \
and 60 >= (start_time - previous['start_time']).seconds >= 0:
self.__remove_fact(previous['id'])
- start_time = previous['start_time']
+
+ # now that we removed the previous one, see if maybe the one
+ # before that is actually same as the one we want to start
+ # (glueing)
+ if len(facts) > 1 and 60 >= (start_time - facts[-2]['end_time']).seconds >= 0:
+ before = facts[-2]
+ if before["activity_id"] == activity_id \
+ and before["tags"] == sorted([tag["name"] for tag in tags]):
+ # essentially same activity - resume it and return
+ update = """
+ UPDATE facts
+ SET end_time = null
+ WHERE id = ?
+ """
+ self.execute(update, (before["id"],))
+
+ return before
else:
# otherwise stop
update = """
@@ -563,6 +577,14 @@ class Storage(storage.Storage):
return self.__get_fact(fact_id)
+ def __get_todays_facts(self):
+ from configuration import conf
+ day_start = conf.get("day_start_minutes")
+ day_start = dt.time(day_start / 60, day_start % 60)
+ today = (dt.datetime.now() - dt.timedelta(hours = day_start.hour,
+ minutes = day_start.minute)).date()
+ return self.__get_facts(today)
+
def __get_facts(self, date, end_date = None, search_terms = ""):
query = """
diff --git a/hamster/storage.py b/hamster/storage.py
index 3996315..e33ab50 100644
--- a/hamster/storage.py
+++ b/hamster/storage.py
@@ -73,6 +73,9 @@ class Storage(object):
def get_facts(self, date, end_date = None, search_terms = ""):
return self.__get_facts(date, end_date, search_terms)
+ def get_todays_facts(self):
+ return self.__get_todays_facts()
+
def get_popular_categories(self):
return self.__get_popular_categories()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]