Permalink
Browse files

fixed lua global variables

  • Loading branch information...
1 parent b070b08 commit d88c3d892533e8d1ff96762a9402b52cc8053a55 quantmind committed May 8, 2012
View
@@ -50,7 +50,7 @@ Ver. 0.7c3 - 2012 May 02
* Added :mod:`stdnet.utils.path`.
* Added a Lua test suite for testing stand alone scripts. Requires lunatest_.
* PEP 386-compliant version number.
-* **572 regression tests** with **90%** coverage.
+* **573 regression tests** with **90%** coverage.
.. _vers06:
@@ -4,9 +4,18 @@
Redis data-structure server.
It is designed to be fast, memory efficient and highly customizable.
</p>
+<g:plusone annotation="inline"></g:plusone>
+<script type="text/javascript">
+ (function() {
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
+ po.src = 'https://apis.google.com/js/plusone.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
+ })();
+</script>
<h3>Useful Links</h3>
<ul>
<li><a href="http://pypi.python.org/pypi/python-stdnet">Stdnet @ PyPI</a></li>
<li><a href="https://github.com/lsbardel/python-stdnet">Stdnet @ github</a></li>
<li><a href="http://twitter.com/lsbardel">lsbardel @ twitter</a></li>
+ <li><a href="https://groups.google.com/forum/?fromgroups#!forum/python-stdnet">email list @ google</a></li>
</ul>
View
@@ -4,16 +4,15 @@
import sys
import os
-from stdnet.conf import settings
-from stdnet.utils import Path
-from stdnet import test, getdb
-
## This is for dev environment with pulsar and dynts.
## If not available, some tests won't run
+from stdnet.utils import Path
p = Path(__file__)
p.add2python('pulsar', up=1, down=('pulsar',), must_exist=False)
p.add2python('dynts', up=1, down=('dynts',), must_exist=False)
+from stdnet.conf import settings
+from stdnet import test, getdb
from stdnet.test import nose, pulsar
View
@@ -29,4 +29,4 @@
'Topic :: Internet'
]
-sphinxtogithub = True
+sphinxtogithub = False
@@ -1,8 +1,11 @@
'''\
-A timeseries application where each field is stored in a redis string.
-This data-structure is composed by several redis structure:
+An application for managing multivariate timeseries_. It provides
+tools for performing aggregation and statistics via lua scripts.
-* A Timeseries for holding times in an ordered fashion.
+The redis implementation uses several redis structures for a given
+class:`ColumnTS` instance:
+
+* A zset for holding times in an ordered fashion.
* A redis *set* for holding *fields* names.
* A redis string for each *field* in the timeseries.
@@ -17,8 +20,7 @@
from datetime date
from stdnet.apps.columnts ColumnTS
- ts = ColumnTS(id = 'test')
-
+ ts = ColumnTS(id='test')
ts.add(date(2012,2,21), {'open': 603.87, 'close': 614.00})
API
@@ -28,6 +30,7 @@
:members:
:member-order: bysource
+.. _timeseries: http://en.wikipedia.org/wiki/Time_series
'''
from . import redis
from .encoders import *
@@ -9,6 +9,7 @@
__all__ = ['TimeseriesCache', 'ColumnTS', 'ColumnTSField']
+
class TimeseriesCache(object):
cache = None
def __init__(self):
@@ -30,6 +31,8 @@ def clear(self):
class ColumnTS(odm.TS):
+ '''A specialised timeseries structure for handling several fields and
+statistical calculations.'''
default_multi_stats = ['covariance']
cache_class = TimeseriesCache
@@ -1,6 +1,8 @@
'''Experimental!
This is an experimental module for converting ColumnTS into
-dynts.timeseries.
+dynts.timeseries. It requires dynts_.
+
+.. _dynts: https://github.com/quantmind/dynts
'''
from . import models as columnts
@@ -6,8 +6,8 @@
from stdnet.lib import redis
-class RedisColumnTS(redisb.TS):
-
+class RedisColumnTS(redisb.Zset):
+ '''Redis backend for :class:`ColumnTS`'''
@property
def fieldsid(self):
return self.id + ':fields'
@@ -25,6 +25,9 @@ def flush(self):
keys, args = cache.merged_series
return self.client.script_call('timeseries_merge', keys, *args)
+ def _iter(self):
+ return iter(self.irange(novalues=True))
+
def allkeys(self):
return self.client.keys(self.id + '*')
@@ -44,21 +47,21 @@ def numfields(self):
'''Number of fields'''
return self.client.scard(self.fieldsid)
- def irange(self, start = 0, end = -1, fields = None, novalues = False,
- delete = False):
+ def irange(self, start = 0, end = -1, fields=None, novalues=False,
+ delete=False, **kwargs):
noval = 1 if novalues else 0
fields = fields or ()
delete = 1 if delete else 0
return self.client.script_call(
- 'timeseries_query', self.id, 'tsrange',
+ 'timeseries_query', self.id, 'zrange',
start, end, noval, delete, len(fields),
- *fields, fields = fields, novalues = novalues)
+ *fields, fields = fields, novalues=novalues)
- def range(self, start, end, fields = None, novalues = False):
+ def range(self, start, end, fields=None, novalues=False, **kwargs):
noval = 1 if novalues else 0
fields = fields or ()
return self.client.script_call(
- 'timeseries_query', self.id,'tsrangebytime',
+ 'timeseries_query', self.id, 'zrangebyscore',
start, end, noval, 0, len(fields), *fields,
fields = fields, novalues = novalues)
@@ -97,18 +100,18 @@ def merge(self, series, fields):
def istats(self, start, end, fields = None):
fields = fields or ()
return self.client.script_call('timeseries_stats', self.id,
- 'tsrange', start, end, 'uni', len(fields), *fields)
+ 'zrange', start, end, 'uni', len(fields), *fields)
def stats(self, start, end, fields = None):
fields = fields or ()
return self.client.script_call('timeseries_stats', self.id,
- 'tsrangebytime', start, end, 'uni', len(fields), *fields)
+ 'zrangebyscore', start, end, 'uni', len(fields), *fields)
def imulti_stats(self, start, end, fields, series, stats):
- return self._multi_stats('tsrange', start, end, fields, series, stats)
+ return self._multi_stats('zrange', start, end, fields, series, stats)
def multi_stats(self, start, end, fields, series, stats):
- return self._multi_stats('tsrangebytime', start, end, fields, series,
+ return self._multi_stats('zrangebyscore', start, end, fields, series,
stats)
def _multi_stats(self, command, start, end, fields, series, stats):
@@ -136,6 +139,8 @@ def _multi_stats(self, command, start, end, fields, series, stats):
redisb.BackendDataServer.struct_map['columnts'] = RedisColumnTS
+############################################################## SCRIPTS
+
class timeseries_session(redis.RedisScript):
script = (redis.read_lua_file('tabletools'),
redis.read_lua_file('columnts.columnts'),
@@ -476,15 +476,15 @@ def flush(self):
return result
def get(self, score):
- r = self.range(score,score,withscores=False)
+ r = self.range(score, score, withscores=False)
if r:
if len(r) > 1:
return r
else:
return r[0]
def _iter(self):
- return iter(self.irange(withscores = False))
+ return iter(self.irange(withscores=False))
def size(self):
return self.client.zcard(self.id)
View
@@ -66,13 +66,13 @@ def __init__(self):
def redis_status(self):
from stdnet import getdb
- from stdnet.lib.redis import ConnectionError
+ from stdnet.lib.redis import RedisConnectionError
db = getdb(self.DEFAULT_BACKEND)
status = "ok"
if db.name == 'redis':
status = db.client.redis_status()
if not status:
- raise ConnectionError('No connection available for server\
+ raise RedisConnectionError('No connection available for server\
at "{0}"'.format(self.DEFAULT_BACKEND))
os.environ['stdnet_backend_status'] = status
return status
View
@@ -3,63 +3,86 @@ class StdNetException(Exception):
'''A general StdNet exception'''
pass
+
+class ConnectionError(StdNetException):
+ pass
+
+
class SessionNotAvailable(StdNetException):
pass
+
class ModelNotAvailable(StdNetException):
pass
+
class ModelNotRegistered(SessionNotAvailable):
'''A :class:`StdNetException` raised when trying to save an instance of a :class:`stdnet.odm.StdModel` not yet
registered with a :class:`stdnet.backends.BackendDataServer`. Check :func:`stdnet.odm.register` for details.'''
pass
+
class InvalidTransaction(StdNetException):
'''A :class:`StdNetException` raised when trying to create a transaction
with models registered with different backends.'''
pass
-class CommitException(StdNetException):
+
+class ResponseError(StdNetException):
+ '''Raised when an invalid response is returned from the backebd server.'''
+ pass
+
+
+class CommitException(ResponseError):
'''A :class:`StdNetException` raised when trying to create a transaction
with models registered with different backends.'''
def __init__(self, msg, failures = 1):
self.failures = failures
super(CommitException,self).__init__(msg)
+
class AlreadyRegistered(StdNetException):
pass
+
class ObjectNotValidated(StdNetException):
'''A :class:`StdNetException` raised when an instance of a :class:`stdnet.odm.StdModel` fails to validate
(probably required :class:`stdnet.odm.Field` are missing from the instance).'''
pass
+
class ImproperlyConfigured(StdNetException):
"A :class:`stdnet.StdNetException` raised when stdnet is somehow improperly configured"
pass
+
class BadCacheDataStructure(StdNetException):
pass
+
class FieldError(StdNetException):
'''Generic Field error'''
pass
+
class StructureFieldError(StdNetException):
'''A :class:`stdnet.FieldError` for :class:stdnet.odm.StructureField`.'''
pass
+
class FieldValueError(FieldError):
'''A :class:`stdnet.FieldError` raised when passing a wrong
value to a field. This exception is cought during the model instance
validation algorithm in :meth:`stdnet.odm.base.Metaclass.is_valid`.'''
pass
+
class QuerySetError(StdNetException):
'''A :class:`stdnet.StdNetException` raised during a :class:`stdnet.odm.query.QuerySet`
evaluation.'''
pass
+
class ObjectNotFound(QuerySetError):
'''A :class:`QuerySetError` raised when an object is not found.'''
pass
@@ -1,4 +1,4 @@
-hasextensions = True
+hasextensions = False
hr = None
from .fallback import *
from . import fallback
Oops, something went wrong.

0 comments on commit d88c3d8

Please sign in to comment.