Esempio n. 1
0
def getResponseTimeAvg(checks):
    """Return the average of the response times
    
    Arguments:
    - checks: A dictionary (key: check time) of pingdomcheck.PingdomCheck objects
    """
    x, y = PingdomCheck.getArrayData(checks)
    
    avg = 0
    for resp_time in y:
        avg += resp_time
    avg /= len(x)
    return avg
Esempio n. 2
0
def computeLinearRegressionModel(checks):
    """Compute a linear regression model for experimental measures.
    
    The model is a function y' = ax + b which best fit the scatter plot of given experimental measures.
    
    Arguments:
    - x, y : vectors (lists) of measures
    
    Return: [a, b], the coefficient of the linear regression model
    """
    
    def sum_vector(n, x):
        sum = 0
        for i in range(n):
            sum += x[i]
        return sum
    
    def sum_vector_power(n, x, power):
        sum = 0
        for i in range(n):
            sum += pow(x[i], power)
        return sum
        
    def sum_xiyi(n, x, y):
        sum = 0
        for i in range(n):
            sum += x[i] * y[i]
        return sum
    
    x, y = PingdomCheck.getArrayData(checks)
    
    n = len(x)
    if(n != len(y)):
        raise Exception('You must have the same count of measures in x and y vectors.')
    
    a = float((n * sum_xiyi(n, x, y) - sum_vector(n, x) * sum_vector(n, y))) / float((n * sum_vector_power(n, x, 2) - pow(sum_vector(n, x), 2)))
    b = float((sum_vector(n, y) * sum_vector_power(n, x, 2) - sum_vector(n, x) * sum_xiyi(n, x, y))) / float((n * sum_vector_power(n, x, 2) - pow(sum_vector(n, x), 2)))
    
    return [a, b]
Esempio n. 3
0
    def plot(
        checks,
        rep_time_avg,
        reg_coef,
        response_time_low,
        response_time_high,
        settlement="",
        file="out.ps",
        terminal="postscript",
    ):
        """Plot a graph of the check results.
        
        Arguments:
        - checks: dictionary of checks results (see pingdom.PingdomCheck class)
        - rep_time_avg: The average response time
        - reg_coef: The coefficient of the linear regression model
        - response_time_low: The lower bound of response time
        - response_time_high: The higher bound of response time
        - settlement: (optional; default: blank string) The scaling decision to display on the graph
        - file: (optional; default: "out.ps") The destination path+filename of the plotted graph
        - terminal (optional; default: "postscript") The file type to use
        """
        x, y = PingdomCheck.getArrayData(checks)
        checks_count = len(x)

        reg_values = []
        for time in x:
            reg_values.append(reg_coef[0] * time + reg_coef[1])

        first_time = x[0]
        plot_times = [(time - first_time) for time in x]

        checks_graph = Gnuplot.Data(plot_times, y, title="Pingdom checks", with_='lines lc rgb "red" lw 2')
        average_graph = Gnuplot.Data(
            plot_times, [rep_time_avg] * checks_count, title="Avg. response time", with_='lines lc rgb "green" lw 1'
        )
        resp_time_low_graph = Gnuplot.Data(
            plot_times,
            [response_time_low] * checks_count,
            title="Resp. time low bound",
            with_='lines lc rgb "grey" lw 1',
        )
        resp_time_high_graph = Gnuplot.Data(
            plot_times,
            [response_time_high] * checks_count,
            title="Resp. time high bound",
            with_='lines lc rgb "grey" lw 1',
        )
        lin_reg_graph = Gnuplot.Data(
            plot_times, reg_values, title="Resp. time tendency", with_='lines lc rgb "blue" lw 1'
        )

        g = Gnuplot.Gnuplot()

        g.set_string("output", file)
        g("set terminal %s" % terminal)

        if settlement != "":
            g.set(title="Settlement: " + settlement)

        g.xlabel("Time (s)")
        g.ylabel("Response time (ms)")

        g.plot(checks_graph, average_graph, resp_time_low_graph, resp_time_high_graph, lin_reg_graph)