Ejemplo n.º 1
0
def save_plot(options, votes, poll_name):
    # prompt for desire to save plot
    save_plot = input("Press 'y' to save this plot (press any other key to go back to main menu): ")

    # save plot
    if save_plot.lower() == 'y':
        # create figure again as plt.show() destroys figure
        fig = charts.create_pie_chart(options, votes, poll_name)
        # modify poll name in order to delete special characters
        for char in ['?','*', '.', '"',"'", '/', '[', ']', ':', ';', '|']:
            poll_name = poll_name.replace(char, "").strip()
        # check OS (in order to use correct slash for saving)
        current_os = platform.system()
        # save figure with path adjusted to OS
        if current_os == 'Windows':
            plt.savefig(f"saved_plots\{poll_name}.png", dpi=400, bbox_inches='tight') 
        elif (current_os == 'Linux') or (current_os == 'Darwin') :
            plt.savefig(f"saved_plots/{poll_name}.png", dpi=400, bbox_inches='tight') 
        print(f"Plot successfully saved as '{poll_name}.png' in the following directory: 'saved_plots'")
        plt.close('all') #destroy figure
Ejemplo n.º 2
0
def create_plt_fig():
    # print all polls and IDs as guide
    polls = Poll.all()
    print("\n\t\t------Available Polls------\n\n")
    for poll in polls:
        print(f"\t\t{poll.id}: {poll.title} (created by {poll.owner})")

    # select poll of interest
    poll_id = int(input("Enter poll you'd like to see a figure for: "))
    

    # save poll name of selected poll to variable (to pass to create_pie_chart() )
    poll_name = poll_name_by_id(polls, poll_id)

    # get vote info for selected poll
    options, votes = Poll.get_info_for_plt(poll_id) 

    # create figure
    fig = charts.create_pie_chart(options, votes, poll_name)
    plt.show()

    save_plot(options, votes, poll_name)
Ejemplo n.º 3
0
def _chart_options_for_poll(poll_id):
    options = database.get_options(poll_id)
    figure = charts.create_pie_chart(options)
    plt.show()
Ejemplo n.º 4
0
def update_pie_chart_by_source(session_data):
    return charts.create_pie_chart(pd.read_json(session_data), 'source')
Ejemplo n.º 5
0
def update_pie_chart_by_name(session_data):
    return charts.create_pie_chart(pd.read_json(session_data), 'name')
Ejemplo n.º 6
0
        json.dump(event_schema, schema_file)

    return {
        'message': 'reveived event_schema',
        'event_schema': event_schema
    }, 200


app = dash.Dash(server=server,
                url_base_pathname=url_base_path,
                external_stylesheets=[dbc.themes.BOOTSTRAP])

app.config['suppress_callback_exceptions'] = True

msc = charts.create_sequence_diagram(initial_event)
number_of_event_names_pie = charts.create_pie_chart(events_df, 'name')
number_of_event_sources_pie = charts.create_pie_chart(events_df, 'source')

with open(max(glob.glob(schema_directory + '/*.json'),
              key=os.path.getctime)) as schema_file:
    event_schema = json.load(schema_file)

conditional_format, tooltips = event_schema_validation.select_events_which_are_not_valid(
    events_df, event_schema)

events_df['valid'] = conditional_format
events_df['tooltip_message'] = tooltips
events_df['delta'] = 0
events_df = charts.create_events_table(events_df)

print('\n\n\n############################## initialise app \n\n\n')