Пример #1
0
 def __setup_data_context(self):
     
     dc = self.data_context
     dc_navigator = DataContextNavigator(dc)        
     for col_name, col in self.columns.iteritems():
         metadata = Column.get_metadata(col)            
         if metadata.uses_data_context:
             
             dc_prop = col_name if metadata.data_context == True else\
                 metadata.data_context                
             try: column_context = dc_navigator.navigate(dc_prop)
             except (AttributeError, KeyError):
                 raise Exception(type(self).__name__ +                                    
                                 ', missing data_context value for column '
                                  '%(col_name)s: %(dc_prop)s'
                                  '\n\t data_context = %(dc)s' % locals())
             
             # allow binding primitives to single argument functions
             if not isinstance(column_context, dict):
                 args = inspect.getargspec(metadata.inner_func).args
                 if args == ['self']:
                     column_context = {tuple():column_context}    
                 else:
                     raise Exception(type(self).__name__ +                                        
                                     ', data_context error for column '
                                     '%s(col_name), unexpected data type. '
                                     'Must be dictionary, since the function'
                                     ' takes multiple arguments '
                                     '(not just "self"\ndata_context='
                                     '%(column_context)' % column_context)                   
                 
                                                 
             for args, val in column_context.iteritems():
                 col.set_value(args, val)        
Пример #2
0
    def do_timestep(self, t):
        if self.__columns == None:
            raise ModelException('You must call super.__init__')

        for col in self.columns.values():
            metadata = Column.get_metadata(col)
            if metadata.is_automatically_called:
                col(t)

        for submodel in self.submodels.values():
            submodel.do_timestep(t)
Пример #3
0
 def do_timestep(self, t):        
     if self.__columns == None:
         raise ModelException('You must call super.__init__')
     
     for col in self.columns.values():
         metadata = Column.get_metadata(col)
         if metadata.is_automatically_called:
             col(t)
     
     for submodel in self.submodels.values():
         submodel.do_timestep(t)
Пример #4
0
    def __setup_data_context(self):

        dc = self.data_context
        dc_navigator = DataContextNavigator(dc)
        for col_name, col in self.columns.iteritems():
            metadata = Column.get_metadata(col)
            if metadata.uses_data_context:

                dc_prop = col_name if metadata.data_context == True else\
                    metadata.data_context
                try:
                    column_context = dc_navigator.navigate(dc_prop)
                except (AttributeError, KeyError):
                    raise Exception(
                        type(self).__name__ +
                        ', missing data_context value for column '
                        '%(col_name)s: %(dc_prop)s'
                        '\n\t data_context = %(dc)s' % locals())

                # allow binding primitives to single argument functions
                if not isinstance(column_context, dict):
                    args = inspect.getargspec(metadata.inner_func).args
                    if args == ['self']:
                        column_context = {tuple(): column_context}
                    else:
                        raise Exception(
                            type(self).__name__ +
                            ', data_context error for column '
                            '%s(col_name), unexpected data type. '
                            'Must be dictionary, since the function'
                            ' takes multiple arguments '
                            '(not just "self"\ndata_context='
                            '%(column_context)' % column_context)

                for args, val in column_context.iteritems():
                    col.set_value(args, val)
Пример #5
0
 def testGetMetadata(self):
     col = Column(lambda x: x, True)
     metadata = Column.get_metadata(col)
     self.assertIsInstance(metadata, ColumnMetadata, \
                           'Expected column metadata')
Пример #6
0
 def get_column_identifier(self, column):
     col_id = self.__model_identifier + Column.get_column_name(column)
     metadata = {'args': getargspec(Column.get_metadata(column).inner_func)}                             
     return ColumnIdentifier(col_id, column, metadata)
Пример #7
0
 def get_column_identifier(self, column):
     col_id = self.__model_identifier + Column.get_column_name(column)
     metadata = {'args': getargspec(Column.get_metadata(column).inner_func)}
     return ColumnIdentifier(col_id, column, metadata)
Пример #8
0
 def testGetMetadata(self):
     col = Column(lambda x: x, True)
     metadata = Column.get_metadata(col)
     self.assertIsInstance(metadata, ColumnMetadata, \
                           'Expected column metadata')