Next / Previous / Contents / TCC Help System / NM Tech homepage

40. class NumberCell: Base class for numeric table cells

The purpose of this class is to provide an interface for computing means and standard deviations to a set of values in a logical row. There are two quite different types of rows with these cells, party-hours rows and census rows; this class exports the behavior shared between the two types, behavior which treats the content of the cell as a floating-point number.

cbchistlib.py
# - - - - -   c l a s s   N u m b e r C e l l

class NumberCell(Cell):
    '''Base class for cells containing values used in statistics.

      Exports:
        NumberCell():
          [ return a new NumberCell instance with no value ]
        .add(value):
          [ value has a type appropriate for the subclass ->
              if self has a value ->
                self  :=  self with (value) accumulated
              else ->
                self  :=  self with value (value) ]
        .__float__(self):         # Virtual method
          [ if self is a cell containing a number that is valid as
            input to a statistical calculation ->
              return that number as a float
            else -> return -1.0 ]
    '''
    __slots__ = ()
    def __init__(self):
        '''Constructor.
        '''
        raise NotImplementedError("NumberCell.__init__() is a "
                                  "virtual method.")
    def add(self, value):
        '''Add value to self's total.
        '''
        raise NotImplementedError("NumberCell.add() is a virtual "
                                  "method.")
    def __float__(self):
        raise NotImplementedError("NumberCell.__float__() is a "
                                  "virtual method.")