def get_i24_monthly_winning(self): # return list of monthly winning for i24 monthly_winning = [] for each_month in get_i24_combined(): this_month_winning = 0 for each_draw in each_month: this_month_winning += prize_calc.i24_prize_calc(each_draw) monthly_winning.append(this_month_winning) return i24_monthly_winning
i6 = [] for each in result_combined: new = num_cat_sort_module.get_i6(each) i6.append(new) i4 = [] for each in result_combined: new = num_cat_sort_module.get_i4(each) i12.append(new) ## calculate prize money won i24_monthly_winning = [] for each_month in i24: this_month_winning = 0 for each_draw in each_month: this_month_winning += prize_calc.i24_prize_calc(each_draw) i24_monthly_winning.append(this_month_winning) i24_total_winning = 0 for each in i24_monthly_winning: i24_total_winning += each i12_monthly_winning = [] for each_month in i12: this_month_winning = 0 for each_draw in each_month: this_month_winning += prize_calc.i12_prize_calc(each_draw) i12_monthly_winning.append(this_month_winning) i12_total_winning = 0 for each in i12_monthly_winning: i12_total_winning += each
def analyze_num_bought(num_bought): ## ========== WEB PARSING STAGE ========== ## start = "2015/08/01" end = "2015/08/31" print "Getting winnings data: " + start + " - " + end raw_result = get_data(start, end) combined_result = combine(raw_result) i24 = num_cat_sort_module.get_i24(combined_result) i12 = num_cat_sort_module.get_i12(combined_result) i6 = num_cat_sort_module.get_i6(combined_result) i4 = num_cat_sort_module.get_i4(combined_result) ## ========== CALCULATE THE NUM OF DRAW WITHIN STIPULATED RANGE ==========# draw_count = 0 for each_draw in combined_result: draw_count += each_draw[3] ## ========== GET WINNING FOR EACH NUM ========== ## i24_num_winning = {} for each_draw in i24: num = each_draw[0] amount = prize_calc.i24_prize_calc(each_draw) if num in i24_num_winning: i24_num_winning[num] += amount else: i24_num_winning[num] = amount i12_num_winning = {} for each_draw in i12: num = each_draw[0] amount = prize_calc.i12_prize_calc(each_draw) if num in i12_num_winning: i12_num_winning[num] += amount else: i12_num_winning[num] = amount i6_num_winning = {} for each_draw in i6: num = each_draw[0] amount = prize_calc.i6_prize_calc(each_draw) if num in i6_num_winning: i6_num_winning[num] += amount else: i6_num_winning[num] = amount i4_num_winning = {} for each_draw in i4: num = each_draw[0] amount = prize_calc.i4_prize_calc(each_draw) if num in i4_num_winning: i4_num_winning[num] += amount else: i4_num_winning[num] = amount ## ========== CHECK NUM-WINNING DICT AGAINST GIVEN NUM LIST ========== ## num_hit = [] #list of num that hit total_winning = 0 # store total winning all_num_cat_winning = {24:i24_num_winning,12:i12_num_winning,6:i6_num_winning,4:i4_num_winning} #dict mapping each num_cat to its winning for each_num in num_bought: each_num_perm = gen_perm(each_num) # generate all possible permutations for num bought num_cat = check_num_cat(each_num) num_winning = all_num_cat_winning[num_cat] for each_perm in each_num_perm: str_each_num = str(each_perm) if str_each_num in num_winning: total_winning += num_winning[str_each_num] new = [str_each_num, num_winning[str_each_num]] num_hit.append(new) sorted_num_hit = sorted(num_hit, key=getKey, reverse=True) return_lst = [total_winning, draw_count, sorted_num_hit] return return_lst
## calculate prize money won by each number ## def getKey(item): # this is for sorting list return item[1] i24_monthly_num_winning = [] i24_combined_num_winning = [] i24_combined_winning = {} for each_month in i24: num_winning = {} lst_num_winning = [] for each_draw in each_month: num = each_draw[0] amount = prize_calc.i24_prize_calc(each_draw) if num in num_winning: num_winning[num] += amount else: num_winning[num] = amount # put num and winning into dict to count winning amount if num in i24_combined_winning: i24_combined_winning[num] += amount else: i24_combined_winning[num] = amount # this part is for all month combined list for num, win in num_winning.items(): new = [num, win] lst_num_winning.append(new) # convert dict back to list i24_monthly_num_winning.append(sorted(lst_num_winning, key=getKey, reverse=True))