Decorator for State Measures that only require the analysis_collection and parameters

    Saves return value to analysis_collection.state.meta with the State Measure's name as the key
161996
def analysis_collection_and_parameter_meta(state_measure_function):
    
    def wrapped_function(state_measure, analysis_collection, state_collection, overriding_parameters=None):
        measure_parameters = get_measure_parameters(state_measure, overriding_parameters)
        measure_value= state_measure_function(analysis_collection,measure_parameters)
        analysis_collection.state.meta[state_measure.name] = measure_value
        return analysis_collection
    return wrapped_function
1182775
def store_meta(self,meta):
        ""
        if self.meta is None:
            self.meta = {}
        self.meta.update(meta)
        return self
1043348
def get_state(self, **kwargs):
        ''''''
        dbdata = self.dbdata
        if 'state' not in dbdata or kwargs:
            dbdata['state'] = ModelState(self, **kwargs)
        return dbdata['state']
1117193
def scale_meta_data_according_state(models_dict, rel_pos=None, as_template=False, fill_up=False):
    # TODO Documentation needed....
    
    # TODO check about positions of input-data- and output-data- or scoped variable-ports is needed
    # TODO adjustments of data ports positions are not sufficient -> origin state size is maybe needed for that
    # TODO consistency check on boundary and scale parameter for every if else case

    if 'states' in models_dict or 'scoped_variables' in models_dict:
        left, right, top, bottom = get_boundaries_of_elements_in_dict(models_dict=models_dict)
        parent_size = models_dict['state'].get_meta_data_editor()['size']
        margin, old_rel_pos, size = cal_frame_according_boundaries(left, right, top, bottom, parent_size, group=False)
        automatic_mode = True if rel_pos is None else False
        clearance = 0.2 if rel_pos is None else 0.
        rel_pos = (margin, margin) if rel_pos is None else rel_pos
        # rel_pos = (0., 0.) if fill_up else rel_pos
        clearance_scale = 1 + clearance

        assert parent_size[0] > rel_pos[0]
        assert parent_size[1] > rel_pos[1]
        # print("edges:", left, right, top, bottom)
        # print("margin:", margin, "rel_pos:", rel_pos, "old_rel_pos", old_rel_pos, "size:", size)

        parent_width, parent_height = parent_size

        boundary_width, boundary_height = size
        # print("parent width:   {0}, parent_height:   {1}".format(parent_width, parent_height))
        # print("boundary width: {0}, boundary_height: {1}".format(boundary_width, boundary_height))

        # no site scale
        if parent_width - rel_pos[0] > boundary_width * clearance_scale and \
                parent_height - rel_pos[1] > boundary_height * clearance_scale and not fill_up:
            if automatic_mode:
                resize_factor = 1.
                boundary_width_in_parent = boundary_width*resize_factor
                # print(boundary_width, resize_factor, boundary_width*resize_factor, boundary_height*resize_factor + margin*2, parent_height)
                # print("left over width: ", parent_width - boundary_width_in_parent - rel_pos[0] - margin)
                width_pos_offset_to_middle = (parent_width - boundary_width_in_parent - rel_pos[0] - margin)/2.
                rel_pos = add_pos(rel_pos, (width_pos_offset_to_middle, 0.))
                boundary_height_in_parent = boundary_height*resize_factor
                # print("left over height: ", parent_height - boundary_height_in_parent - rel_pos[0] - margin)
                height_pos_offset_to_middle = (parent_height - boundary_height_in_parent - rel_pos[1] - margin)/2.
                rel_pos = add_pos(rel_pos, (0., height_pos_offset_to_middle))
            offset = subtract_pos((0., 0.), subtract_pos(old_rel_pos, rel_pos))
            offset_rel_pos_of_all_models_in_dict(models_dict, offset)
            return 1, 1  # (1, 1), offset, rel_pos
        # smallest site scale
        else:
            # increase of boundary or clearance results into bigger estimated size and finally stronger
            # reduction of original element sizes
            left, right, top, bottom = get_boundaries_of_elements_in_dict(models_dict=models_dict, clearance=clearance)
            parent_size = models_dict['state'].get_meta_data_editor()['size']
            margin, old_rel_pos, size = cal_frame_according_boundaries(left, right, top, bottom, parent_size, group=False)

            rel_pos = (margin, margin) if rel_pos is None else rel_pos
            assert parent_size[0] > rel_pos[0]
            assert parent_size[1] > rel_pos[1]
            # print("edges:", left, right, top, bottom)
            # print("margin:", margin, "rel_pos:", rel_pos, "old_rel_pos", old_rel_pos, "size:", size)

            parent_width, parent_height = parent_size

            boundary_width, boundary_height = size
            if (parent_height - rel_pos[1] - margin)/boundary_height < \
                    (parent_width - rel_pos[0] - margin)/boundary_width:
                # print("#2"*20, 1, "#"*20, rel_pos)
                resize_factor = (parent_height - rel_pos[1] - margin)/boundary_height
                boundary_width_in_parent = boundary_width*resize_factor
                # print(boundary_width, resize_factor, boundary_width*resize_factor)
                # print("left over width: ", parent_width - boundary_width_in_parent - rel_pos[0] - margin)
                width_pos_offset_to_middle = (parent_width - boundary_width_in_parent - rel_pos[0] - margin)/2.
                rel_pos = add_pos(rel_pos, (width_pos_offset_to_middle, 0.))
                # print(resize_factor, rel_pos)
            else:
                # print("#2"*20, 2, "#"*20, rel_pos)
                resize_factor = (parent_width - rel_pos[0] - margin)/boundary_width
                boundary_height_in_parent = boundary_height*resize_factor
                # print(boundary_width, resize_factor, boundary_width*resize_factor)
                # print("left over height: ", parent_height - boundary_height_in_parent - rel_pos[0] - margin)
                height_pos_offset_to_middle = (parent_height - boundary_height_in_parent - rel_pos[1] - margin)/2.
                rel_pos = add_pos(rel_pos, (0., height_pos_offset_to_middle))
                # print(resize_factor, rel_pos)
            frame = {'rel_pos': rel_pos, 'size': mult_two_vectors((resize_factor, resize_factor), size)}
            # print(models_dict['state'].get_meta_data_editor()['rel_pos'], \)
            #     parent_size, models_dict['state'].parent.get_meta_data_editor()['size']
            # print("frame", frame, resize_factor)
            # # rel_pos = mult_two_vectors((1, -1), frame['rel_pos'])
            offset = subtract_pos((0., 0.), old_rel_pos)
            offset_rel_pos_of_all_models_in_dict(models_dict, offset)

            resize_of_all_models_in_dict(models_dict, (resize_factor, resize_factor))

            offset_rel_pos_of_all_models_in_dict(models_dict, frame['rel_pos'])
            # scale_meta_data_according_frame(models_dict, frame)
            return resize_factor, resize_factor  # (resize_factor, resize_factor) , offset, frame['rel_pos']
    else:
        return 1, 1
