Ejemplo n.º 1
0
def load_basic_tools(fname="basic.gl"):
    parser = Parser()
    parser.parse_file(fname)
    tool_dict = parser.tool_dict
    basic_tools = ImportedTools(tool_dict)
    basic_tools.line.add_symmetry((1, 0))
    basic_tools.dist.add_symmetry((1, 0))
    basic_tools.intersection_ll.add_symmetry((1, 0))
    basic_tools.midpoint.add_symmetry((1, 0))
    add_movable_tools(tool_dict, basic_tools)
    return ImportedTools(tool_dict)
Ejemplo n.º 2
0
def prepare_data(filename):
    """
    Parse and classify text from file with given filename to prepare data to
    generate the report.
    """
    parser = Parser()
    classifier = Classifier()

    class_duration = {    # Dictionary for duration of each class
        'W': timedelta(hours=0, minutes=0),
        'R': timedelta(hours=0, minutes=0),
        'N': timedelta(hours=0, minutes=0),
    }
    action_durations = {} # Dictionary for duration of each action

    activities = parser.parse_file(filename)
    for activity in activities:
        duration = activity['duration']
        actions = activity['actions']

        divided_duration = duration / len(actions)
        for action in actions:
            classification = classifier.classify_action(action)
            class_duration[classification] += divided_duration
            if action in action_durations:
                action_durations[action] += divided_duration
            else:
                action_durations[action] = divided_duration

    sorted_action_durations = sorted(action_durations.items(),
                                     key=lambda tup: tup[1], reverse=True)

    # Add structure to data and return
    plot_data = {
        'summary_pie_chart': {
            'class_duration': class_duration,
        },
    }
    report_data = {
        'sorted_action_durations': sorted_action_durations,
        'class_duration': class_duration,
        'timedelta_to_string': timedelta_to_string,
    }
    return plot_data, report_data
Ejemplo n.º 3
0
def load_tools(fname):
    basic_tools = load_basic_tools()
    parser = Parser(basic_tools.tool_dict)
    parser.parse_file(fname, axioms=False, basic_tools=basic_tools)
    return ImportedTools(parser.tool_dict)
Ejemplo n.º 4
0
    def load_file(self, fname):
        self.viewport.reset_tool()
        if fname is None: return
        self.update_title(fname)
        parser = Parser(self.imported_tools.tool_dict)
        parser.parse_file(fname, axioms=True)
        loaded_tool = parser.tool_dict['_', ()]
        steps = loaded_tool.assumptions
        names = [
            loaded_tool.var_to_name_proof[x]
            for x in range(len(loaded_tool.var_to_name_proof))
        ]
        if loaded_tool.implications:
            goals, proof = loaded_tool.implications, loaded_tool.proof
        else:
            goals, proof = None, None
        self.env.set_steps(steps, names=names, goals=goals, proof=proof)

        # hide objects
        visible = set(loaded_tool.result)  # old format
        if visible:
            for gi in range(len(self.vis.gi_to_hidden)):
                self.vis.gi_to_hidden[gi] = gi not in visible
        for gi, name in enumerate(names):  # new format
            if ("hide__{}".format(name), ()) in parser.tool_dict:
                self.vis.gi_to_hidden[gi] = True

        # set labels
        for gi, name in enumerate(names):  # new format
            label_pos_tool = parser.tool_dict.get(
                ("label__{}".format(name), ()), None)
            if label_pos_tool is not None:
                self.vis.gi_label_show[gi] = True
                logic = LogicalCore(basic_tools=self.imported_tools)
                pos_l = label_pos_tool.run((), (), logic, 0)
                pos_n = [logic.num_model[x] for x in pos_l]
                t = self.vis.gi_to_type(gi)
                if t == Point:
                    point, = pos_n
                    position = point.a
                    print(position)
                elif t == Line:
                    position = tuple(d.x for d in pos_n)
                elif t == Circle:
                    ang, offset = pos_n
                    position = ang.data * 2, offset.x
                else:
                    print(
                        "Warning: save label: unexpected type {} of {}".format(
                            t, name))
                    continue
                self.vis.gi_label_position[gi] = position

        self.vis.refresh()

        # viewport zoom and position
        view_data_tool = parser.tool_dict.get(('view__data', ()), None)

        if view_data_tool is None:
            self.viewport.set_zoom((375, 277), 1)
        else:
            logic = LogicalCore(basic_tools=self.imported_tools)
            anchor_l, zoom_l = view_data_tool.run((), (), logic, 0)
            anchor = logic.num_model[anchor_l].a
            zoom = logic.num_model[zoom_l].x
            self.viewport.set_zoom(anchor, zoom)

        self.reset_view()