Permalink
Browse files

info method in apps.columnts to return start and stop date

  • Loading branch information...
1 parent 4e5e8f9 commit 6b1d5d6c4654c2a59a257fde53b33de708967c35 quantmind committed Aug 21, 2012
Showing with 23 additions and 8 deletions.
  1. +5 −4 stdnet/apps/columnts/models.py
  2. +4 −0 stdnet/lib/lua/columnts/columnts.lua
  3. +14 −4 tests/regression/columnts/readonly.py
@@ -40,17 +40,18 @@ def front(self, *fields):
'''Return the front pair of the structure'''
v,f = tuple(self.irange(0, 0, fields=fields))
if v:
- return (v[0],dict(((field,f[field][0]) for field in f)))
+ return (v[0],dict(((field, f[field][0]) for field in f)))
def back(self, *fields):
'''Return the back pair of the structure'''
v,f = tuple(self.irange(-1, -1, fields=fields))
if v:
- return (v[0],dict(((field,f[field][0]) for field in f)))
+ return (v[0],dict(((field, f[field][0]) for field in f)))
def info(self):
'''Provide information for this :class:`ColumnTS`.'''
- return self.backend_structure().info()
+ res = self.backend_structure().info()
+ return self.async_handle(res, self._stats)
def fields(self):
'''Tuple of ordered fields for this :class:`ColumnTS`.'''
@@ -179,7 +180,7 @@ def load_get_data(self, result):
return dict(((f, vloads(v)) for f, v in iterpair(result)))
def _stats(self, result):
- if result:
+ if result and 'start' in result:
result['start'] = self.pickler.loads(result['start'])
result['stop'] = self.pickler.loads(result['stop'])
return result
@@ -364,6 +364,10 @@ local columnts = {
local size = # times
local result = {size=size, fields={}}
if size > 0 then
+ result['start'] = times[1]
+ result['stop'] = times[size]
+ end
+ if size > 0 then
for field, data in pairs(field_values) do
local f = {}
local missing = 0
@@ -12,18 +12,28 @@ def testInfoSimple(self):
ts = session.add(ColumnTS(id='goog'))
info = ts.info()
self.assertEqual(info['size'], 0)
- ts.update({date(2012,5,15): {'open':605},
- date(2012,5,16): {'open':617}})
+ self.assertFalse('start' in info)
+ d1 = date(2012, 5, 15)
+ d2 = date(2012, 5, 16)
+ ts.update({d1: {'open':605},
+ d2: {'open':617}})
info = ts.info()
self.assertEqual(info['size'], 2)
self.assertEqual(info['fields']['open']['missing'], 0)
- ts.update({date(2012,5,14): {'open':nan,'close':607},
- date(2012,5,13): {'open':nan,'close':nan}})
+ self.assertEqual(info['start'].date(), d1)
+ self.assertEqual(info['stop'].date(), d2)
+ d3 = date(2012,5,14)
+ d4 = date(2012,5,13)
+ ts.update({d3: {'open':nan,'close':607},
+ d4: {'open':nan,'close':nan}})
info = ts.info()
self.assertEqual(info['size'], 4)
+ self.assertEqual(info['start'].date(), d4)
+ self.assertEqual(info['stop'].date(), d2)
self.assertEqual(info['fields']['open']['missing'], 2)
self.assertEqual(info['fields']['close']['missing'], 3)
+
def __test(self):
ts.update({date(2012,5,15): {'open':605},
date(2012,5,16): {'open':617}})

0 comments on commit 6b1d5d6

Please sign in to comment.