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 [3]:
#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