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

43. class CensusTotal: Number of individuals in one category

This class is used by Section 42, “class CensusCell: Accumulator for counts of individual birds” to keep track of one of the four categories of records (regular, questionable, count-week, and questionable count-week).

It solves this problem: how do we combine unknown counts (encoded as -1 in the Census.census field) with positive counts? There may also be records with a .census field of 0, but the meaning is the same: the original periodical did not publish a number.

The .total attribute of each instance keeps track of the current state. Its values are interpreted thusly:

.total == 0 No records have been added.
.total > 0 At least one record with a positive count has been added, and .total is the sum of all the positive counts added.
.total < 0 At least one record has been added, but all records added had nonpositive counts.
cbchistlib.py
# - - - - -   c l a s s   C e n s u s T o t a l

class CensusTotal(object):
    '''Special accumulator for the different counts of individuals.

      Exports:
        CensusTotal(suffix):
          [ suffix is a string to be appended on output ->
              return a new CensusTotal with self._total = None ]
        .total:
          [ if no census records have been added to self -> 0
            else if one or more census records with positive
            numbers have been added ->
              the sum of those numbers
            else -> -1 ]
        .suffix:       [ as passed to constructor ]
        .add(nInd):
          [ nInd is a number of individuals as an int, with -1 or 0
            meaning unknown ->
              if self.total > 0 ->
                if nInd > 0 ->
                  self.total  +:=  nInd
                else -> I
              else if nInd > 0 ->
                self.total  :=  nInd
              else ->
                self.total  :=  -1 ]
        .html():
          [ if self.total > 0 ->
              return str(self.total)+self.suffix
            else if self.suffix == '':
              return '(unk)'
            else ->
              return self.suffix ]
        .__float__():
          [ if self.total is 0 -> return 0.0
            else if self.total < 0 ->
              return 1.0
            else -> return float(self._total) ]
    '''
    __slots__ = ('total', 'suffix')