Esempio n. 1
0
 def get_value(self, x, y):
     # PRECONDITION:  0 <= x <= 1,  0 <= y <= 1
     for n in (x, y, self.size_x, self.size_y):
         if not is_number(n):
             print n, 'is not a FLOAT!!!'  # ***
             exit()
     return self.current_value[int(round(x * self.size_x)),
                               int(round(y * self.size_y))]
Esempio n. 2
0
 def to_string(self, data):
     if is_number(data):
         return round(float(data), 2).__str__()
     elif is_dict(data):
         return dictionary_to_string(data)
     elif is_function(data):
         return self.to_string(data(self))
     elif hasattr(data, '__iter__'):
         return (self.to_string(item) for item in data)
     else:
         return data.__str__()
Esempio n. 3
0
 def check(*kew_words):
     # This checks if it's time to store the
     # element referenced with kew_words
     code = self.elements_to_store
     for kew_word in kew_words:
         if is_dict(code) and kew_word in code:
             code = code[kew_word]
         else:
             return False
     return ((code == 'Once' and self.parent_ecosystem.time == 0)
             or (is_number(code)
                 and round(self.parent_ecosystem.time / code)
                 == self.parent_ecosystem.time / code))
Esempio n. 4
0
def check_inputs_of_discrete_distribution(*inputs):
    if not is_tuple_or_list(inputs):
        return False
    total = 0
    for pair in inputs:
        if is_tuple_or_list(pair) and len(pair) == 2 and is_number(pair[1]):
            total += pair[1]
        else:
            return False
    if total == 1:
        return True
    else:
        return False
Esempio n. 5
0
    def make_function(self, function_settings, tags_list=None):
        remove_no_effect_directives(function_settings)
        if tags_list is not None:
            self.tags_list = tags_list
        if print_methods_names:  # ***
            print 'make_function', self.tags_list
            print function_settings

        if is_number(function_settings):
            return lambda *arguments: function_settings

        elif is_function(function_settings):
            return function_settings

        elif is_string(function_settings):
            return self.make_function_from_string(function_settings)

        elif is_tuple_or_list(function_settings):
            terms = [self.make_function(item) for item in function_settings]
            return lambda *arguments: [item(*arguments) for item in terms]

        elif is_dict(function_settings):
            function_to_return = self.make_function_from_dict(
                function_settings)
            if 'allowed interval' in function_settings:
                allowed_interval = self.make_function(
                    function_settings['allowed interval'])
                return self.constrain_function_to_allowed_interval(
                    function_to_return, allowed_interval)
            else:
                return function_to_return

        else:
            self.error_messenger('Warning. Unevaluated function settings:',
                                 str(function_settings), 'y tal',
                                 type(function_settings), 'y eso')
            return lambda *arguments: function_settings