def _linCoeff(self,h_data): vals = map(lambda x: [x.value,x.pstart],h_data) vals = vals + map(lambda x: [x.value,x.pend],h_data) coeff = linreg.linearRegression(vals,1) log("linreg coeff = " + repr(coeff)) # y = mx + b # b,m = coeff return coeff
def try_linreg(h_data): vals = map(lambda x: [x.value, x.pstart], h_data) coeff = linreg.linearRegression(vals, 1) print coeff def lin_f(x, par): m, b = par return (m * x) + b def lin_fsolve(y, par): m, b = par return (y - b) / m b, m = coeff values = m, b print "today: ", lin_f(time.time(), values) print "next week: ", lin_f(time.time() + (86400 * 7), values) print "hit 90 at: ", time.asctime(time.localtime(lin_fsolve(90.0, values))) print "hit 100 at: ", time.asctime(time.localtime(lin_fsolve(100.0, values)))