コード例 #1
0
ファイル: graphs.py プロジェクト: DigitME2/oee_server
def create_machine_gantt(machine_id, graph_start, graph_end, hide_jobless=False):
    """ Create a gantt chart of the usage of a single machine, between the two timestamps provided"""

    if machine_id is None:
        return "This machine does not exist"

    activities = get_machine_activities(machine_id=machine_id, timestamp_start=graph_start, timestamp_end=graph_end)
    # Sort the activities so that uptime is always the first.
    # This is a workaround to make the graph always show uptime on the bottom
    activities.sort(key=sort_activities, reverse=True)

    df = get_activities_df(activities=activities, group_by="activity_code", graph_start=graph_start,
                           graph_end=graph_end)

    if len(df) == 0:
        return "No machine activity"

    machine = Machine.query.get(machine_id)
    graph_title = f"{machine.name} OEE"

    # Create the colours dictionary using codes' colours from the database
    colours = {}
    for act_code in ActivityCode.query.all():
        colours[act_code.short_description] = act_code.graph_colour

    fig = ff.create_gantt(df,
                          title=graph_title,
                          group_tasks=True,
                          colors=colours,
                          index_col='Code',
                          bar_width=0.4,
                          show_colorbar=True)

    # Create a layout object using the layout automatically created
    layout = Layout(fig['layout'])
    layout = apply_default_layout(layout)
    layout.showlegend = True

    # Highlight jobs
    layout = highlight_jobs(activities, layout)

    # Pass the changed layout back to fig
    fig['layout'] = layout
    config = {'responsive': True}
    return plot(fig, output_type="div", include_plotlyjs=True, config=config)
コード例 #2
0
ファイル: graphs.py プロジェクト: DigitME2/oee_server
def create_multiple_machines_gantt(graph_start, graph_end, machine_ids):
    """ Creates a gantt plot of OEE for all machines in the database between given times
    graph_start = the start time of the graph
    graph_end = the end time of the graph
    machine_ids = a list of ids to include in the graph"""

    activities = []
    machine_ids.sort()
    for machine_id in machine_ids:
        machine_activities = get_machine_activities(machine_id=machine_id, timestamp_start=graph_start,
                                                    timestamp_end=graph_end)
        # If a machine has no activities, add a fake one so it still shows on the graph
        if len(machine_activities) == 0:
            activities.append(Activity(timestamp_start=graph_start, timestamp_end=graph_start))
        else:
            activities.extend(machine_activities)

    df = get_activities_df(activities=activities,
                           group_by="machine_name",
                           graph_start=graph_start,
                           graph_end=graph_end,
                           crop_overflow=True)

    if len(df) == 0:
        return "No machine activity"
    # Create the colours dictionary using codes' colours from the database
    colours = {}
    for act_code in ActivityCode.query.all():
        colours[act_code.short_description] = act_code.graph_colour
    fig = ff.create_gantt(df,
                          group_tasks=True,
                          colors=colours,
                          index_col='Code',
                          bar_width=0.4)

    # Create a layout object using the layout automatically created
    layout = Layout(fig['layout'])
    layout = apply_default_layout(layout)
    layout.showlegend = True
    fig['layout'] = layout
    config = {'responsive': True}
    return plot(fig, output_type="div", include_plotlyjs=True, config=config)