def join( self, _ModelStr="", **_LocalJoiningVariablesDict ): #debug print('Joiner join method') print('_ModelStr is ',_ModelStr) if hasattr(self,"StructuredKeyStr"): print('self.StructuredKeyStr is ',self.StructuredKeyStr) print('') #Maybe we need to refresh some modeled and tabulared attributes if _ModelStr!="": #debug ''' print('_ModelStr is ',_ModelStr) print('') ''' #row self.tabular(_ModelStr) else: #set again the _ModelStr _ModelStr=self.ModeledDict['ModelStr'] #Init maybe the _LocalJoiningVariablesDict if 'IsJoiningBool' not in _LocalJoiningVariablesDict: #set IsScanningBool to False _LocalJoiningVariablesDict['IsJoiningBool']=False #Refresh attributes self.JoinedJoinedList=[-1,-1] self.JoinedOrderedDict=collections.OrderedDict() self.JoinedNodifiedOrderedDict=collections.OrderedDict() #Init a default False IsCheckingJoiningBool if 'IsCheckingJoiningBool' not in _LocalJoiningVariablesDict: _LocalJoiningVariablesDict['IsCheckingJoiningBool']=True #set the JoiningTuple if 'JoiningTuple' not in _LocalJoiningVariablesDict: #Case where there are joins if 'JoiningTuple' in self.ModeledDict: #set to the _LocalJoiningVariablesDict _LocalJoiningVariablesDict['JoiningTuple']=self.ModeledDict['JoiningTuple'] #Maybe we have to structure if self.IsGroupedBool==False: #debug ''' print('Join We have to structure first') if hasattr(self,"StructuredKeyStr"): print('self.StructuredKeyStr is ',self.StructuredKeyStr) ''' #Structure self.structure(self.ModeledDict['JoiningTuple'][0]) else: #set a default _LocalJoiningVariablesDict['JoiningTuple']=("","") #Nodify if there is the nodified objects if _LocalJoiningVariablesDict['IsJoiningBool']==False and _LocalJoiningVariablesDict['JoiningTuple' ][0]!="": #debug print('Joiner we are going to nodify the ',_LocalJoiningVariablesDict['JoiningTuple'][0]) if hasattr(self,'StructuredKeyStr'): print('self.StructuredKeyStr is ',self.StructuredKeyStr) print('') #Nodify self.nodify(_LocalJoiningVariablesDict['JoiningTuple'][0]) self.JoinedNodifiedOrderedDict=copy.copy(self.NodifiedOrderedDict) self.JoinedNodifiedNodeStr=self.NodifiedNodeStr self.JoinedNodifiedNodedStr=SYS.getDoneStrWithDoStr(self.NodifiedNodeStr) self.JoinedNodifiedNodingStr=SYS.getDoneStrWithDoStr(self.NodifiedNodeStr) #debug print('self.JoinedNodifiedOrderedDict is ',self.JoinedNodifiedOrderedDict) print('') #debug ''' print("_LocalJoiningVariablesDict['JoiningTuple'] is ", _LocalJoiningVariablesDict['JoiningTuple']) print('') ''' #If there is a joined model if len(self.JoinedNodifiedOrderedDict)==0 or _LocalJoiningVariablesDict['IsJoiningBool']: #debug ''' print('We have the right to join !') print("_LocalJoiningVariablesDict['IsJoiningBool']", _LocalJoiningVariablesDict['IsJoiningBool']) print('self.ModeledDict is ',self.ModeledDict) print('') ''' #Tabular for the _JoiningRowingStr if JoiningTuple is not None if _LocalJoiningVariablesDict['JoiningTuple'][1]!=None: self.JoinedModelStr=_LocalJoiningVariablesDict['JoiningTuple'][1] self.JoinedModeledStr=SYS.getDoneStrWithDoStr(self.JoinedModelStr) self.tabular(self.JoinedModelStr) self.JoinedModeledDict=copy.copy(self.ModeledDict) self.JoinedModeledKeyStr=self.ModeledKeyStr self.JoinedJoinedList[0]=self.ShapedTabularedInt self.JoinedTabularedTable=self.TabularedTable #debug ''' print('self.JoinedModeledDict is ',self.JoinedModeledDict) print('self.JoinedModeledKeyStr is ',self.JoinedModeledKeyStr) print('self.JoinedJoinedList is ',self.JoinedJoinedList) print('') ''' #Check if the actual setup is already rowed if _LocalJoiningVariablesDict['IsCheckingJoiningBool'] and self.JoinedJoinedList[1]==-1: #Definition the GettingStrsList and the GettedVariablesList if 'ColumningTuplesList' in self.JoinedModeledDict: #Get the GettingStrsList and GettedVariablesList GettingStrsList=SYS.unzip(self.JoinedModeledDict['ColumningTuplesList'],[0]) GettedVariablesList=self.pick(GettingStrsList) #debug ''' print(map( lambda __Row: map( lambda __GettingStr,__GettedVariable: all(__Row[__GettingStr]==__GettedVariable), GettingStrsList, GettedVariablesList ), JoinedTabularedTable.iterrows() ) ) ''' #Check if it was already rowed IsRowedBoolsList=map( lambda __Row: all( map( lambda __GettingStr,__GettedVariable: SYS.getIsEqualBool(__Row[__GettingStr],__GettedVariable), GettingStrsList, GettedVariablesList ) ), self.JoinedTabularedTable.iterrows() ) #debug ''' print('self.StructuredKeyStr is ',self.StructuredKeyStr) print('IsRowedBoolsList is ',IsRowedBoolsList) print('') ''' #If it is rowed then set the JoinedJoinedList try: IndexInt=IsRowedBoolsList.index(True) except ValueError: IndexInt=-1 self.JoinedJoinedList[1]=IndexInt #Give to itself JoinedOrderedSetTagStr=self.JoinedNodifiedNodedStr+'JoinedOrderedDict' if hasattr(self,JoinedOrderedSetTagStr): self.JoinedOrderedDict=getattr(self,JoinedOrderedSetTagStr) if self.JoinedOrderedDict==None: self.JoinedOrderedDict=collections.OrderedDict() self.JoinedOrderedDict.__setitem__( self.JoinedJoinedListKeyStr,self.JoinedJoinedList ) if self.JoinedNodifiedNodedStr!="": ParentPointer=getattr(self,self.JoinedNodifiedNodedStr+'ParentPointer') if ParentPointer!=None: #Give to the Parent JoinedOrderedDict=getattr(ParentPointer,JoinedOrderedSetTagStr) JoinedOrderedDict[getattr(self,self.JoinedNodifiedNodedStr+'KeyStr' )+self.JoinedJoinedListKeyStr]=self.JoinedJoinedList #debug ''' print('JoinedModeledDict is ',JoinedModeledDict) print('JoinedList is ',JoinedList) print('') ''' #Tabular again to set again the ModeledDict self.tabular(_ModelStr) else: #debug ''' print('This either a not last level of child or it is not yet authorized to join') print('self.JoinedNodifiedOrderedDict.values() is ',self.JoinedNodifiedOrderedDict.values()) print('len(self.NodifiedOrderedDict.values()) is ',len(self.NodifiedOrderedDict.values())) print("_LocalJoiningVariablesDict['IsJoiningBool']",_LocalJoiningVariablesDict['IsJoiningBool']) print('so join the deeper children groups first') print('') ''' map( lambda __JoiningObjects: __JoiningObjects.join( self.ModeledDict['ModelStr'], **_LocalJoiningVariablesDict ), self.JoinedNodifiedOrderedDict.values() ) ''' print('The deeper children groups are joined now') print('So join here !') print('') ''' self.join( self.ModeledDict['ModelStr'], **dict( _LocalJoiningVariablesDict,**{'IsJoiningBool':True} ) ) #Return self return self
def model(self,_ModelStr="",**_DatabasingVariablesDict): """Call the Output<HookStr> methods and return self.OutputedPointer (self by default)""" #debug print('Modeler model method') print('_ModelStr is ',_ModelStr) print('') #Reinit attributes LocalOutputedPointer=self if _ModelStr=="": _ModelStr=self.DatabasedDict['ModelStr'] else: self.DatabasedDict=self['App_Model_'+SYS.getDoingStrWithDoStr(_ModelStr)+'Dict'] if self.DatabasedDict!=None: if 'IsDatabasedBool' not in self.DatabasedDict: #set variables IsDatabasedBool=False ModelStr=_ModelStr DatabasingStr=SYS.getDoingStrWithDoStr(ModelStr) DatabasedStr=SYS.getDoneStrWithDoStr(ModelStr) ModeledSuffixStr=SYS.getClassStrWithTypeStr(DatabasedStr+'Model') DatabasedKeyStr="" #Put them in the DatabasedDict LocalVars=vars() map( lambda __GettingStr: self.DatabasedDict.__setitem__(__GettingStr,LocalVars[__GettingStr]), [ 'IsDatabasedBool', 'ModelStr', 'DatabasingStr', 'DatabasedStr', 'ModeledSuffixStr', 'DatabasedKeyStr' ] ) #set IsDatabasingBool self.IsDatabasingBool=True #Hook methods for OrderStr in ["Before","After"]: #Definition the HookMethodStr HookingMethodStr='model'+OrderStr #Check that there is HookingMethods for it if HookingMethodStr in self.__class__.HookingMethodStrToMethodsListDict: #Call the specific Appended methods for HookingMethod in self.__class__.HookingMethodStrToMethodsListDict[HookingMethodStr]: #Call the HookMethod OutputVariable=HookingMethod(self,**_DatabasingVariablesDict) if type(OutputVariable)==dict: if 'LocalDatabasingVariablesDict' in OutputVariable: LocalDatabasingVariablesDict=OutputVariable['LocalDatabasingVariablesDict'] if 'LocalOutputedPointer' in OutputVariable: LocalOutputedPointer=OutputVariable['LocalOutputedPointer'] #Check Bool if self.IsDatabasingBool==False: return LocalOutputedPointer #debug print('END Modeler model method') print('_ModelStr is ',_ModelStr) print('') #Return the OutputVariable return LocalOutputedPointer
def modelAfter(self,**_ModelingVariablesDict): #debug ''' print('Joiner modelAfter method') print('') ''' #Join maybe if 'JoiningTuple' in self.ModeledDict: #debug ''' print("self.ModeledDict['JoiningTuple'] is ",self.ModeledDict['JoiningTuple']) print() ''' #Definition the JoinedModeledStr JoinedModeledStr=SYS.getDoneStrWithDoStr(self.ModeledDict['JoiningTuple'][1]) #Add a JoinedList for the join with the joining table at this level self.JoinedJoinedListKeyStr=JoinedModeledStr+'JoinedList' self.ModeledDescriptionClass.columns[self.JoinedJoinedListKeyStr]=tables.Int64Col(shape=2) #Nodify with the JoiningNodifiedStr if self.ModeledDict['JoiningTuple'][0]!="": #debug ''' print('Joiner we are going to nodify the ',self.ModeledDict['JoiningTuple'][0]) print('') ''' #Nodify self.nodify(self.ModeledDict['JoiningTuple'][0]) #set the JoinedNodifiedKeyStrKeyStrsList JoinedNodifiedKeyStrsList=map( lambda __JoinedObjects: getattr( __JoinedObjects, self.NodifiedKeyStrKeyStr ), self.NodifiedOrderedDict.values() ) #set the Cols for the joined children map( lambda __NodifiedKeyStrKeyStr: self.ModeledDescriptionClass.columns.__setitem__( self.NodifiedNodedStr+__NodifiedKeyStrKeyStr+JoinedModeledStr+'JoinedList', tables.Int64Col(shape=2) ), JoinedNodifiedKeyStrsList ) #Definition the JoinedOrderedDict JoinedOrderedSetTagStr=self.NodifiedNodedStr+'JoinedOrderedDict' self.__setattr__(JoinedOrderedSetTagStr,collections.OrderedDict()) JoinedOrderedDict=getattr(self,JoinedOrderedSetTagStr) JoinedOrderedDict[self.JoinedJoinedListKeyStr]=[-1,-1] #Init the JoinedList for each child map( lambda __JoinedNodifiedKeyStr: JoinedOrderedDict.__setitem__( self.NodifiedNodedStr+__JoinedNodifiedKeyStr+self.JoinedJoinedListKeyStr, [-1,-1] ), JoinedNodifiedKeyStrsList )