| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybDbi::mapper::Mapper Class Reference

List of all members.

Public Member Functions

def __init__
def is_valid
def smry
def automap
def convert_csv2dbi
def __call__
def __str__
def __repr__

Public Attributes

 cls
 csv_fields
 dbi_attrs
 dbi2csv
 csv2type

Static Public Attributes

tuple miss = property(lambda self:filter( lambda _:self[_]==None, self ))

Detailed Description

Establish the mapping between sets of fields (such as csv fields) and dbi attributes, usage::
 
    ckf = ['status', '_srcline', 'afterPulse', 'sigmaSpe', 'pmtID', 'efficiency', 'darkRate', '_hasblank', 'prePulse', 'speLow', 'timeOffset', 'timeSpread', 'speHigh', 'description']
    mpr = Mapper( GCalibPmtSpec, ckf , afterPulse="AfterPulseProb", sigmaSpe="SigmaSpeHigh", prePulse="PrePulseProb", description="Describ" )
    print mpr

If a mapping cannot be made, an exception is thrown that reports the partial mapping constructed.

The automapping performed is dumb by design, only case insensitively identical names are
auto mapped. Other differences between csv field names and dbi attributes must be manually provided
in the keyword arguments.

The string codetype from the spec is promoted into the corresponding python type, to enable
conversion of the csv dict (comprised of all strings) into a dbi dict with appropriate types
for the values.   

Definition at line 2 of file mapper.py.


Member Function Documentation

def DybDbi::mapper::Mapper::__init__ (   self,
  cls,
  csv_fields,
  kwargs 
)

Definition at line 4 of file mapper.py.

00021                                                   :
00022         self.cls = cls
00023 
00024         self.csv_fields = filter(lambda _:not _.startswith("_"), csv_fields)       ## remove names beginning "_" 
00025         self.dbi_attrs = map(str, cls.SpecKeys().aslist() )   ## avoid the TObjString   
00026         
00027         self.automap()
00028         self.update(kwargs)
00029 
00030         self.dbi2csv = dict([(kdbi,kcsv) for kcsv,kdbi in self.items() ])   ## reverse mapping
        

def DybDbi::mapper::Mapper::is_valid (   self  ) 

Definition at line 31 of file mapper.py.

00035                               :
            raise Exception("insufficient info to contruct mapper, partial mapping: %r ",self)

def DybDbi::mapper::Mapper::smry (   self  ) 

Definition at line 34 of file mapper.py.

00035                               :
00036             raise Exception("insufficient info to contruct mapper, partial mapping: %r ",self)
00037 
        def cast( typ ):

def DybDbi::mapper::Mapper::automap (   self  ) 

Basic auto mapping, using case insensitive comparison 
and yielding case sensitive mapping from csv fields to dbi attributes

The index of the csv fieldname in the dbi attribute list is 
found with case insensitive string comparison 

Definition at line 38 of file mapper.py.

00038                        :
00039            if typ == "int":
00040                return int
00041            elif typ == "float" or typ == "double":
00042                return float
00043            else:
00044                return str
00045 
00046         self.csv2type = dict([(self.dbi2csv[k],cast(sm[k]['codetype'])) for k in sk ])
00047  
00048     def is_valid(self):
00049         return len(self.miss) == 0 
00050 
00051     def smry(self):
00052         print repr(self)
00053         print self
00054 
00055     def automap(self):
00056         """
00057         Basic auto mapping, using case insensitive comparison 
        and yielding case sensitive mapping from csv fields to dbi attributes

def DybDbi::mapper::Mapper::convert_csv2dbi (   self,
  dcsv 
)

Translate dict with csv fieldnames into dict with dbi attr names
and appropiate types for insertion into the DBI Row cls instance 

Definition at line 60 of file mapper.py.

00064                           :_.upper()
00065         for ck in self.csv_fields:
00066            try:

def DybDbi::mapper::Mapper::__call__ (   self,
  dcsv 
)

Definition at line 67 of file mapper.py.

00068                             :
00069                idx = -1
           if idx > -1: 

def DybDbi::mapper::Mapper::__str__ (   self  ) 

Definition at line 70 of file mapper.py.

00070                       : 
00071                self[ck] = self.dbi_attrs[idx]     
00072            else:
00073                self[ck] = None
00074 
00075     miss = property(lambda self:filter( lambda _:self[_]==None, self ))

def DybDbi::mapper::Mapper::__repr__ (   self  ) 

Definition at line 76 of file mapper.py.

00077                                    :
00078         """
00079         Translate dict with csv fieldnames into dict with dbi attr names
00080         and appropiate types for insertion into the DBI Row cls instance 
        """


Member Data Documentation

tuple DybDbi::mapper::Mapper::miss = property(lambda self:filter( lambda _:self[_]==None, self )) [static]

Definition at line 58 of file mapper.py.

DybDbi::mapper::Mapper::cls

Definition at line 5 of file mapper.py.

DybDbi::mapper::Mapper::csv_fields

Definition at line 7 of file mapper.py.

DybDbi::mapper::Mapper::dbi_attrs

Definition at line 8 of file mapper.py.

DybDbi::mapper::Mapper::dbi2csv

Definition at line 13 of file mapper.py.

DybDbi::mapper::Mapper::csv2type

Definition at line 29 of file mapper.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:17:17 2011 for DybDbi by doxygen 1.4.7