1204989
def consume(self, state):
        
        self.state.append(self.func(state))
        return self.state
1335056
function(state) {
      var includes = state.parent ? extend({}, state.parent.includes) : {};
      includes[state.name] = true;
      return includes;
    }
881630
def load_state(self, state):
        
        state_data = state[self.name]
        if isinstance(state_data["resp_args"]["name_id_policy"], str):
            state_data["resp_args"]["name_id_policy"] = name_id_policy_from_string(
                state_data["resp_args"]["name_id_policy"])
        return state_data
77820
def PushState(self, **unused_kwargs):
    """"""
    logging.debug('Storing state {0:s}'.format(repr(self.state)))
    self.state_stack.append(self.state)
1363080
def wrap(self, data):
        
        for name, field in self.fields:
            try:
                self._state[name] = field.consume(
                    self._state.get(name, None), data[name])
            except KeyError:
                self._state[name] = None
571760
def collect_metrics():
    
    def _register(action):
        handler = Handler.get(action)
        handler.add_predicate(partial(_restricted_hook, 'collect-metrics'))
        return action
    return _register
821073
def get_state_estimates_by_state(
        self, api, table, variable, estimate, state
    ):
        
        state = Division.objects.get(level=self.STATE_LEVEL, code=state)
        state_data = api.get(
            ("NAME", estimate),
            {"for": "state:{}".format(state.code)},
            year=int(table.year),
        )
        for datum in state_data:
            self.write_state_estimate(table, variable, estimate, datum)
734136
def collect_analysis(using):
    
    python_analysis = defaultdict(dict)
    for index in registry.indexes_for_connection(using):
        python_analysis.update(index._doc_type.mapping._collect_analysis())

    return stringer(python_analysis)
339554
def add_metaclass(metaclass):
    
    vars_to_skip = ('__dict__', '__weakref__')

    def wrapper(cls):
        copied_dict = {
            key: value
            for key, value in cls.__dict__.items()
            if key not in vars_to_skip
        }
        return metaclass(cls.__name__, cls.__bases__, copied_dict)
    return wrapper
836168
def _use_provider_states(
        provider_state_fixtures_with_params: List[Tuple[ProviderStateFixture, Dict]]
) -> Generator:
    """"""
    with contextlib.ExitStack() as stack:
        for provider_state_fixture, params in provider_state_fixtures_with_params:
            stack.enter_context(provider_state_fixture(**params))

        yield
473399
def gauge(self, key, gauge=None, default=float("nan"), **dims):
        """"""
        return super(MetricsRegistry, self).gauge(
            self.metadata.register(key, **dims), gauge=gauge, default=default)
597535
def state_index ( state )
      raise TypeError, ps.class.to_s + ': Incorrectly types for \'state_index\' method of <Parser>.' unless
	state.instance_of? State
	
      @states.each_with_index do |st,i|
	return i if state == st
      end
      raise "State <#{state.statename}> is not exist in Parser."
    end
1366216
def get_meta(self, key=None):
        """"""
        if self.is_fake:
            return {}

        if key == "tag":
            return self.tag
        elif key is None:
            ret = {}
            for key in self.journal.info.keys():
                ret[key] = self.meta_mappings.map_get(self.journal.info, key)[1]
            return ret
        else:
            key, value = self.meta_mappings.map_get(self.journal.info, key)
            return value