cybertools/tracking
helmutm ac2a48f72f minor improvement on stopRun()
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1529 fd906abe-77d9-0310-91a1-e0d9ade77398
2006-11-27 16:36:24 +00:00
..
__init__.py added cybertools.tracking (ported from yeepa) 2006-10-23 08:26:50 +00:00
btree.py minor improvement on stopRun() 2006-11-27 16:36:24 +00:00
interfaces.py bug fixes and extensions for cybertools.tracking 2006-11-27 12:49:24 +00:00
README.txt bug fixes and extensions for cybertools.tracking 2006-11-27 12:51:13 +00:00
tests.py added cybertools.tracking (ported from yeepa) 2006-10-23 08:26:50 +00:00

====================================
User tracking in the loops framework
====================================

  ($Id$)

  >>> from cybertools.tracking.btree import TrackingStorage

  >>> tracks = TrackingStorage()
  >>> tracks.saveUserTrack('a001', 0, 'u1', {'somekey': 'somevalue'})
  '0000001'
  >>> t1 = tracks.getUserTracks('a001', 0, 'u1')
  >>> len(t1)
  1
  >>> t1[0].data
  {'somekey': 'somevalue'}
  >>> tracks.getUserNames('a001')
  ['u1']
  >>> tracks.getUserNames('a002')
  []
  >>> [str(id) for id in tracks.getTaskIds()]
  ['a001']

  >>> tracks.query(taskId='a001')
  [<Track ['a001', 1, 'u1', '...-...-... ...:...']: {'somekey': 'somevalue'}>]

  >>> tracks.saveUserTrack('a002', 0, 'u1', {'somekey': 'anothervalue'})
  '0000002'
  >>> result = tracks.query(userName='u1')
  >>> 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'}]

It is also possible to retrieve the last entry for a set of keys directliy:

  >>> tracks.getLastUserTrack('a001', 0, 'u1')
  <Track ['a001', 1, 'u1', ...]: {'somekey': 'newvalue'}>

Instead of creating a new track object for each call one can also replace
an existing one (if present). The replaced entry is always the last one
for a given set of keys:

  >>> tracks.saveUserTrack('a001', 0, 'u1', {'somekey': 'newvalue2'}, replace=True)
  '0000003'
  >>> t3 = tracks.getUserTracks('a001', 0, 'u1')
  >>> [t.data for t in t3]
  [{'somekey': 'somevalue'}, {'somekey': 'newvalue2'}]

  >>> tracks.saveUserTrack('a001', 0, 'u2', {'somekey': 'user2'}, replace=True)
  '0000004'
  >>> t4 = tracks.getUserTracks('a001', 0, 'u2')
  >>> [t.data for t in t4]
  [{'somekey': 'user2'}]

The tracks of a tracking store may be reindexed:

  >>> tracks.reindexTracks()


Fin de partie
=============