def calc_stats_and_plot()

in perfrunbook/utilities/measure_and_plot_basic_sysstat_stats.py [0:0]


def calc_stats_and_plot(df, stat, yaxis_range=None):
    """
    Function that calculates the common stats and 
    plots the data.
    """
    df['time_delta'] = (df.index - df.index[0]).seconds
    df = df.set_index('time_delta')

    if yaxis_range:
        limit = yaxis_range
    else:
        limit = (0, df[stat].max() + 1)

    # Calculate some meaningful aggregate stats for comparing time-series plots
    geomean = stats.gmean(df[stat])
    p50 = stats.scoreatpercentile(df[stat], 50)
    p90 = stats.scoreatpercentile(df[stat], 90)
    p99 = stats.scoreatpercentile(df[stat], 99)
    xtitle = f"gmean:{geomean:>6.2f} p50:{p50:>6.2f} p90:{p90:>6.2f} p99:{p99:>6.2f}"

    plot_terminal(df, stat, xtitle, limit)