diff --git a/tracking/README.txt b/tracking/README.txt index 01fd4f4..893980d 100644 --- a/tracking/README.txt +++ b/tracking/README.txt @@ -7,11 +7,12 @@ User tracking in the loops framework >>> from cybertools.tracking.btree import TrackingStorage >>> tracks = TrackingStorage() - >>> runId = tracks.startRun('a001') - >>> tracks.saveUserTrack('a001', runId, 'u1', {'somekey': 'somevalue'}) + >>> tracks.saveUserTrack('a001', 0, 'u1', {'somekey': 'somevalue'}) '0000001' - >>> t1 = tracks.getUserTrack('a001', runId, 'u1') - >>> t1.data + >>> t1 = tracks.getUserTracks('a001', 0, 'u1') + >>> len(t1) + 1 + >>> t1[0].data {'somekey': 'somevalue'} >>> tracks.getUserNames('a001') ['u1'] @@ -29,6 +30,14 @@ User tracking in the loops framework >>> len(result) 2 +What happens if we store more than on record for one set of keys? + + >>> tracks.saveUserTrack('a001', 0, 'u1', {'somekey': 'newvalue'}) + '0000003' + >>> t2 = tracks.getUserTracks('a001', 0, 'u1') + >>> [t.data for t in t2] + [{'somekey': 'somevalue'}, {'somekey': 'newvalue'}] + The tracks of a tracking store may be reindexed: >>> tracks.reindexTracks() diff --git a/tracking/btree.py b/tracking/btree.py index 68992af..9b6ebd2 100644 --- a/tracking/btree.py +++ b/tracking/btree.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2005 Helmut Merz helmutm@cy55.de +# Copyright (c) 2006 Helmut Merz helmutm@cy55.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -90,11 +90,10 @@ class TrackingStorage(BTreeContainer): trackNum = int(trackId) self.indexTrack(trackNum, self[trackId]) - def getUserTrack(self, taskId, runId, userName): + def getUserTracks(self, taskId, runId, userName): if not runId: runId = self.currentRuns.get(taskId) - tracks = self.query(taskId=taskId, runId=runId, userName=userName) - return tracks and tracks[0] or None + return self.query(taskId=taskId, runId=runId, userName=userName) def query(self, **kw): result = None diff --git a/tracking/interfaces.py b/tracking/interfaces.py index 604c20f..26548cb 100644 --- a/tracking/interfaces.py +++ b/tracking/interfaces.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2005 Helmut Merz helmutm@cy55.de +# Copyright (c) 2006 Helmut Merz helmutm@cy55.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -58,9 +58,9 @@ class ITrackingStorage(Interface): userName, timeFrom, timeTo. """ - def getUserTrack(taskId, runId, userName): - """ Return the user track data corresponding to the user name and - task id given. If no run id is given use the current one. + def getUserTracks(taskId, runId, userName): + """ Return the user tracks corresponding to the user name and + task id given. If a 0 run id is given use the current one. """ def getUserNames(taskId):