# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Tabularer helps to define names for setting Tables in a hdf5 structure,
given the names of predefined models.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Modeler"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import importlib
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass(**{'ClassingSwitchMethodStrsList':['tabular']})
class TabularerClass(
BaseClass
):
#Definition
RepresentingKeyStrsList=[
'TabularedGroupVariable',
'TabularedTopFileVariable',
'TabularedSuffixStr',
'TabularedTableKeyStrsList',
'TabularedTablesOrderedDict'
]
def default_init(self,
_TabularedGroupVariable=None,
_TabularedTopFileVariable=None,
_TabularedSuffixStr="",
_TabularedTableKeyStrsList=None,
_TabularedTablesOrderedDict=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_tabular(self):
""" """
#debug
'''
self.debug(
[
('self.',self,[
'ModelingDescriptionTuplesList',
'ModeledDescriptionClass',
'WatchModelWithModelerBool',
'WatchModelWithJoinerBool'
]),
'self.model is '+SYS._str(self.model)
]
)
'''
#<NotHook>
#model first
self.model()
#</NotHook>
#debug
'''
self.debug(
[
('self.',self,['ModelingDescriptionTuplesList','ModeledDescriptionClass']),
('self.ModelDeriveControllerVariable!=None is '+str(self.ModelDeriveControllerVariable!=None))
]
)
'''
#Maybe we have to hdformat first
if self.ModelDeriveControllerVariable!=None:
#Check
if self.ModelDeriveControllerVariable.HdformatedFileVariable==None:
#debug
'''
self.debug('We have to hdformat first...')
'''
#Hdformat
self.ModelDeriveControllerVariable.hdformat()
#self.ModelDeriveControllerVariable.structure()
#Link
self.TabularedTopFileVariable=self.ModelDeriveControllerVariable.HdformatedFileVariable
self.HdfGroupPathStr=self.ModelDeriveControllerVariable.HdfGroupPathStr
#debug
'''
self.debug(('self.',self,[
'HdformatedFileVariable',
'ModelingDescriptionTuplesList',
'ModeledDescriptionClass'
]))
'''
#Check
if self.TabularedTopFileVariable!=None:
#debug
'''
self.debug(
[
'Looking for names of tables here',
('self.',self,['HdfGroupPathStr'])
]
)
'''
#Definition Tabulared attributes
self.TabularedGroupVariable=self.TabularedTopFileVariable.getNode(
self.HdfGroupPathStr)
#debug
'''
self.debug(('self.',self,['ModeledSuffixStr']))
'''
#set
self.TabularedSuffixStr='Model'.join(self.ModeledSuffixStr.split('Model')[:-1])+'Table'
#debug
'''
self.debug(
[
('looking for tables with the same suffix Str as : '),
('self.',self,['TabularedSuffixStr'])
]
)
'''
#Get and sort
self.TabularedTableKeyStrsList=sorted(
filter(
lambda __KeyStr:
__KeyStr.endswith(self.TabularedSuffixStr),
self.TabularedGroupVariable._v_leaves.keys()
)
)
self.TabularedTablesOrderedDict.update(
map(
lambda __TabularedKeyStr:
(
__TabularedKeyStr,
self.TabularedGroupVariable._f_getChild(__TabularedKeyStr)
),
self.TabularedTableKeyStrsList
)
)
#debug
'''
self.debug(("self.",self,[
'TabularedSuffixStr',
'TabularedTableKeyStrsList'
]))
'''
#<NotHook>
#Return
#return self
#</NotHook>
#</DefineClass>
View the Tabularer sources on Github
In [3]:
#ImportModules
import tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Tabularer
#Definition of a Storer instance with a noded datar
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Tabularer.TabularerClass().__setitem__(
'Attr_ModelingDescriptionTuplesList',
[
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',(tables.Int64Col(shape=3)))
]
)
)
#Build a structure with a database
MyStructurer['<Datome>ThingsTabularer'].tabular()
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print