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 )) |
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.
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 | ) |
def DybDbi::mapper::Mapper::smry | ( | self | ) |
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 | ||||
) |
def DybDbi::mapper::Mapper::__call__ | ( | self, | ||
dcsv | ||||
) |
def DybDbi::mapper::Mapper::__str__ | ( | self | ) |
def DybDbi::mapper::Mapper::__repr__ | ( | self | ) |
tuple DybDbi::mapper::Mapper::miss = property(lambda self:filter( lambda _:self[_]==None, self )) [static] |