def p2SLR_predict(tData_xy, base_date, end_date, predict_start_date, predict_end_date, flavor_names): # Make prediction predict_start_x = parser.cal_day(base_date, predict_start_date) predict_end_x = parser.cal_day(base_date, predict_end_date) predict_flavors = [] tDays = parser.cal_day(base_date, end_date) pDays = parser.cal_day(base_date, predict_end_date) - parser.cal_day( base_date, predict_start_date) flavors_wb = {} new_tData_xy = {} for key in tData_xy.keys(): new_tData_xy[key] = tData_xy[key][-7:] flavors_wb = get_flavors_wb(new_tData_xy) print 'flavors_wb:', flavors_wb for each in flavor_names: num = tData_xy[each][-1][1] # get the num of the following weekend's machines #### pflavor_num = (tDays + pDays) * flavors_wb[each][0] + flavors_wb[each][1] - num pflavor_num *= 1.1 if pflavor_num < 0: pflavor_num = 0 elif pflavor_num - int(pflavor_num) < 0.5: pflavor_num = int(pflavor_num) + 1 else: pflavor_num = int(pflavor_num) print ' pflavor_num: ', pflavor_num predict_flavors.append((each, pflavor_num)) return predict_flavors
def ls_predict(tData_xy=None, base_date=None, end_date=None, predict_start_date=None, predict_end_date=None, flavor_names=None): predict_flavors = [] tDays = parser.cal_day(base_date, end_date) pDays = parser.cal_day(base_date, predict_end_date) - parser.cal_day( base_date, predict_start_date) # print tData_xy new_tData_xy = {} for each in flavor_names: x = [] y = [] new_tData_xy[each] = tData_xy[each][-pDays:] for t in new_tData_xy[each]: x.append(t[0]) y.append(t[1]) a, b = calcAB(x, y) print a, b py = a * (tDays + pDays) + b if py < tData_xy[each][-1][1]: num = tData_xy[each][-1][1] num = int(round(num * pDays / tDays)) else: num = py - tData_xy[each][-1][1] #num = int(round(num*pDays/tDays)) predict_flavors.append((each, int(num))) print predict_flavors return predict_flavors
def average_predict(tData_xy=None, base_date=None, end_date=None, predict_start_date=None, predict_end_date=None, flavor_names=None): predict_flavors = [] tDays = parser.cal_day(base_date, end_date) pDays = parser.cal_day(base_date, predict_end_date) - parser.cal_day( base_date, predict_start_date) for each in flavor_names: num = tData_xy[each][-1][1] num = num * pDays / tDays predict_flavors.append((each, num)) return predict_flavors
def p1SLR_predict(tData_xy, base_date, end_date, predict_start_date, predict_end_date, flavor_names): # Make prediction predict_start_x = parser.cal_day(base_date, predict_start_date) predict_end_x = parser.cal_day(base_date, predict_end_date) predict_flavors = [] tDays = parser.cal_day(base_date, end_date) pDays = parser.cal_day(base_date, predict_end_date) - parser.cal_day( base_date, predict_start_date) flavors_wb1 = {} flavors_wb2 = {} new_tData_xy1 = {} new_tData_xy2 = {} for key in tData_xy.keys(): new_tData_xy1[key] = tData_xy[key][-7:] new_tData_xy2[key] = tData_xy[key][-4:] print tData_xy[key] print new_tData_xy1[key] print new_tData_xy2[key] print '-' * 20 flavors_wb1 = get_flavors_wb(new_tData_xy1) flavors_wb2 = get_flavors_wb(new_tData_xy2) for each in flavor_names: num = tData_xy[each][-1][1] # get the num of the following weekend's machines #### pflavor_num1 = ( tDays + pDays) * flavors_wb1[each][0] + flavors_wb1[each][1] - num pflavor_num2 = ( tDays + pDays) * flavors_wb2[each][0] + flavors_wb2[each][1] - num rate = 0.598 pflavor_num = pflavor_num1 * rate + pflavor_num2 * ( 1 - rate) + random.randint(-1, 1) if pflavor_num < 0: pflavor_num = 0 elif pflavor_num - int(pflavor_num) < 0.5: pflavor_num = int(pflavor_num) + 1 else: pflavor_num = int(pflavor_num) print ' pflavor_num: ', pflavor_num predict_flavors.append((each, pflavor_num)) return predict_flavors
def SLR_predict(tData_xy, base_date, end_date, predict_start_date, predict_end_date, flavor_names): #for key in tData_xy.keys(): #new_tData_xy[key] = tData_xy[key][-14:-1] #print 'new_data_xy:', new_tData_xy #flavors_wb = get_flavors_wb(new_tData_xy) # Make prediction predict_start_x = parser.cal_day(base_date, predict_start_date) predict_end_x = parser.cal_day(base_date, predict_end_date) predict_flavors = [] tDays = parser.cal_day(base_date, end_date) pDays = parser.cal_day(base_date, predict_end_date) - parser.cal_day( base_date, predict_start_date) #get the everyday of the predicted day's flavors number for day in range(pDays): for each in flavor_names: new_tData_xy = {} for key in tData_xy.keys(): new_tData_xy[key] = tData_xy[key][-7 - day:] flavors_wb = get_flavors_wb(new_tData_xy) wangNum = (tDays + day + 1) * flavors_wb[each][0] + flavors_wb[each][1] if wangNum < 0: wangNum = 0 elif wangNum - int(wangNum) < 0.5: wangNum = int(wangNum) + 1 else: wangNum = int(wangNum) new_tData_xy[each].append((tDays + day + 1, wangNum)) #print 'new ....' ,new_tData_xy # get the num of the following weekend's machines #### for each in flavor_names: #print 'new_tData_xy[', each , '][-1][1]', new_tData_xy[each][-1][1] #print 'new_tData_xy[each][-8][1]', new_tData_xy[each][-8][1] pWeek_flavor_num = new_tData_xy[each][-1][1] - new_tData_xy[each][-8][1] predict_flavors.append((each, pWeek_flavor_num)) #print 'predict_flavors:', predict_flavors return predict_flavors
def tls_predict(tData_xy=None, base_date=None, end_date=None, predict_start_date=None, predict_end_date=None, flavor_names=None): predict_flavors = [] tDays = parser.cal_day(base_date, end_date) pDays = parser.cal_day(base_date, predict_end_date) - parser.cal_day( base_date, predict_start_date) # print tData_xy new_tData_xy = {} for each in flavor_names: x = [] y = [] new_tData_xy[each] = tData_xy[each][-7:] for t in new_tData_xy[each]: x.append(t[0]) y.append(t[1]) a, b, y_begin, y_end = calcAB2(x, y) print a, b mid = (x[0] + x[-1]) / 2 half = mid - x[0] emm = (tDays + pDays - mid) / half py = a * (emm) * 1.0273 + b py = restore_scale1([py], y_begin, y_end)[0] if py < tData_xy[each][-1][1]: num = tData_xy[each][-1][1] num = int(round(num * pDays / tDays)) else: num = py - tData_xy[each][-1][1] #num = int(round(num*pDays/tDays)) predict_flavors.append((each, int(num))) print predict_flavors return predict_flavors
def average_predict(tData_xy=None, base_date=None, end_date=None, predict_start_date=None, predict_end_date=None, flavor_names=None): predict_flavors = [] tDays = parser.cal_day(base_date, end_date) pDays = parser.cal_day(base_date, predict_end_date) - parser.cal_day( base_date, predict_start_date) for each in flavor_names: num = tData_xy[each][-1][1] - tData_xy[each][1][1] d = tData_xy[each][-1][0] - tData_xy[each][-4][0] if d == 0: num = int(num * pDays / tDays) else: num = int(num * pDays / d) predict_flavors.append((each, num)) return predict_flavors