Пример #1
0
 def add(self, s):
     verify_type(s, str)
     v = Decimal(s)
     if self.v is None:
         self.v = v
     elif self.v < v:
         self.v = v
Пример #2
0
    def add(self, rec):
        verify_type(rec, list, str)

        key = self._getKey(rec)
        if key not in self.hashMap:
            self.hashMap[key] = [x() for x in self.accGenL]

        valL = self._getSubRecord(rec, self.valIdxL)
        accL = self.hashMap[key]
        for acc, val in zip(accL, valL):
            acc.add(val)
Пример #3
0
 def _getSubRecord(self, rec, idxes):
     '''
     rec :: [str] - record
     idxes :: [int] - index list
     return :: [str] - sub record
     '''
     verify_type(rec, list, str)
     verify_type(idxes, list, [int, long])
     ret = []
     for i in idxes:
         ret.append(rec[i])
     return ret
Пример #4
0
def parseAcc(s):
    '''
    s :: str - like 'avg2', 'sum3' column index is 1-origin.
    return :: (int, Accumulator generator) - column index (0-origin) and accumulator generator.
    '''
    verify_type(s, str)
    m = re.match('([^0-9]+)([0-9]+)', s)
    if not m:
        raise RuntimeError('parse operator failed:', s)
    op = m.group(1)
    idx1 = int(m.group(2))
    if idx1 < 1:
        raise RuntimeError('bad index', op, idx1)
    d = {'avg': AccAvg, 'sum': AccSum, 'min': AccMin, 'max': AccMax, }
    if op not in d:
        raise RuntimeError('bad operator', op, idx1)
    return (idx1 - 1, d[op])
Пример #5
0
 def add(self, s):
     verify_type(s, str)
     self.c += 1
     self.v += Decimal(s)
Пример #6
0
 def __init__(self, args):
     verify_type(args, argparse.Namespace)
     self.convL, grpIdxL = unzip(pysows.getTypedColumnIndexList(args.groupIndexes))
     self.grpIdxL = [x - 1 for x in grpIdxL] # convert to 0-origin.
     self.valIdxL, self.accGenL = unzip(map(parseAcc, args.valueIndexes.split(',')))
     self.hashMap = {}