mikrokosmos/objects.py
def resolve_objects(scenario):
    """Resolve a set of classes, generate objects, resolve objects"""

    set_seed(scenario)
    faker = init_faker(scenario)

    @attr.s
    class Context:
        faker = attr.ib()
        scenario = attr.ib()

    ctx = Context(faker, scenario)

    objects = []
    triggered_objects = []
    outputs = []

    classes = [
        cls for cls in scenario['objects']
        if cls.get('count')
    ]
    triggered_classes = [
        cls for cls in scenario['objects']
        if (cls.get('trigger') or cls.get('triggers'))
    ]

    for cls in classes:
        Class = resolve_class(cls, ctx)

        output = cls.get('output')

        for i in range(cls.get('count')):
            obj = Class()
            objects.append(obj)

            if output:
                resolved_output = recursive_resolve(output, obj)
                outputs.append(resolved_output)

    for cls in triggered_classes:
        Class = resolve_class(cls, ctx)

        triggers = [cls.get('trigger')]
        if not triggers[0]:
            triggers = cls.get('triggers')

        trigger_objs = []

        for obj in objects:
            obj_class = obj.__class__.__name__

            for trigger in triggers:

                tri_class, field, comp_func, tri_value = resolve_trigger(trigger)
                obj_value = getattr(obj, field)

                if obj_class == tri_class and comp_func(obj_value, tri_value):
                    if obj not in trigger_objs:
                        trigger_objs.append(obj)

        output = cls.get('output')

        def gen_obj_output(trigger_obj):
            obj = Class()
            triggered_objects.append(obj)

            if output:
                resolved_output = recursive_resolve(output, obj, trigger_obj, trigger_objs)
                outputs.append(resolved_output)

        # TODO: This is crazy wrong, but will do for now
        if len(triggers) > 1:
            gen_obj_output(trigger_objs[0])
        else:
            for trigger_obj in trigger_objs:
                gen_obj_output(trigger_obj)

    return outputs
Resolve a set of classes, generate objects, resolve objects
Resolve a set of classes, generate objects, resolve objects
Resolve a set of classes generate objects resolve objects
def resolve_objects(scenario):
    set_seed(scenario)
    faker = init_faker(scenario)
    @attr.s
    class Context:
        faker = attr.ib()
        scenario = attr.ib()
    ctx = Context(faker, scenario)
    objects = []
    triggered_objects = []
    outputs = []
    classes = [
        cls for cls in scenario['objects']
        if cls.get('count')
    ]
    triggered_classes = [
        cls for cls in scenario['objects']
        if (cls.get('trigger') or cls.get('triggers'))
    ]
    for cls in classes:
        Class = resolve_class(cls, ctx)
        output = cls.get('output')
        for i in range(cls.get('count')):
            obj = Class()
            objects.append(obj)
            if output:
                resolved_output = recursive_resolve(output, obj)
                outputs.append(resolved_output)
    for cls in triggered_classes:
        Class = resolve_class(cls, ctx)
        triggers = [cls.get('trigger')]
        if not triggers[0]:
            triggers = cls.get('triggers')
        trigger_objs = []
        for obj in objects:
            obj_class = obj.__class__.__name__
            for trigger in triggers:
                tri_class, field, comp_func, tri_value = resolve_trigger(trigger)
                obj_value = getattr(obj, field)
                if obj_class == tri_class and comp_func(obj_value, tri_value):
                    if obj not in trigger_objs:
                        trigger_objs.append(obj)
        output = cls.get('output')
        def gen_obj_output(trigger_obj):
            obj = Class()
            triggered_objects.append(obj)
            if output:
                resolved_output = recursive_resolve(output, obj, trigger_obj, trigger_objs)
                outputs.append(resolved_output)
        if len(triggers) > 1:
            gen_obj_output(trigger_objs[0])
        else:
            for trigger_obj in trigger_objs:
                gen_obj_output(trigger_obj)
    return outputs
def resolve_objects ( scenario ) : set_seed ( scenario ) faker = init_faker ( scenario ) @ attr . s class Context : faker = attr . ib ( ) scenario = attr . ib ( ) ctx = Context ( faker , scenario ) objects = [ ] triggered_objects = [ ] outputs = [ ] classes = [ cls for cls in scenario [ 'objects' ] if cls . get ( 'count' ) ] triggered_classes = [ cls for cls in scenario [ 'objects' ] if ( cls . get ( 'trigger' ) or cls . get ( 'triggers' ) ) ] for cls in classes : Class = resolve_class ( cls , ctx ) output = cls . get ( 'output' ) for i in range ( cls . get ( 'count' ) ) : obj = Class ( ) objects . append ( obj ) if output : resolved_output = recursive_resolve ( output , obj ) outputs . append ( resolved_output ) for cls in triggered_classes : Class = resolve_class ( cls , ctx ) triggers = [ cls . get ( 'trigger' ) ] if not triggers [ 0 ] : triggers = cls . get ( 'triggers' ) trigger_objs = [ ] for obj in objects : obj_class = obj . __class__ . __name__ for trigger in triggers : tri_class , field , comp_func , tri_value = resolve_trigger ( trigger ) obj_value = getattr ( obj , field ) if obj_class == tri_class and comp_func ( obj_value , tri_value ) : if obj not in trigger_objs : trigger_objs . append ( obj ) output = cls . get ( 'output' ) def gen_obj_output ( trigger_obj ) : obj = Class ( ) triggered_objects . append ( obj ) if output : resolved_output = recursive_resolve ( output , obj , trigger_obj , trigger_objs ) outputs . append ( resolved_output ) if len ( triggers ) > 1 : gen_obj_output ( trigger_objs [ 0 ] ) else : for trigger_obj in trigger_objs : gen_obj_output ( trigger_obj ) return outputs
Resolve a set of classes, generate objects, resolve objects
Resolve a set of classes generate objects resolve objects
"""Resolve a set of classes, generate objects, resolve objects""" # TODO: This is crazy wrong, but will do for now
scenario