Perform the ETA and rate calculation.

        Two linear lines are used to calculate the ETA: the linear regression (line through a scatter-plot), and the
        fitted line (a line that runs through the latest data point in _timing_data but parallel to the linear
        regression line).

        As the percentage moves closer to 100%, _calculate() gradually uses the ETA based on the fitted line more and
        more. This is done to prevent an ETA that's in the past.

        http://code.activestate.com/recipes/578914-simple-linear-regression-with-pure-python/
        http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient

def _calculate(self):
        """Perform the ETA and rate calculation.

        Two linear lines are used to calculate the ETA: the linear regression (line through a scatter-plot), and the
        fitted line (a line that runs through the latest data point in _timing_data but parallel to the linear
        regression line).

        As the percentage moves closer to 100%, _calculate() gradually uses the ETA based on the fitted line more and
        more. This is done to prevent an ETA that's in the past.

        http://code.activestate.com/recipes/578914-simple-linear-regression-with-pure-python/
        http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient
        """
        # Calculate means and standard deviations.
        mean_x = sum(i[0] for i in self._timing_data) / len(self._timing_data)
        mean_y = sum(i[1] for i in self._timing_data) / len(self._timing_data)
        std_x = sqrt(sum(pow(i[0] - mean_x, 2) for i in self._timing_data) / (len(self._timing_data) - 1))
        std_y = sqrt(sum(pow(i[1] - mean_y, 2) for i in self._timing_data) / (len(self._timing_data) - 1))

        # Calculate coefficient.
        sum_xy, sum_sq_v_x, sum_sq_v_y = 0, 0, 0
        for x, y in self._timing_data:
            x -= mean_x
            y -= mean_y
            sum_xy += x * y
            sum_sq_v_x += pow(x, 2)
            sum_sq_v_y += pow(y, 2)
        pearson_r = sum_xy / sqrt(sum_sq_v_x * sum_sq_v_y)

        # Calculate regression line. y = mx + b where m is the slope and b is the y-intercept.
        m = self.rate = pearson_r * (std_y / std_x)
        if self.undefined:
            return
        y = self.denominator
        b = mean_y - m * mean_x
        x = (y - b) / m

        # Calculate fitted line (transformed/shifted regression line horizontally).
        fitted_b = self._timing_data[-1][1] - (m * self._timing_data[-1][0])
        fitted_x = (y - fitted_b) / m
        adjusted_x = ((fitted_x - x) * (self.numerator / self.denominator)) + x
        self.eta_epoch = adjusted_x