Skip to content

Commit

Permalink
Fixed statistics bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Apr 3, 1998
1 parent 57959fd commit 07c425a
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions DT_InSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
__doc__='''Sequence variables support
$Id: DT_InSV.py,v 1.1 1998/04/02 17:37:36 jim Exp $'''
__version__='$Revision: 1.1 $'[11:-2]
$Id: DT_InSV.py,v 1.2 1998/04/03 19:28:41 jim Exp $'''
__version__='$Revision: 1.2 $'[11:-2]

from string import lower, upper, rfind
from math import sqrt
Expand Down Expand Up @@ -153,13 +153,13 @@ def value(self,index,name):
if data['mapping']: return item[name]
return getattr(item,name)

def first(self,name):
def first(self,name,key=''):
data=self.data
if data['sequence-start']: return 1
index=data['sequence-index']
return self.value(index,name) != self.value(index-1,name)

def last(self,name):
def last(self,name,key=''):
data=self.data
if data['sequence-end']: return 1
index=data['sequence-index']
Expand Down Expand Up @@ -195,7 +195,7 @@ def query(self, ignored):
'variance', 'variance-n','standard-deviation', 'standard-deviation-n',
)

def statistics(self,name):
def statistics(self,name,key):
items=self.items
data=self.data
mapping=data['mapping']
Expand Down Expand Up @@ -272,10 +272,11 @@ def statistics(self,name):
try: data['median-%s' % name]=(
"between %s and %s" % (values[n],values[n-1]))
except: pass


def next_batches(self, suffix='batches'):
if suffix != 'batches': raise KeyError, 'next-batches'
return data[key]

def next_batches(self, suffix='batches',key=''):
if suffix != 'batches': raise KeyError, key
data=self.data
sequence=self.items
try:
Expand All @@ -301,8 +302,8 @@ def next_batches(self, suffix='batches'):
data['next-batches']=r
return r

def previous_batches(self, suffix='batches'):
if suffix != 'batches': raise KeyError, 'previous-batches'
def previous_batches(self, suffix='batches',key=''):
if suffix != 'batches': raise KeyError, key
data=self.data
sequence=self.items
try:
Expand Down Expand Up @@ -336,8 +337,8 @@ def previous_batches(self, suffix='batches'):
'previous': previous_batches,
'next': next_batches,
# These two are for backward compatability with a missfeature:
'sequence-index': lambda self, suffix: self['sequence-'+suffix],
'sequence-index-is': lambda self, suffix: self['sequence-'+suffix],
'sequence-index': lambda self, suffix, key: self['sequence-'+suffix],
'sequence-index-is': lambda self, suffix, key: self['sequence-'+suffix],
}
for n in statistic_names: special_prefixes[n]=statistics

Expand All @@ -358,7 +359,7 @@ def __getitem__(self,key,
return getattr(self,suffix)(data[prefix+'-index'])

if special_prefix(prefix):
return special_prefixes[prefix](self, suffix)
return special_prefixes[prefix](self, suffix, key)

if prefix[-4:]=='-var':
prefix=prefix[:-4]
Expand Down Expand Up @@ -403,6 +404,9 @@ def opt(start,end,size,orphan,sequence):
##############################################################################
#
# $Log: DT_InSV.py,v $
# Revision 1.2 1998/04/03 19:28:41 jim
# Fixed statistics bug.
#
# Revision 1.1 1998/04/02 17:37:36 jim
# Major redesign of block rendering. The code inside a block tag is
# compiled as a template but only the templates blocks are saved, and
Expand Down

0 comments on commit 07c425a

Please sign in to comment.