def get_week_range_history(start_week, end_week): cursor, conn = prepare_history_db(start_week, end_week) users_param = restore_from_db(cursor) History.total_user = len(users_param) users_with_index = list(enumerate(users_param, start=1)) gen = iter_pool_do(dispatch_one_user, users_with_index, cap=4) for g in gen: pass
def count_total_record(start_week, end_week): cursor, conn = prepare_history_db(start_week, end_week) users_param = restore_from_db(cursor) total_record_count = 0 user_count = len(users_param) user_index = 0 bobj = BatchRegulate(lambda param: History(*param).get_count(), users_param, 5) for user in users_param: user_index += 1 n = next(bobj) if n is None: n = 0 total_record_count += n print "count (%d/%d) users=%s listened=%d --- totals listened count = %d ---" % ( user_index, user_count, user[0], n, total_record_count) return total_record_count