A Databaser rises to the DatabaserClass. This latter is the deepest class for instancing Variables able to store values in hierarchic tables. Here, as a first step, the database method helps to set the
in the dict
View the Databaser notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Databaser.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
A Databaser rises to the DatabaserClass. This latter is the deepest class for instancing
Variables able to store values in hierarchic tables. Here, as a first step,
the database method helps to set the <ModelingKeyStr> in the __dict__
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Noders.Structurer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass(**{'ClassingSwitchMethodStrsList':['database']})
class DatabaserClass(
BaseClass
):
#Definition
RepresentingKeyStrsList=[
'ModeledSuffixStr',
'ModeledCollectionStr',
'ModeledSuffixStr',
'ModelDeriveControllerVariable'
]
def default_init(self,
_ModelingKeyStr="",
_ModeledCollectionStr="",
_ModeledSuffixStr="",
_ModelDeriveControllerVariable=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_database(self):
#set
if hasattr(self,'NodeKeyStr'):
self.ModelingKeyStr=self.NodeKeyStr
self.ModeledCollectionStr=self.NodeCollectionStr
#set
self.ModeledSuffixStr=self.ModelingKeyStr+'Model'
#
if hasattr(self,'NodePointDeriveNoder'):
self.point(
self.NodePointDeriveNoder,
'ModelDeriveControllerVariable'
)
#</DefineClass>
View the Databaser sources on Github
In [3]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Controllers import Storer
from ShareYourSystem.Standards.Modelers import Databaser
#Definition of a Storer instance with a noded databaser
MyStorer=Storer.StorerClass().collect(
"Datome",
"Things",
Databaser.DatabaserClass()
)
#database
MyStorer['<Datome>ThingsDatabaser'].database()
#Definition the AttestedStr
SYS._attest(
[
'MyStorer is '+SYS._str(
MyStorer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
)
]
)
#Print
The Modeler defines the model to be stored in a database like Django or PyTable. Here are defined the relations between attributes of an instance and their corresponding types in the databased structures.
View the Modeler notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Modeler.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Modeler defines the model to be stored in a database like Django or PyTable.
Here are defined the relations between attributes of an instance and their corresponding
types in the databased structures.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Databaser"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import copy
import tables
from ShareYourSystem.Standards.Classors import Doer
#</ImportSpecificModules>
#<DefineLocals>
AnalyzingColStrsList=[
'Int',
'Float',
'Str'
]
ModelingJoinStr='__'
ModelingLinkStr='_'
#</DefineLocals>
#<DefineFunctions>
def getModeledColWithGetKeyStr(_GetKeyStr):
#Definition
global AnalyzingColStrsList
#Definition
ModeledColStr=SYS._filter(
lambda __AnalyzingColStr:
_GetKeyStr.endswith(__AnalyzingColStr),
AnalyzingColStrsList
)[0]
#Get the Col Class
ModeledColClass=getattr(tables,ModeledColStr+'Col')
#Return
if _GetKeyStr=='Str':
return ModeledColClass(length=100)
else:
return ModeledColClass()
def getModelingColumnTupleWithGetKeyStr(_GetKeyStr):
return (_GetKeyStr,_GetKeyStr,getModeledColWithGetKeyStr(_GetKeyStr))
#</DefineFunctions>
#<DefineClass>
@DecorationClass(**{
'ClassingSwitchMethodStrsList':["model"]
})
class ModelerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'ModelingDescriptionTuplesList',
'ModeledDescriptionClassesOrderedDict',
'ModeledDescriptionClass',
'ModeledKeyStr'
]
def default_init(
self,
_ModelingDescriptionTuplesList={
'DefaultValueType':property,
'PropertyInitVariable':[],
'PropertyDocStr':''
},
_ModeledDescriptionClassesOrderedDict=None,
_ModeledDescriptionClass=None,
_ModeledKeyStr="",
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_model(self):
""" """
#debug
'''
self.debug(('self.',self,['ModelingDescriptionTuplesList']))
'''
#<NotHook>
#database first
self.database()
#</NotHook>
#set a name if it was not already
if self.ModeledKeyStr=="":
#debug
'''
self.debug(('self.',self,['ModelingKeyStr','ModeledSuffixStr']))
'''
#Link set
self.ModeledKeyStr=self.ModeledSuffixStr
#Definition the ModelClass
class ModeledDescriptionClass(tables.IsDescription):
#Add a tabulared Int (just like a unique KEY in mysql...)
RowInt=tables.Int64Col()
#debug
'''
self.debug(('self.',self,['ModeledGetStrToColumnStrOrderedDict']))
'''
#set the cols in the ModelClass
map(
lambda __ModelingColumnTuple:
ModeledDescriptionClass.columns.__setitem__(
__ModelingColumnTuple[1],
__ModelingColumnTuple[2]
),
self.ModelingDescriptionTuplesList
)
#Give a name
ModeledDescriptionClass.__name__=SYS.getClassStrWithNameStr(self.ModeledKeyStr)
#set the ModelClass
if self.ModeledDescriptionClassesOrderedDict==None:
self.ModeledDescriptionClassesOrderedDict=collections.OrderedDict()
self.ModeledDescriptionClassesOrderedDict[self.ModeledKeyStr]=ModeledDescriptionClass
#set the ModeledDescriptionClass
self.ModeledDescriptionClass=ModeledDescriptionClass
#</DefineClass>
View the Modeler sources on Github
In [7]:
#ImportModules
import tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Collecter
from ShareYourSystem.Standards.Modelers import Modeler
#Definition of a Collecter instance with a noded datar
MyCollecter=Collecter.CollecterClass().collect(
"Datome",
"Things",
Modeler.ModelerClass()
)
#Definition a Modeler instance
MyCollecter['<Datome>ThingsModeler'].model([
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',tables.Int64Col(shape=3))
])
#Definition the AttestedStr
SYS._attest(
[
'MyCollecter is '+SYS._str(
MyCollecter,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'MyCollecter["<Datome>ThingsModeler"].ModeledDescriptionClass.__dict__ is '+SYS._str(
dict(MyCollecter['<Datome>ThingsModeler'].ModeledDescriptionClass.__dict__.items()
) if MyCollecter['<Datome>ThingsModeler'
].ModeledDescriptionClass!=None else {},**{'RepresentingAlineaIsBool':False}
)
]
)
#Print
# -*- 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 [11]:
#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
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Tabler defines TablesClass instances able to set in a hdf5 structure
a table at a certain node, taking in account the order of already created tables.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Tabularer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
#</ImportSpecificModules>
#<DefineLocals>
TablingOrderStr='xx'
#</DefineLocals>
#<DefineClass>
@DecorationClass(**{'ClassingSwitchMethodStrsList':['table']})
class TablerClass(
BaseClass,
):
#Definition
RepresentingKeyStrsList=[
'TabledKeyStr',
'TabledInt',
'TabledTable'
]
def default_init(self,
_TabledKeyStr="",
_TabledInt=-1,
_TabledTable=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_table(self):
#debug
'''
self.debug(('self.',self,['ModelingDescriptionTuplesList']))
'''
#<NotHook>
#tabular first
self.tabular()
#</NotHook>
#debug
'''
self.debug(
[
'We are going to look if this is a new table or not...In order to index it',
('self.',self,[
'ModeledKeyStr',
'ModeledDescriptionClass',
'TabularedTableKeyStrsList',
'TabularedSuffixStr',
'TabledKeyStr'
])
]
)
'''
#Get the suffix Strs of all the tables and their index
TabledList=SYS.unzip(map(
lambda __StrsList:
(
__StrsList[1],
TablingOrderStr.join(__StrsList[2:])
),
map(
lambda __TabledKeyStr:
__TabledKeyStr.split(TablingOrderStr),
self.TabularedTableKeyStrsList
)
),[0,1])
#debug
'''
self.debug(('vars ',vars(),['TabledList']))
'''
#Unpack if it is possible
if len(TabledList)>0:
#Unpack
[TabledIntsTuple,TabledSuffixStrsList]=TabledList
#debug
'''
self.debug(
[
'There are already some tables',
'TabledSuffixStrsList is '+str(TabledSuffixStrsList),
"self.TabularedSuffixStr is "+str(
self.TabularedSuffixStr)
]
)
'''
if self.TabularedSuffixStr not in TabledSuffixStrsList:
#Increment the IndexStr
IndexInt=max(map(int,TabledIntsTuple))+1
#Strify
IndexStr=str(IndexInt)
#debug
'''
self.debug('IndexStr of this new table is '+str(IndexStr))
'''
else:
#Get the already setted one
IndexStr=self.TabularedTableKeyStrsList[
TabledSuffixStrsList.index(self.TabularedSuffixStr)
].split(TablingOrderStr)[1]
#Intify
IndexInt=(int)(IndexStr)
#debug
'''
self.debug('IndexStr of this not new table is '+str(IndexStr))
'''
else:
#debug
'''
self.debug('There are no tables here')
'''
#set to empty lists
[TabledIntsTuple,TabledSuffixStrsList]=[[],[]]
#Init the list
IndexInt=0
#Strify
IndexStr="0"
#Bind with TabledKeyStr setting
self.TabledKeyStr=TablingOrderStr+IndexStr+TablingOrderStr+self.TabularedSuffixStr
#set the TabularedInt
self.TabledInt=IndexInt
#debug
'''
self.debug("self.TabledKeyStr is "+str(self.TabledKeyStr))
'''
#debug
'''
self.debug(
[
'Here we create the table or get it depending if it is new or not',
'self.TabledKeyStr is '+self.TabledKeyStr,
'self.TabularedTopFileVariable!=None is '+str(self.TabularedTopFileVariable!=None)
]
)
'''
#Check
if self.TabledKeyStr!="" and self.TabularedTopFileVariable!=None:
#debug
'''
self.debug(
[
('self.',self,['TabledKeyStr','TabularedTableKeyStrsList'])
]
)
'''
#Create the Table if not already
if self.TabledKeyStr not in self.TabularedTableKeyStrsList:
#debug
'''
self.debug(
[
'The table not exists',
]
)
'''
#Create the Table in the hdf5
self.TabledTable=self.TabularedTopFileVariable.create_table(
self.TabularedGroupVariable,
self.TabledKeyStr,
self.ModeledDescriptionClass,
self.ModeledDescriptionClass.__doc__
if self.ModeledDescriptionClass.__doc__!=None
else "This is the "+self.ModeledDescriptionClass.__name__
)
#Append in the self.ModeledDict['TabularedTableKeyStrsList']
self.TabularedTableKeyStrsList.append(self.TabledKeyStr)
else:
#debug
'''
self.debug(
[
'The table exists',
"self.TabularedGroupVariable is "+str(self.TabularedGroupVariable)
]
)
'''
#Else just get it
self.TabledTable=self.TabularedGroupVariable._f_getChild(self.TabledKeyStr)
#set the in the TablesOrderedDict
self.TabularedTablesOrderedDict[self.TabledKeyStr]=self.TabledTable
#debug
'''
self.debug("self.TabularedTablesOrderedDict is "+str(self.TabularedTablesOrderedDict))
'''
#debug
'''
self.debug(
[
'Table is done here...',
('self.',self,['TabledTable','TabularedTopFileVariable'])
]
)
'''
#<NotHook>
#Return
#return self
#</NotHook>
#</DefineClass>
View the Tabler sources on Github
In [15]:
#ImportModules
import tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Tabler
#Definition of a Structurer instance with a noded datar
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Tabler.TablerClass().__setitem__(
'Attr_ModelingDescriptionTuplesList',
[
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',(tables.Int64Col(shape=3)))
]
)
)
#Tabular in it
MyStructurer['<Datome>ThingsTabler'].table()
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Rower helps to set rowed lines in a Databaser from pointed attributes,
ready then to be inserted in a table.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Tabler"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import copy
#</ImportSpecificModules>
#<DefineFunctions>
def getRowedDictsListWithTable(_Table):
return map(
lambda __Row:
dict(
zip(
_Table.colnames,
map(
lambda __ColumnStr:
__Row[__ColumnStr],
_Table.colnames
)
)
),
_Table.iterrows()
)
#</DefineFunctions>
#<DefineClass>
@DecorationClass(
#**{'ClassingSwitchMethodStrsList':["row"]}
)
class RowerClass(
BaseClass
):
#Definition
RepresentingKeyStrsList=[
'RowingKeyStrsList',
'RowedGetStrToColumnStrOrderedDict',
'RowedColumnStrsList',
'RowedPickOrderedDict',
'RowedIsBoolsList',
'RowedIsBool',
'RowedIndexInt'
]
def default_init(
self,
_RowingKeyStrsList={
'DefaultValueType':property,
'PropertyInitVariable':[],
'PropertyDocStr':''
},
_RowedGetStrToColumnStrOrderedDict=None,
_RowedColumnStrsList=None,
_RowedPickOrderedDict=None,
_RowedIsBoolsList=None,
_RowedIsBool=False,
_RowedIndexInt=-1,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def setModelingDescriptionTuplesList(self,_SettingValueVariable):
#debug
'''
self.debug(
[
'Before setting ModelingDescriptionTuplesList',
('self.',self,['ModelingDescriptionTuplesList']),
'_SettingValueVariable is '+str(_SettingValueVariable)
]
)
'''
#set
self._ModelingDescriptionTuplesList=_SettingValueVariable
#debug
'''
self.debug(
[
'After',
('self.',self,['ModelingDescriptionTuplesList']),
'We bind with RowedGetStrToColumnStrOrderedDict setting',
]
)
'''
#Bind with RowedGetStrToColumnStrOrderedDict setting
self.RowedGetStrToColumnStrOrderedDict=collections.OrderedDict(
map(
lambda _ModelingSealTuple:
(_ModelingSealTuple[0],_ModelingSealTuple[1]),
self._ModelingDescriptionTuplesList
)
)
#debug
'''
self.debug(
[
('self.',self,['RowedGetStrToColumnStrOrderedDict'])
]
)
'''
ModelingDescriptionTuplesList=property(
BaseClass.ModelingDescriptionTuplesList.fget,
setModelingDescriptionTuplesList,
BaseClass.ModelingDescriptionTuplesList.fdel,
BaseClass.ModelingDescriptionTuplesList.__doc__
)
def setRowingKeyStrsList(self,_SettingValueVariable):
#debug
'''
self.debug('_SettingValueVariable '+str(_SettingValueVariable))
'''
#set
self._RowingKeyStrsList=_SettingValueVariable
#debug
'''
self.debug(
[
'bind with RowedColumnStrsList setting',
('self.',self,['RowedGetStrToColumnStrOrderedDict'])
]
)
'''
#Bind with
self.RowedColumnStrsList=map(
lambda __RowingGetStr:
self.RowedGetStrToColumnStrOrderedDict[__RowingGetStr],
_SettingValueVariable
)
#debug
'''
self.debug(('self.',self,['RowedColumnStrsList']))
'''
#@Alerter.AlerterClass()
#@Hooker.HookerClass(**{'HookingBeforeVariablesList':[{'CallingMethodStr':"table"}]})
def do_row(self):
""""""
#<NotHook>
#table then
self.table()
#</NotHook>
#Check
if self.NodePointDeriveNoder!=None:
#debug
'''
self.NodePointDeriveNoder.debug('ParentSpeaking...')
'''
#Update
self.RowedPickOrderedDict.update(
zip(
self.RowedColumnStrsList,
self.NodePointDeriveNoder.pick(self.RowingKeyStrsList)
)
)
#debug
'''
self.debug(('self.',self,[
'RowedPickOrderedDict',
'TabledTable'
]))
'''
#Check if it was already rowed
self.RowedIsBoolsList=map(
lambda __Row:
all(
map(
lambda __RowedItemTuple:
SYS.getIsEqualBool(
__Row[__RowedItemTuple[0]],
__RowedItemTuple[1]
),
self.RowedPickOrderedDict.items()
)
),
self.TabledTable.iterrows()
)
#debug
'''
self.debug(('self.',self,['RowedIsBoolsList']))
'''
#set
if len(self.RowedIsBoolsList)==0:
self.RowedIsBool=False
else:
self.RowedIsBool=any(self.RowedIsBoolsList)
#Init to the len of the table
self.RowedIndexInt=self.TabledTable.nrows
#But maybe find a last index
if self.RowedIsBool:
if len(self.RowedIsBoolsList)>0:
self.RowedIndexInt=self.RowedIsBoolsList.index(True)
#debug
'''
self.debug(('self.',self,['RowedIsBool','RowedIndexInt']))
'''
#<NotHook>
#Return self
#return self
#</NotHook>
#</DefineClass>
View the Rower sources on Github
In [19]:
#ImportModules
import tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Rower
#Definition of a Structurer instance with a noded datar
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Rower.RowerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',(tables.Int64Col(shape=3)))
]
),
('Attr_RowingKeyStrsList',['MyInt'])
]
)
)
#Tabular in it
MyStructurer.update(
[
('MyInt',0),
('MyStr',"hello"),
('MyIntsList',[2,4,1])
])['<Datome>ThingsRower'].row()
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Inserter instances can insert a RowedVariablesList into a table
checking maybe before if this line is new in the table or not
depending on identifying items.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
import collections
BaseModuleStr="ShareYourSystem.Standards.Modelers.Rower"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class InserterClass(
BaseClass,
):
#Definition
RepresentingKeyStrsList=[
'InsertedNotRowGetStrsList',
'InsertedNotRowColumnStrsList',
'InsertedNotRowPickOrderedDict',
'InsertedIndexInt'
]
def default_init(self,
_InsertedNotRowGetStrsList=None,
_InsertedNotRowColumnStrsList=None,
_InsertedNotRowPickOrderedDict=None,
_InsertedIndexInt=-1,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def setRowingKeyStrsList(self,_SettingValueVariable):
#Hook
BaseClass.setRowingKeyStrsList(self,_SettingValueVariable)
#Bind
self.InsertedNotRowGetStrsList=list(set(SYS.unzip(
self.ModelingDescriptionTuplesList,[0]
))-set(self.RowingKeyStrsList))
#set
self.InsertedNotRowColumnStrsList=map(
lambda __NotRowGetStr:
self.RowedGetStrToColumnStrOrderedDict[__NotRowGetStr],
self.InsertedNotRowGetStrsList
)
RowingKeyStrsList=property(
BaseClass.RowingKeyStrsList.fget,
setRowingKeyStrsList,
BaseClass.RowingKeyStrsList.fdel,
BaseClass.RowingKeyStrsList.__doc__
)
def do_insert(self):
""" """
#debug
'''
self.debug('row maybe before...')
'''
#<NotHook>
#row first
self.row()
#</NotHook>
#debug
'''
self.debug(
('self.',self,['RowedIsBool'])
)
self.NodePointDeriveNoder.debug([
('NOTE : ...ParentSpeaking...')
])
'''
"""
map(
lambda __InitVariable:
setattr(
self,
__KeyStr,
SYS.getInitiatedVariableWithKeyStr(__KeyStr)
) if __InitVariable==None else None,
map(
lambda __KeyStr:
(
__KeyStr,
getattr(self,__KeyStr)
),
[
'InsertedNotRowPickOrderedDict',
'InsertedNotRowGetStrsList',
'InsertedNotRowGetStrsList',
'InsertedNotRowPickOrderedDict'
]
)
)
"""
#debug
'''
self.debug(('self.',self,['InsertedNotRowPickOrderedDict']))
'''
#Append and row if it is new
if self.RowedIsBool==False:
#Check
if self.TabledTable!=None:
#debug
'''
self.debug('This is a new row')
'''
#Get the row
Row=None
Row=self.TabledTable.row
#debug
'''
self.debug(('self.',self,['InsertedNotRowPickOrderedDict']))
'''
#Pick and update
self.InsertedNotRowPickOrderedDict.update(
zip(
self.InsertedNotRowColumnStrsList,
self.NodePointDeriveNoder.pick(
self.InsertedNotRowGetStrsList
)
)
)
#debug
'''
self.debug(('self.',self,[
'RowedPickOrderedDict',
'InsertedNotRowPickOrderedDict'
]))
'''
#Definition the InsertedItemTuplesList
InsertedItemTuplesList=[
('RowInt',self.RowedIndexInt)
]+self.RowedPickOrderedDict.items(
)+self.InsertedNotRowPickOrderedDict.items()
#import tables
#print(tables.tableextension.Row)
#debug
'''
self.debug(
[
'This is a new row',
'Colnames are : '+str(self.TabledTable.colnames),
'InsertedItemTuplesList is '+str(InsertedItemTuplesList),
'self.TabledTable is '+str(dir(self.TabledTable)),
'self.ModeledDescriptionClass is '+(str(self.ModeledDescriptionClass.columns) if hasattr(self.ModeledDescriptionClass,'columns') else ""),
'Row is '+str(dir(Row)),
'Row.table is '+str(Row.table),
'TabularedTablesOrderedDict is '+str(self.TabularedTablesOrderedDict)
]
)
'''
#set
map(
lambda __InsertingTuple:
Row.__setitem__(*__InsertingTuple),
InsertedItemTuplesList
)
#debug
'''
self.debug('The Row setting was good, so append insert')
'''
#Append and Insert
Row.append()
self.TabledTable.insert()
else:
#debug
'''
self.debug(
[
'This is maybe not an IdentifyingInserter',
'Or it is already rowed',
'self.InsertedIsBoolsList is '+str(self.InsertedIsBoolsList)
]
)
'''
pass
#<NotHook>
#Return self
#return self
#</NotHook>
#</DefineClass>
View the Inserter sources on Github
In [23]:
#ImportModules
import tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Inserter
#Definition of a Structurer instance with a noded datar
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Inserter.InserterClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',(tables.Int64Col(shape=3)))
]
),
('Attr_RowingKeyStrsList',['MyInt'])
]
)
)
#Definition a structure with a db
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[2,4,6])
]
).command(
_UpdateList=[('insert',{'LiargVariablesList':[]})],
**{'GatheringVariablesList':['<Datome>ThingsInserter']}
).update(
[
('MyInt',0),
('MyStr',"hello"),
('MyIntsList',[0,0,0])
]
).command(
_UpdateList=[('insert',{'LiargVariablesList':[]})],
)
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Retriever instances can retrieve InsertedVariablesList given their
IndexInt of their corresponding table and their RowInt
(ie their index of their inserted line).
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Inserter"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class RetrieverClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'RetrievingIndexesList',
'RetrievedColumnStrToGetStrOrderedDict',
'RetrievedRowInt',
'RetrievedTable',
'RetrievedPickOrderedDict'
]
def default_init(self,
_RetrievingIndexesList=None,
_RetrievedColumnStrToGetStrOrderedDict=None,
_RetrievedRowInt=-1,
_RetrievedTable=None,
_RetrievedPickOrderedDict=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def setModelingDescriptionTuplesList(self,_SettingValueVariable):
#debug
'''
self.debug('Before we call the parent setModelingDescriptionTuplesList method ')
'''
#Hook
BaseClass.setModelingDescriptionTuplesList(self,_SettingValueVariable)
#Bind with RetrievedColumnStrToGetStrOrderedDict setting
if self.RetrievedColumnStrToGetStrOrderedDict==None:
self.RetrievedColumnStrToGetStrOrderedDict=collections.OrderedDict()
map(
lambda __ModelingColumnTuple:
self.RetrievedColumnStrToGetStrOrderedDict.__setitem__(
__ModelingColumnTuple[1],
__ModelingColumnTuple[0]
),
self.ModelingDescriptionTuplesList
)
#Init
if self.RetrievedPickOrderedDict==None:
self.RetrievedPickOrderedDict=collections.OrderedDict()
#debug
'''
self.debug(('self.',self,['RetrievedColumnStrToGetStrOrderedDict']))
'''
ModelingDescriptionTuplesList=property(
BaseClass.ModelingDescriptionTuplesList.fget,
setModelingDescriptionTuplesList,
BaseClass.ModelingDescriptionTuplesList.fdel,
BaseClass.ModelingDescriptionTuplesList.__doc__
)
#@Hooker.HookerClass(**{'HookingAfterVariablesList':[{"CallingMethodStr":"table"}]})
def do_retrieve(self):
#debug
'''
self.debug(
[
('self.',self,[
'TabularedTableKeyStrsList',
'RetrievingIndexesList'
])
]
)
'''
#<NotHook>
#table first
self.table()
#</NotHook>
#debug
'''
self.debug(
[
('Ok table is done'),
('self.',self,['TabularedTablesOrderedDict','TabularedTableKeyStrsList'])
]
)
'''
#set the RetrievedRowInt
self.RetrievedRowInt=self.RetrievingIndexesList[1]
#Definition the RetrievedTable
self.RetrievedTable=self.TabularedTablesOrderedDict[
self.TabularedTableKeyStrsList[
self.RetrievingIndexesList[0]
]
]
#debug
'''
self.debug(('self.',self,['RetrievedRowInt','RetrievedTable']))
'''
#Definition the RetrievedRowsList
for __RetrievedRow in self.RetrievedTable.iterrows():
if __RetrievedRow['RowInt']==self.RetrievedRowInt:
#debug
'''
self.debug('self.RetrievedTable.colnames is '+str(self.RetrievedTable.colnames))
'''
#Init
if self.RetrievedPickOrderedDict==None:
self.RetrievedPickOrderedDict=collections.OrderedDict()
#set
map(
lambda __ColumnStr:
self.RetrievedPickOrderedDict.__setitem__(
self.RetrievedColumnStrToGetStrOrderedDict[__ColumnStr],
__RetrievedRow[__ColumnStr]
) if __ColumnStr in self.RetrievedColumnStrToGetStrOrderedDict else None
,
self.RetrievedTable.colnames
)
#debug
'''
self.debug('RetrievedPickOrderedDict is setted')
'''
#debug
'''
self.debug(
[
('self.',self,['RetrievedPickOrderedDict'])
]
)
'''
#Update
self.NodePointDeriveNoder.update(
self.RetrievedPickOrderedDict.items(),
**{'RestrictingIsBool':True}
)
self.NodePointDeriveNoder.RestrictingIsBool=False
#debug
'''
self.debug('Update was done')
'''
#<NotHook>
#Return self
#return self
#</NotHook>
#</DefineClass>
View the Retriever sources on Github
In [27]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Retriever
import tables
#Definition of a Structurer instance with a noded datar
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Retriever.RetrieverClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',(tables.Int64Col(shape=3)))
]
),
('Attr_RowingKeyStrsList',['MyInt'])
]
)
)
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[2,4,6])
]
).command(
_UpdateList=[('insert',{'LiargVariablesList':[]})],
**{'GatheringVariablesList':['<Datome>ThingsRetriever']}
).update(
[
('MyInt',0),
('MyStr',"guten tag"),
('MyIntsList',[0,0,0])
]
).command(
_UpdateList=[('insert',{'LiargVariablesList':[]})],
)
#Retrieve
MyStructurer['<Datome>ThingsRetriever'].__setitem__(
'RetrievingIndexesList',(0,1)
).retrieve()
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
Findoer (sorry Finder is already an important module in python standards, so just to be sure to not override...) instances helps to find in a hdf5 table RowedVariablesList corresponding to the FindingConditionVariable.
View the Findoer notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Findoer.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Findoer (sorry Finder is already an important module in python standards, so just to be sure to not override...)
instances helps to find in a hdf5 table RowedVariablesList corresponding to the FindingConditionVariable.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Retriever"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
#from ShareYourSystem.Functers import Argumenter,Hooker
from ShareYourSystem.Standards.Modelers import Rower
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class FindoerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'FindingConditionVariable',
'FoundRowDictsList',
'FoundFilterRowDictsList'
]
def default_init(self,
_FindingConditionVariable=None,
_FoundRowDictsList=None,
_FoundFilterRowDictsList=None,
_FoundIsBool=False,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
#@Hooker.HookerClass(**{'HookingAfterVariablesList':[{'CallingMethodStr':"table"}]})
#@Argumenter.ArgumenterClass()
def do_find(self):
#debug
'''
self.debug(("self.",self,['ModeledKeyStr','FindingConditionVariable']))
'''
#<NotHook>
#table first
self.table()
#</NotHook>
#If the FoundRowedTuplesList was not yet setted
if self.FoundIsBool==False:
#debug
'''
self.debug('FoundRowDictsList was not yet setted')
'''
#Take the first one in the list
self.FoundRowDictsList=Rower.getRowedDictsListWithTable(
self.TabularedGroupVariable._f_getChild(
self.TabularedTableKeyStrsList[0]
)
)
#set
self.FoundIsBool=True
#debug
'''
self.debug(
[
("self.",self,['FoundRowDictsList'])
]
)
'''
#Now find really !
self.FoundFilterRowDictsList=SYS.filterNone(
SYS.where(
self.FoundRowDictsList,
self.FindingConditionVariable
)
)
#debug
'''
self.debug(
[
'The where is over now',
("self.",self,['FoundFilterRowDictsList'])
]
)
'''
#<NotHook>
#Return self
#return self
#</NotHook>
#</DefineClass>
View the Findoer sources on Github
In [31]:
#ImportModules
import tables,operator
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Findoer
#Definition of a Structurer instance with a noded datar
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Findoer.FindoerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',(tables.Int64Col(shape=3)))
]
),
('Attr_RowingKeyStrsList',['MyInt','MyStr','MyIntsList'])
]
)
)
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsFindoer'].insert()
MyStructurer.update(
[
('MyInt',0),
('MyStr',"guten tag"),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsFindoer'].insert()
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[0,0,0])
]
)['<Datome>ThingsFindoer'].insert()
#Retrieve
MyStructurer['<Datome>ThingsFindoer'].find(
[
('MyInt',(operator.eq,1)),
('MyIntsList',(SYS.getIsEqualBool,[0,0,1]))
]
)
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
Findoer (sorry Finder is already an important module in python standards, so just to be sure to not override...) instances helps to find in a hdf5 table RowedVariablesList corresponding to the FindingConditionVariable.
View the Recoverer notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Recoverer.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Findoer (sorry Finder is already an important module in python standards, so just to be sure to not override...)
instances helps to find in a hdf5 table RowedVariablesList corresponding to the FindingConditionVariable.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Findoer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
from ShareYourSystem.Functers import Argumenter,Hooker
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class RecovererClass(
BaseClass
):
#Definition
RepresentingKeyStrsList=[
'RecoveredDict'
]
def default_init(self,
_RecoveredDict=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
#@Hooker.HookerClass(**{'HookingAfterVariablesList':[{'MethodCallingStr':"find"}]})
#@Argumenter.ArgumenterClass()
def do_recover(self):
#debug
'''
self.debug(
[
'Is the self.RecoveredDict already setted ?',
'len(self.RecoveredDict) is '+str(len(self.RecoveredDict))
]
)
'''
#<NotHook>
#find first
self.find()
#</NotHook>
#Check
if len(self.RecoveredDict)==0:
#debug
'''
self.debug(
[
'The RecoveredDict is not yet setted',
'Look if we have found only one FilteredRowedDict',
'len(self.FoundFilterRowDictsList) is '+str(len(self.FoundFilterRowDictsList))
]
)
'''
#Check
if len(self.FoundFilterRowDictsList)==1:
#debug
'''
self.debug('It is good, there is one solution !')
'''
#set the RecoveredDict
self.RecoveredDict.update(self.FoundFilterRowDictsList[0])
#debug
'''
self.debug(
[
'Now we update with the self.RecoveredDict',
'self.RecoveredDict is '+str(self.RecoveredDict)
]
)
'''
#set the RetrievingIndexesList and retrieve
self.RetrievingIndexesList=(
0,
self.RecoveredDict['RowInt']
)
#Now we can retrieve
self.retrieve()
#<NotHook>
#Return self
#return self
#</NotHook>
#</DefineClass>
View the Recoverer sources on Github
In [35]:
#ImportModules
import operator,tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Recoverer
#Definition of a Structurer instance with a noded datar
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Recoverer.RecovererClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
#GetStr #ColumnStr #Col
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',(tables.Int64Col(shape=3)))
]
),
('Attr_RowingKeyStrsList',['MyInt','MyStr','MyIntsList'])
]
)
)
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsRecoverer'].insert()
MyStructurer.update(
[
('MyInt',0),
('MyStr',"guten tag"),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsRecoverer'].insert()
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[0,0,0])
]
)['<Datome>ThingsRecoverer'].insert()
#Retrieve
MyStructurer['<Datome>ThingsRecoverer'].recover(
**{
'FindingConditionVariable':
[
('MyInt',(operator.eq,1)),
('MyIntsList',(SYS.getIsEqualBool,[0,0,1]))
]
}
)
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
Shaper instances help for storing data in formated tables : if the shape of a rowed variable is depending on other flexible int attribute in the environment, it then build or set another table with the good format size to store again.
View the Shaper notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Shaper.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Shaper instances help for storing data in formated tables :
if the shape of a rowed variable is depending on other flexible int attribute
in the environment, it then build or set another table with the good format
size to store again.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Recoverer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import copy
import collections
import numpy
from ShareYourSystem.Standards.Modelers import Modeler,Tabularer,Tabler,Inserter
#</ImportSpecificModules>
#<DefineLocals>
ShapingJoiningStr='__'
ShapingTuplingStr='_'
#</DefineLocals>
#<DefineClass>
@DecorationClass(
**{
'ClassingSwitchMethodStrsList':[
'shape',
'model',
'tabular'
]
}
)
class ShaperClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'ShapingDimensionTuplesList',
'ShapedSealGetKeyStrsList',
'ShapedSealDimensionGetKeyStrsListsList',
'ShapedIndexIntsList',
'ShapedDimensionGetKeyStrsList',
'ShapedDimensionIntsList',
'ShapedStr'
]
def default_init(self,
_ShapingDimensionTuplesList=None,
_ShapedSealGetKeyStrsList=None,
_ShapedSealDimensionGetKeyStrsListsList=None,
_ShapedIndexIntsList=None,
_ShapedDimensionGetKeyStrsList=None,
_ShapedDimensionIntsList=None,
_ShapedStr="",
**_KwargVariablesDict):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def mimic_model(self):
#debug
'''
self.debug(
[
'self.shape is '+SYS._str(self.shape)
]
)
'''
#<NotHook>
#database and shape first
'''
self.debug('We database first')
'''
self.database()
'''
self.debug(
[
'We shape first',
'self.shape is '+str(self.shape)
]
)
'''
self.shape()
#</NotHook>
#Get the new ModeledKeyStr
if self.ShapedStr!="":
#debug
'''
self.debug(
[
'We set the new ModeledKeyStr',
('self.',self,['ShapedStr','ModeledSuffixStr'])
]
)
'''
#set
self.ModeledKeyStr=self.ShapedStr+ShapingJoiningStr+self.ModeledSuffixStr
else:
self.ModeledKeyStr=self.ModeledSuffixStr
#debug
'''
self.debug(
[
'We set the new ModeledKeyStr',
('self.',self,['ShapedStr','ModeledKeyStr'])
]
)
'''
#Check
if self.ModeledDescriptionClassesOrderedDict==None:
self.ModeledDescriptionClassesOrderedDict=collections.OrderedDict()
#Unnzip
ModeledGetKeyStrsList=SYS.unzip(self.ModelingDescriptionTuplesList,[0])
#debug
'''
self.debug(
[
('Now change the shape of the shaping cols'),
('self.',self,['ShapedSealDimensionGetKeyStrsListsList'])
]
)
'''
ShapedModelingDescriptionTuplesList=map(
self.ModelingDescriptionTuplesList.__getitem__,
self.ShapedIndexIntsList
)
#debug
'''
self.debug(
'ShapedModelingDescriptionTuplesList is '+str(ShapedModelingDescriptionTuplesList)
)
'''
#set the shaping cols
map(
lambda __ShapedIndexInt,__ShapedModelingSealTuple:
self.ModelingDescriptionTuplesList.__setitem__(
__ShapedIndexInt,
__ShapedModelingSealTuple
),
self.ShapedIndexIntsList,
map(
lambda __ShapedModelingSealTuple,__ShapedSealDimensionGetKeyStrsList:
(
__ShapedModelingSealTuple[0],
__ShapedModelingSealTuple[1],
__ShapedModelingSealTuple[2].__class__(
shape=self.NodePointDeriveNoder.pick(
__ShapedSealDimensionGetKeyStrsList)
)
),
ShapedModelingDescriptionTuplesList,
self.ShapedSealDimensionGetKeyStrsListsList
)
)
#debug
'''
self.debug("Now self.ModelingDescriptionTuplesList is "+str(
self.ModelingDescriptionTuplesList))
'''
#<NotHook>
#model then
Modeler.ModelerClass.model(self)
#</NotHook>
def mimic_tabular(self):
#<NotHook>
#tabular first
Tabularer.TabularerClass.tabular(self)
#</NotHook>
#debug
'''
self.debug(
[
'We add the ShapedStr to the TabularedSuffix Str ?',
('self.',self,[
'TabularedSuffixStr',
'ShapedStr'
])
]
)
'''
#Add the ShapedStr
if self.ShapedStr!="":
#debug
'''
self.debug(' ShapingJoiningStr not in self.TabularedSuffixStr is '+str( ShapingJoiningStr not in self.TabularedSuffixStr))
'''
if ShapingJoiningStr not in self.TabularedSuffixStr:
#debug
'''
self.debug('Yes we add')
'''
#Add
self.TabularedSuffixStr=self.ShapedStr+ShapingJoiningStr+self.TabularedSuffixStr
#debug
'''
self.debug("self.TabularedSuffixStr is "+self.TabularedSuffixStr)
'''
def mimic_insert(self):
#debug
'''
self.debug(
[
('self.',self,[
'We check the good dimensions of the shaping variables'
'TabledKeyStr',
'TabledTable'
])
]
)
'''
try:
#<NotHook>
#insert first
BaseClass.insert(self)
#</NotHook>
except ValueError:
#Definition the InsertedOldDimensionIntsListsList
InsertedOldDimensionIntsList=map(
lambda __ShapedSealDimensionGetKeyStrsList:
self.NodePointDeriveNoder.pick(
__ShapedSealDimensionGetKeyStrsList),
self.ShapedSealDimensionGetKeyStrsListsList
)
#Definition the InsertedNewDimensionIntsListsList
InsertedNewDimensionIntsListsList=map(
lambda __ShapedSealGetKeyStr:
list(
numpy.shape(
self.NodePointDeriveNoder[__ShapedSealGetKeyStr]
)
),
self.ShapedSealGetKeyStrsList
)
#debug
'''
self.debug(('vars ',vars(),[
'InsertedOldDimensionIntsList',
'InsertedNewDimensionIntsListsList'
]))
'''
#set the shaping attributes to their new values
map(
lambda __ShapedSealDimensionGetKeyStrsList,__InsertedOldDimensionList,__InsertedNewDimensionList:
self.__setitem__(
'ShapedErrorBool',
True
).NodePointDeriveNoder.update(
zip(
__ShapedSealDimensionGetKeyStrsList,
__InsertedNewDimensionList
)
) if __InsertedNewDimensionList!=__InsertedOldDimensionList
else None,
self.ShapedSealDimensionGetKeyStrsListsList,
InsertedOldDimensionIntsList,
InsertedNewDimensionIntsListsList
)
#debug
'''
self.debug('We reset some methods')
'''
#reboot
self.reboot(['Model','Shape','Tabular','Table'])
#Table
self.table()
#debug
'''
self.debug('Ok table again is done, so now we insert')
'''
#<NotHook>
#insert first
BaseClass.insert(self)
#</NotHook>
def do_shape(self):
#debug
'''
self.debug(
[
'We shape here',
#("self.",self,['ShapingDimensionTuplesList'])
]
)
'''
#Check
if len(self.ShapingDimensionTuplesList)>0:
#set
[
self.ShapedSealGetKeyStrsList,
self.ShapedSealDimensionGetKeyStrsListsList
]=SYS.unzip(self.ShapingDimensionTuplesList,[0,1])
#Flat and set
self.ShapedDimensionGetKeyStrsList=list(
set(
SYS.flat(
self.ShapedSealDimensionGetKeyStrsListsList
)
)
)
else:
#Default
self.ShapedSealGetKeyStrsList=[]
self.ShapedDimensionGetKeyStrsList=[]
self.ShapedSealDimensionGetKeyStrsListsList=[]
#debug
'''
self.debug(("self.",self,[
'ShapedSealGetKeyStrsList',
'ShapedDimensionGetKeyStrsList'
]))
'''
#Definition
ModeledGetKeyStrsList=SYS.unzip(self.ModelingDescriptionTuplesList,[0])
#set
self.ShapedIndexIntsList=map(
lambda __ShapedSealGetKeyStr:
ModeledGetKeyStrsList.index(__ShapedSealGetKeyStr),
self.ShapedSealGetKeyStrsList
)
#Check
if hasattr(self,'NodePointDeriveNoder') and self.NodePointDeriveNoder!=None:
#Pick
self.ShapedDimensionIntsList=self.NodePointDeriveNoder.pick(
self.ShapedDimensionGetKeyStrsList
)
else:
#Default
self.ShapedDimensionIntsList=[]
#debug
'''
self.debug(("self.",self,['ShapedDimensionIntsList']))
'''
#Bind with ModeledShapedStr setting
self.ShapedStr=ShapingJoiningStr.join(
map(
lambda __ShapedSealGetKeyStr,__ShapedDimensionVariable:
ShapingJoiningStr+str(
__ShapedSealGetKeyStr
)+ShapingTuplingStr+str(
__ShapedDimensionVariable),
self.ShapedDimensionGetKeyStrsList,
self.ShapedDimensionIntsList
)
)
#debug
'''
self.debug(('self.',self,['ShapedStr']))
'''
#</DefineClass>
View the Shaper sources on Github
In [39]:
#ImportModules
import tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Shaper
#Definition a structure
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Shaper.ShaperClass().update(
[
('Attr_ModelingDescriptionTuplesList',
[
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',tables.Int64Col(shape=[3]))
]
),
('Attr_RowingKeyStrsList',
['MyInt','MyStr']
),
('ShapingDimensionTuplesList',
[
('MyIntsList',['UnitsInt'])
]
)
]
)
)
MyStructurer.update(
[
('MyInt',0),
('MyStr',"hello"),
('UnitsInt',3),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsShaper'].insert()
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsShaper'].insert()
MyStructurer.update(
[
('MyInt',1),
('MyStr',"ola"),
('MyIntsList',[0,1])
]
)['<Datome>ThingsShaper'].insert()
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingAlineaIsBool':False,
'RepresentingBaseKeyStrsListBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Merger instances help for reloading rowed variables from
different tables but with different shaping variables.
The results is a list of rowed items from merged tables.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Shaper"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import operator
Shaper=BaseModule
from ShareYourSystem.Standards.Modelers import Tabler,Rower,Recoverer
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class MergerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'MergingConditionVariable',
'MergedRowedDictsList'
]
def default_init(self,
_MergingConditionVariable=None,
_MergedRowedDictsList=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def mimic_find(self):
#<NotHook>
#merge first
self.merge()
#</NotHook>
#Bound the FoundRowDictsList with the MergedRowedDictsList one
self.FoundRowDictsList=self.MergedRowedDictsList
#<NotHook>
#find then
BaseClass.find(self)
#</NotHook>
def do_merge(self):
#debug
'''
self.debug(
('self.',self,[
'ModeledKeyStr',
'MergingConditionVariable',
'TabularedTableKeyStrsList'
])
)
'''
#Debug
'''
print(
map(
lambda __TabularedKeyStr:
__TabularedKeyStr.split(Shaper.ShapingJoiningStr),
self.TabularedTableKeyStrsList
)
)
'''
#Bind with MergedShapingDictsList setting
MergedShapingDictsList=map(
lambda __StrsList:
dict(
map(
lambda __ShapingStr:
SYS.getUnSerializedTuple(
self.NodePointDeriveNoder,
__ShapingStr.split(
Shaper.ShapingTuplingStr
)
)
#Remove the suffix and the prefix
,__StrsList[1:-1] if len(__StrsList)>2 else []
)
),
map(
lambda __TabularedKeyStr:
__TabularedKeyStr.split(Shaper.ShapingJoiningStr),
self.TabularedTableKeyStrsList
)
)
#debug
'''
self.debug('MergedShapingDictsList is '+str(MergedShapingDictsList))
'''
#Bind with MergedFilteredShapingDictsList
MergedFilteredShapingDictsList=SYS.where(
MergedShapingDictsList,
self.MergingConditionVariable
)
#debug
'''
self.debug('MergedFilteredShapingDictsList is '+str(MergedFilteredShapingDictsList))
'''
#Bind with MergedTablesList setting
MergedTablesList=SYS.filterNone(
map(
lambda __Table,__MergedFilteredShapingDict:
__Table
if __MergedFilteredShapingDict!=None
else None,
self.TabularedTablesOrderedDict.values(),
MergedFilteredShapingDictsList
))
MergedRowedDictsListsList=map(
lambda __MergedTable:
map(
lambda __RowedDict:
dict(__RowedDict,**{
'TabledInt':int(
__MergedTable.name.split(Tabler.TablingOrderStr)[1]
)
}
),
Rower.getRowedDictsListWithTable(__MergedTable)
),
MergedTablesList
)
#debug
'''
self.debug('MergedRowedDictsListsList is '+str(MergedRowedDictsListsList))
'''
#Reduce
if len(MergedRowedDictsListsList)>0:
self.MergedRowedDictsList=reduce(operator.__add__,MergedRowedDictsListsList)
#</DefineClass>
View the Merger sources on Github
In [43]:
#ImportModules
import operator,tables
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Merger
#Definition a structure
MyStructurer=Structurer.StructurerClass().collect(
"Datome",
"Things",
Merger.MergerClass().update(
[
('Attr_ModelingDescriptionTuplesList',
[
('MyInt','MyInt',tables.Int64Col()),
('MyStr','MyStr',tables.StringCol(10)),
('MyIntsList','MyIntsList',tables.Int64Col(shape=[3]))
]
),
('Attr_RowingKeyStrsList',
['MyInt','MyStr']
),
('ShapingDimensionTuplesList',
[
('MyIntsList',['UnitsInt'])
]
)
]
)
)
MyStructurer.update(
[
('MyInt',0),
('MyStr',"hello"),
('UnitsInt',3),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsMerger'].insert()
MyStructurer.update(
[
('MyInt',1),
('MyStr',"bonjour"),
('MyIntsList',[0,0,1])
]
)['<Datome>ThingsMerger'].insert()
MyStructurer.update(
[
('MyInt',1),
('MyStr',"ola"),
('MyIntsList',[0,1])
]
)['<Datome>ThingsMerger'].insert()
#Merge
MyStructurer['<Datome>ThingsMerger'].merge(
[
('UnitsInt',(operator.gt,2))
]
)
#Definition the AttestedStr
SYS._attest(
[
'MyStructurer is '+SYS._str(
MyStructurer,
**{
'RepresentingAlineaIsBool':False,
'RepresentingBaseKeyStrsListBool':False
}
),
'hdf5 file is : '+MyStructurer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
Joiner instances helps to insert in joined databases, get the corresponding RetrieveIndexesLists if it was already inserted, and then insert locally depending if it is a new row compared to all JoinedRetrieveIndexesListsList
View the Joiner notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Joiner.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Joiner instances helps to insert in joined databases, get the corresponding
RetrieveIndexesLists if it was already inserted, and then insert locally
depending if it is a new row compared to all JoinedRetrieveIndexesListsList
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Merger"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
Featurer=BaseModule
import collections
import tables
from ShareYourSystem.Standards.Modelers import Modeler
#</ImportSpecificModules>
#<DefineLocals>
JoinStr='__'
JoinDeepStr='/'
#</DefineLocals>
#<DefineFunctions>
def getJoinedRetrieveIndexesListWithInstanceVariableAndDeriveDatabaser(
_InstanceVariable,_DeriveDatabaser):
#Table
_DeriveDatabaser.table().pick(['TabledInt',-1])
#set the JoinedRetrieveIndexesListKeyStr
return [_DeriveDatabaser.TabledInt,-1]
#<DefineFunctions>
#<DefineClass>
@DecorationClass(**{
'ClassingSwitchMethodStrsList':[
'model',
'tabular',
'join',
'insert'
]
})
class JoinerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'JoiningCollectionStr',
'JoiningCatchStr',
'JoiningAttentionStr',
'JoiningFindBeforeBool',
'JoinedCatchCollectionOrderedDict',
'JoinedCatchDeriveJoinersList',
'JoinedRetrieveIndexesListGetStrsList',
'JoinedRetrieveIndexesListColumnStrsList',
'JoinedInsertIndexIntsList'
]
def default_init(self,
_JoiningCollectionStr="",
_JoiningCatchStr="",
_JoiningAttentionStr="",
_JoiningFindBeforeBool=True,
_JoinedAttentionCollectionOrderedDict=None,
_JoinedCatchCollectionOrderedDict=None,
_JoinedCatchDeriveJoinersList=None,
_JoinedRetrieveIndexesListGetStrsList=None,
_JoinedRetrieveIndexesListColumnStrsList=None,
_JoinedInsertIndexIntsList=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def mimic_model(self):
#debug
'''
self.debug('We join first')
'''
#<NotHook>
#join first
self.join()
#</NotHook>
#debug
'''
self.debug('Add in the ModelingDescriptionTuplesList')
'''
#set
if len(self.JoinedRetrieveIndexesListColumnStrsList)>0:
self.ModelingDescriptionTuplesList=map(
lambda __JoinedRetrieveIndexesListGetStr,__JoinedRetrieveIndexesListColumnStr:
(
__JoinedRetrieveIndexesListGetStr,
__JoinedRetrieveIndexesListColumnStr,
tables.Int64Col(shape=2)
),
self.JoinedRetrieveIndexesListGetStrsList,
self.JoinedRetrieveIndexesListColumnStrsList
)+self.ModelingDescriptionTuplesList
#debug
'''
self.debug(
[
('self.',self,['ModelingDescriptionTuplesList']),
'Now call the parent model method'
]
)
'''
#<NotHook>
#join and model first
BaseClass.model(self)
#</NotHook>
def mimic_row(self):
#debug
'''
self.debug('Maybe we have to join first')
'''
#<NotHook>
#table and join first
self.table()
self.join()
#</NotHook>
#debug
'''
self.debug(
[
("We are going to check if is already inserted in the joined databases..."),
('self.',self,['JoinedCatchDeriveJoinersList'])
]
)
'''
#set
self.JoinedInsertIndexIntsList=map(
lambda __JoinedDeriveDatabaserPointer:
__JoinedDeriveDatabaserPointer.row().RowedIndexInt,
self.JoinedCatchDeriveJoinersList
)
#debug
'''
self.debug(('self.',self,[
'JoinedInsertIndexIntsList',
'JoinedRetrieveIndexesListGetStrsList'
]))
'''
#set the modeled int in the retrieve tuples
map(
lambda __JoinedRetrieveIndexesListGetStr,__JoinedInsertIndexInt:
getattr(
self.NodePointDeriveNoder,
__JoinedRetrieveIndexesListGetStr
).__setitem__(
1,
__JoinedInsertIndexInt
),
self.JoinedRetrieveIndexesListGetStrsList,
self.JoinedInsertIndexIntsList
)
#debug
'''
self.debug([
('Before updating the RowingKeyStrsList'),
#('self.',self,['NodePointDeriveNoder'])
('model first to set the ModeledGetStrToColumStr')
]
)
'''
#Model first to set the ModeledGetStrToColumStr
#self.model()
#Add in the RowingKeyStrsList
self.RowingKeyStrsList=self.JoinedRetrieveIndexesListGetStrsList+self.RowingKeyStrsList
#debug
'''
self.debug('Now row with Featurer')
'''
#<NotHook>
#row then
BaseClass.row(self)
#</NotHook>
#debug
'''
self.debug('Ok row is over for joining')
'''
def mimic_insert(self):
#<NotHook>
#row first
self.row()
#</NotHook>
#debug
'''
self.debug(
[
'First setSwitch and make insert the catched databases',
('self.',self,[
'JoiningCatchStr',
'JoiningCollectionStr'
])
]
)
'''
#Insert the post joined databases
self.JoinedInsertIndexIntsList=map(
lambda __JoinedCatchDeriveJoinerPointer:
__JoinedCatchDeriveJoinerPointer.CatchToPointVariable.insert(),
self.JoinedCatchCollectionOrderedDict.values(),
)
#switch first
self.transmit(
[
('setSwitch',{
'LiargVariablesList':[],
'KwargVariablesDict':
{
'_ClassVariable':"Joiner",
'_DoStrsList':['Insert']
}
}
)
],
[self.JoiningCatchStr+self.JoiningCollectionStr]
)
#debug
'''
self.debug('Now we can insert here')
'''
#<NotHook>
#insert then
BaseClass.insert(self)
#</NotHook>
def mimic_retrieve(self):
#debug
'''
self.debug(('self.',self,['RetrievingIndexesList']))
'''
#<NotHook>
#retrieve first
BaseClass.retrieve(self)
#</NotHook>
#Retrieve in the joined databases
self.JoinedInsertIndexIntsList=map(
lambda __JoinedRetrieveIndexesListGetStr,__JoinedDeriveDatabaserPointer:
__JoinedDeriveDatabaserPointer.retrieve(
getattr(
self.NodePointDeriveNoder,
__JoinedRetrieveIndexesListGetStr
)
),
self.JoinedRetrieveIndexesListGetStrsList,
self.JoinedCatchDeriveJoinersList
)
def mimic_find(self):
#<NotHook>
#table first
self.table()
#</NotHook>
#debug
'''
self.debug(('self.',self,['FindingConditionVariable']))
'''
#
if self.JoiningFindBeforeBool:
#Find in the joined databases
JoinedFindFilterRowDictsListsList=map(
lambda __JoinedDeriveDatabaserPointer:
__JoinedDeriveDatabaserPointer.find().FoundFilterRowDictsList,
self.JoinedCatchDeriveJoinersList
)
#debug
'''
self.debug('JoinedFindFilterRowDictsListsList is '+str(JoinedFindFilterRowDictsListsList))
'''
#Just keep the retrieve lists
JoinedFindFilterRetrieveListsList=map(
lambda __JoinedFindFilterRowDictsList:
map(
lambda __JoinedFindFilterRowDict:
[
__JoinedFindFilterRowDict['TabledInt']
if 'TabledInt' in __JoinedFindFilterRowDict else 0,
__JoinedFindFilterRowDict['RowInt']
],
__JoinedFindFilterRowDictsList
),
JoinedFindFilterRowDictsListsList
)
#debug
'''
self.debug('JoinedFindFilterRetrieveListsList is '+str(JoinedFindFilterRetrieveListsList))
'''
#Map
JoinedFindingConditionVariable=map(
lambda __JoinedRetrieveIndexesListColumnStr,__JoinedFindFilterRetrieveList:
(
__JoinedRetrieveIndexesListColumnStr,
(
SYS.getIsInListBool,
__JoinedFindFilterRetrieveList
)
),
self.JoinedRetrieveIndexesListColumnStrsList,
JoinedFindFilterRetrieveListsList
)
#debug
'''
self.debug('JoinedFindingConditionVariable is '+str(JoinedFindingConditionVariable))
'''
#Add to the finding condition tuples
self.FindingConditionVariable+=JoinedFindingConditionVariable
#Call the parent method
Featurer.FeaturerClass.find(self)
else:
#Call the parent method
BaseClass.find(self).FoundFilterRowDictsList
def do_join(
self
):
#<NotHook>
#database first
self.database()
#</NotHook>
#Check
if self.JoiningCollectionStr=="":
self.JoiningCollectionStr=self.NetworkCollectionStr
if self.JoiningCatchStr=="":
self.JoiningCatchStr=self.NetworkCatchStr
if self.JoiningAttentionStr=="":
self.JoiningAttentionStr=self.NetworkAttentionStr
#debug
'''
self.debug(
('self.',self,[
'JoiningCollectionStr',
'JoiningCatchStr',
'JoiningAttentionStr'
])
)
'''
#set
JoinedAttentionCollectionOrderedSetTagStr=self.JoiningAttentionStr+self.JoiningCollectionStr+"CollectionOrderedDict"
#check
if hasattr(
self,
JoinedAttentionCollectionOrderedSetTagStr
):
#get
self.JoinedAttentionCollectionOrderedDict=getattr(
self,
JoinedAttentionCollectionOrderedSetTagStr
)
#set
JoinedCatchCollectionOrderedSetTagStr=self.JoiningCatchStr+self.JoiningCollectionStr+"CollectionOrderedDict"
#check
if hasattr(self,JoinedCatchCollectionOrderedSetTagStr):
#get
self.JoinedCatchCollectionOrderedDict=getattr(
self,
JoinedCatchCollectionOrderedSetTagStr
)
#model and link all the catched joiners
self.JoinedCatchDeriveJoinersList=map(
lambda __JoinedCatchDeriveJoiner:
#__JoinedCatchDeriveJoiner.__setitem__(
# 'InsertIsBool',
# False
#).CatchToPointVariable.model(
#),
__JoinedCatchDeriveJoiner.CatchToPointVariable.model(),
self.JoinedCatchCollectionOrderedDict.values()
)
#debug
'''
self.debug(('self.',self,['JoinedCatchCollectionOrderedDict']))
'''
#set
self.JoinedRetrieveIndexesListColumnStrsList=map(
lambda __JoinedCatchDeriveJoiner:
"Join"+''.join(
[
__JoinedCatchDeriveJoiner.ModelDeriveControllerVariable.NodeKeyStr
if __JoinedCatchDeriveJoiner.ModelDeriveControllerVariable.NodeKeyStr!=""
else 'Top'+__JoinedCatchDeriveJoiner.ModelDeriveControllerVariable.__class__.NameStr,
__JoinedCatchDeriveJoiner.ModeledSuffixStr
]
)+"RetrieveIndexesList",
self.JoinedCatchDeriveJoinersList,
)
#debug
'''
self.debug(('self.',self,['JoinedRetrieveIndexesListColumnStrsList']))
'''
#set
self.JoinedRetrieveIndexesListGetStrsList=map(
lambda __JoinedCatchDeriveJoiner:
"Joined"+''.join(
[
self.ModelDeriveControllerVariable.NodeKeyStr
if self.ModelDeriveControllerVariable.NodeKeyStr!=""
else 'Top'+self.ModelDeriveControllerVariable.__class__.NameStr,
self.ModeledSuffixStr,
'To',
__JoinedCatchDeriveJoiner.ModelDeriveControllerVariable.NodeKeyStr
if __JoinedCatchDeriveJoiner.ModelDeriveControllerVariable.NodeKeyStr!=""
else 'Top'+__JoinedCatchDeriveJoiner.ModelDeriveControllerVariable.__class__.NameStr,
__JoinedCatchDeriveJoiner.ModeledSuffixStr
]
)+"RetrieveIndexesList",
self.JoinedCatchDeriveJoinersList,
)
#debug
'''
self.debug(
[
('self.',self,['JoinedRetrieveIndexesListGetStrsList']),
'Table the joined databases'
]
)
'''
#Table all the joined databasers and init the corresponding JoinedRetrieveIndexesList in the NodePointDeriveNoder
self.ModelDeriveControllerVariable.update(
zip(
self.JoinedRetrieveIndexesListGetStrsList,
map(
lambda __JoinedCatchDeriveJoiner:
[
__JoinedCatchDeriveJoiner.table()['TabledInt'],
-1
],
self.JoinedCatchDeriveJoinersList
)
)
)
#debug
'''
self.debug(
('self.',self,[
'JoinedRetrieveIndexesListColumnStrsList',
'JoinedRetrieveIndexesListGetStrsList'
])
)
'''
#</DefineClass>
View the Joiner sources on Github
In [47]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Classors import Classer
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Joiner
import operator
import tables
import numpy as np
#Define a Multiplier class
@Classer.ClasserClass()
class MultiplierClass(Structurer.StructurerClass):
#Definition
RepresentingKeyStrsList=[
'MultiplyingFirstInt',
'MultiplyingSecondInt'
]
def default_init(self,
_MultiplyingFirstInt=0,
_MultiplyingSecondInt=0,
**_KwargVariablesDict
):
#Call the parent init method
self.__class__.__bases__[0].__init__(self,**_KwargVariablesDict)
#Set a parameters database
self.collect(
"Datome",
"Parameters",
Joiner.JoinerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
('MultiplyingFirstInt','MultiplyingFirstInt',tables.Int64Col()),
('MultiplyingSecondInt','MultiplyingSecondInt',tables.Int64Col())
]
),
('Attr_RowingKeyStrsList',['MultiplyingFirstInt','MultiplyingSecondInt'])
]
)
)
#Define a Modulizer class
@Classer.ClasserClass()
class ModulizerClass(Structurer.StructurerClass):
#Definition
RepresentingKeyStrsList=[
'ModulizingPowerFloat',
'ModulizedTotalFloat'
]
def default_init(self,
_ModulizingPowerFloat=1.,
_ModulizedTotalFloat=0.,
**_KwargVariablesDict
):
#Call the parent init method
self.__class__.__bases__[0].__init__(self,**_KwargVariablesDict)
#Build the output hierarchy
self.update(
[
('<Component>RealMultiplier',MultiplierClass()),
('<Component>ImageMultiplier',MultiplierClass())
]
)
#Set a parameters database
self.collect(
"Datome",
"Parameters",
Joiner.JoinerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
('ModulizingPowerFloat','ModulizingPowerFloat',tables.Float64Col())
]
),
('Attr_RowingKeyStrsList',['ModulizingPowerFloat']),
('ConnectingGraspClueVariablesList',
[
'/NodePointDeriveNoder/<Component>RealMultiplier/<Datome>ParametersJoiner',
'/NodePointDeriveNoder/<Component>ImageMultiplier/<Datome>ParametersJoiner'
]
)
]
)
)
#Definition of a Modulizer instance, structure and network
MyModulizer=ModulizerClass().structure(
['Component']
).network(
**{
'VisitingCollectionStrsList':['Datome','Component'],
'RecruitingConcludeConditionVariable':[
(
'__class__.__mro__',
operator.contains,Joiner.JoinerClass
)
]
}
)
#Update and insert in the results
MyModulizer.__setitem__(
"Dis_<Component>",
[
[
('MultiplyingFirstInt',1),
('MultiplyingSecondInt',2)
],
[
('MultiplyingFirstInt',1),
('MultiplyingSecondInt',3)
]
]
)['<Datome>ParametersJoiner'].insert()
#Update and insert in the results
MyModulizer.__setitem__(
"Dis_<Component>",
[
[
('MultiplyingFirstInt',2)
],
[
('MultiplyingSecondInt',4)
]
]
)['<Datome>ParametersJoiner'].insert()
#Definition the AttestedStr
SYS._attest(
[
'MyModulizer is '+SYS._str(
MyModulizer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyModulizer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
A Hierarchizer is a Joiner that taking care of the order of the joining connections between derived Joiners, whatever is the level of their setting in the hierarchy of their parent derived Storers.
View the Hierarchizer notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Hierarchizer.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
A Hierarchizer is a Joiner that taking care of the
order of the joining connections between derived Joiners,
whatever is the level of their setting in the hierarchy of
their parent derived Storers.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Joiner"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import tables
from ShareYourSystem.Standards.Noders import Noder
Joiner=BaseModule
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass(**{
'ClassingSwitchMethodStrsList':[
'model',
'tabular',
'join',
'insert'
]
})
class HierarchizerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
]
#@Hooker.HookerClass(**{'HookingAfterVariablesList':[{'CallingVariable':BaseClass.__init__}]})
def default_init(self,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def mimic_insert(self):
#debug
'''
self.debug(
[
'we setSwitch first and insert',
('self.',self,[
'JoiningAttentionStr',
'JoiningCollectionStr'
])
]
)
'''
#<NotHook>
#insert then
BaseClass.insert(self)
#</NotHook>
#debug
'''
self.debug('we hierarchize now, self.hierarchize is '+str(self.hierarchize))
'''
#call
self.hierarchize()
#switch first
self.transmit(
[
('setSwitch',{
'LiargVariablesList':[],
'KwargVariablesDict':
{
'_ClassVariable':'Hierarchizer',
'_DoStrsList':['Insert']
}
})
],
[self.JoiningAttentionStr+self.JoiningCollectionStr],
#Self is not switched (if not it is circular !)
#False
)
def do_hierarchize(self):
#debug
'''
self.debug(
[
'insert then in the joined attention databasers',
('self.',self,['JoinedAttentionCollectionOrderedDict'])
]
)
'''
#map
map(
lambda __JoinedAttentionCollectionDeriveJoinerPointer:
__JoinedAttentionCollectionDeriveJoinerPointer.CatchToPointVariable.insert(),
self.JoinedAttentionCollectionOrderedDict.values()
)
#</DefineClass>
View the Hierarchizer sources on Github
In [51]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Classors import Classer
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Hierarchizer
import operator
import tables
import numpy as np
#Define a Sumer class
@Classer.ClasserClass()
class SumerClass(Structurer.StructurerClass):
#Definition
RepresentingKeyStrsList=[
'SumingFirstInt',
'SumingSecondInt',
'SumedTotalInt'
]
def default_init(self,
_SumingFirstInt=0,
_SumingSecondInt=0,
_SumedTotalInt=0,
**_KwargVariablesDict
):
#Call the parent init method
self.__class__.__bases__[0].__init__(self,**_KwargVariablesDict)
#Set a parameters database
self.collect(
"Datome",
"Parameters",
Hierarchizer.HierarchizerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
('SumingFirstInt','SumingFirstInt',tables.Int64Col()),
('SumingSecondInt','SumingSecondInt',tables.Int64Col())
]
),
('Attr_RowingKeyStrsList',['SumingFirstInt','SumingSecondInt'])
]
)
)
#Set a results database
self.collect(
"Datome",
"Results",
Hierarchizer.HierarchizerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
('SumedTotalInt','SumedTotalInt',tables.Int64Col())
]
),
('ConnectingGraspClueVariablesList',
[
'/NodePointDeriveNoder/<Datome>ParametersHierarchizer'
]
),
('TagStr','Networked')
]
)
)
def do_sum(self):
#debug
'''
self.debug(('self.',self,['SumingFirstInt','SumingSecondInt']))
'''
#set the SumedTotalInt
self.SumedTotalInt=self.SumingFirstInt+self.SumingSecondInt
#Define a Factorizer class
@Classer.ClasserClass()
class FactorizerClass(Structurer.StructurerClass):
#Definition
RepresentingKeyStrsList=[
'FactorizingPowerFloat',
'FactorizedTotalFloat'
]
def default_init(self,
_FactorizingPowerFloat=1.,
_FactorizedTotalFloat=0.,
**_KwargVariablesDict
):
#Call the parent init method
self.__class__.__bases__[0].__init__(self,**_KwargVariablesDict)
#Build the output hierarchy
self.update(
[
('<Component>XSumer',SumerClass()),
('<Component>YSumer',SumerClass())
]
)
#Set a parameters database
self.collect(
"Datome",
"Parameters",
Hierarchizer.HierarchizerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
('FactorizingPowerFloat','FactorizingPowerFloat',tables.Float64Col())
]
),
('Attr_RowingKeyStrsList',['FactorizingPowerFloat']),
('ConnectingGraspClueVariablesList',
[
'/NodePointDeriveNoder/<Component>XSumer/<Datome>ParametersHierarchizer',
'/NodePointDeriveNoder/<Component>YSumer/<Datome>ParametersHierarchizer'
]
)
]
)
)
#Set a results database
self.collect(
"Datome",
"Results",
Hierarchizer.HierarchizerClass().update(
[
(
'Attr_ModelingDescriptionTuplesList',
[
('FactorizedTotalFloat','FactorizedTotalFloat',tables.Float64Col())
]
),
('ConnectingGraspClueVariablesList',
[
'/NodePointDeriveNoder/<Datome>ParametersHierarchizer'
]
),
('TagStr','Networked')
]
)
)
def do_factorize(self):
#debug
self.debug('We factorize here')
#set the FactorizedTotalFloat
self.FactorizedTotalFloat=np.power(
sum(
map(
lambda __DeriveSumer:
__DeriveSumer.SumedTotalInt,
self['<Component>']
)
),
self.FactorizingPowerFloat
)
#Definition of a Factorizer instance, structure and network
MyFactorizer=FactorizerClass().structure(
['Component']
).network(
**{
'VisitingCollectionStrsList':['Datome','Component'],
'RecruitingConcludeConditionVariable':[
(
'__class__.__mro__',
operator.contains,Hierarchizer.HierarchizerClass
)
]
}
)
#Update transmit the do method and insert in the results
MyFactorizer.__setitem__(
"Dis_<Component>",
[
[
('SumingFirstInt',1),
('SumingSecondInt',2)
],
[
('SumingFirstInt',1),
('SumingSecondInt',3)
]
]
).walk(
{
'AfterUpdateList':[
('callDo',{'LiargVariablesList':[]})
],
'GatherVariablesList':['<Component>']
}
)['<Datome>ResultsHierarchizer'].insert()
#Update and insert in the results
MyFactorizer.__setitem__(
"Dis_<Component>",
[
[
('SumingFirstInt',2)
],
[
('SumingSecondInt',4)
]
]
).walk(
{
'AfterUpdateList':[
('callDo',{'LiargVariablesList':[]})
],
'GatherVariablesList':['<Component>']
}
)['<Datome>ResultsHierarchizer'].insert()
#Definition the AttestedStr
SYS._attest(
[
'MyFactorizer is '+SYS._str(
MyFactorizer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyFactorizer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Featurer instances helps for defining Databaser where all
the rowed variables are identifying items.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Hierarchizer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
from ShareYourSystem.Standards.Modelers import Rower
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class FeaturerClass(
BaseClass
):
#Definition
RepresentingKeyStrsList=[
'FeaturingAllBool',
'FeaturedJoinDatabasersList'
]
def default_init(self,
_FeaturingAllBool=False,
_FeaturingJoinInsertBool=True,
_FeaturedJoinDatabasersList=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def mimic_model(self):
#<NotHook>
#feature first
self.feature()
#</NotHook>
#<NotHook>
#model then
BaseClass.model(self)
#</NotHook>
#<NotHook>
#Return self
#return self
#</NotHook>
def mimic_row(self):
#debug
'''
self.debug(('self.',self,self.__class__.DoingAttributeVariablesOrderedDict.keys()))
'''
#Put all the GettingStrsList in the identifying container
if self.FeaturingAllBool:
#debug
'''
self.debug('Set the RowingKeyStrsList with all the ModelingGetStrs')
'''
#set
self['Attr_RowingKeyStrsList']=SYS.unzip(
self.ModelingDescriptionTuplesList,
[0]
)
#debug
'''
self.debug(('self.',self,['RowingKeyStrsList','ModelingDescriptionTuplesList']))
'''
#<NotHook>
#row then
BaseClass.row(self)
#</NotHook>
#<NotHook>
#Return self
#return self
#</NotHook>
def mimic_insert(self):
#<NotHook>
#feature first
self.feature()
#</NotHook>
#debug
'''
self.debug(('self.',self,['FeaturingJoinInsertBool']))
'''
#Check
if len(self.FeaturedJoinDatabasersList)>0 and self.FeaturingJoinInsertBool:
#debug
'''
self.debug('insert in the joined featured databasers')
'''
#set
self.FeaturingJoinInsertBool=False
#map
map(
lambda __FeaturedDatabaser:
__FeaturedDatabaser.insert(),
self.FeaturedJoinDatabasersList
)
#set
self.FeaturingJoinInsertBool=True
#Return
return
else:
#debug
self.debug('insert now here')
#insert directly
BaseClass.insert(self)
def do_feature(self):
#Check
if self.NodePointDeriveNoder!=None:
#map
self.FeaturedJoinDatabasersList=SYS.filterNone(
map(
lambda __NodedDatabaser:
__NodedDatabaser if hasattr(
__NodedDatabaser,'JoiningDownGetKeyStrsList')
and __NodedDatabaser.JoiningDownGetKeyStrsList !=None and
self.NodedDatabaseKeyStr in __NodedDatabaser.JoiningDownGetKeyStrsList
else None,
self.ModeledDeriveDatabasersOrderedDict.values()
)
)
#debug
'''
self.debug(('self.',self,['FeaturedJoinDatabasersList']))
'''
#</DefineClass>
View the Featurer sources on Github
In [55]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Classors import Classer
from ShareYourSystem.Functers import Triggerer
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Featurer,Joiner
import tables
import operator
MyFeaturer=Featurer.FeaturerClass()
#Definition the AttestedStr
SYS._attest(
[
'MyFeaturer is '+SYS._str(
MyFeaturer,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyFeaturer.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
Recuperater instances
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Modelers.Joiner"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class RecuperaterClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'RecuperatingRetrieveList'
]
#@Hooker.HookerClass(**{'HookingAfterVariablesList':[{'CallingVariable':BaseClass.__init__}]})
def default_init(self,
_RecuperatingRetrieveList=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_recuperate(self):
#retrieve
self.retrieve(self.RecuperatingRetrieveList)
#debug
self.debug(('self',self,['RetrievedPickOrderedDict']))
#</DefineClass>
View the Recuperater sources on Github
In [59]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Classors import Classer
from ShareYourSystem.Functers import Triggerer
from ShareYourSystem.Standards.Noders import Structurer
from ShareYourSystem.Standards.Modelers import Featurer,Recuperater
import tables
import operator
MyRecuperater=Recuperater.RecuperaterClass()
#Definition the AttestedStr
SYS._attest(
[
'MyRecuperater is '+SYS._str(
MyRecuperater,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
'hdf5 file is : '+MyRecuperater.hdfview().hdfclose().HdformatedConsoleStr
]
)
#Print