def test_ensure_threshold_consistency(): #Test for consistency among all threshold #finding functions. data = setUp() capacities = range(-50, 10**3, 50) precision = .001 hex0_0006 = 0.000091552734375 #binary close to .0001 #They are all very similar results however #find_threshold_bin() yeilds a slightly different #result given the same parameters. for capacity in capacities: threshold1 = find_threshold_iterative(data, capacity, precision) threshold1 = round_decimals_up(threshold1, 1) threshold2 = find_threshold_recursive(data, capacity, precision) threshold2 = round_decimals_up(threshold2, 1) threshold3 = find_threshold_bin(data, capacity, hex0_0006) threshold3 = round_decimals_up(threshold3, 1) print(capacity, threshold1, threshold2, threshold3) assert threshold1 == threshold2 assert threshold2 == threshold3
def test_find_minimum_capacity_recursive(): #Test find_minimum_capacity_recursive() with a #variety of thresholds. data = setUp() max_usage = max(data) min_usage = min(data) step = int(math.log10(max_usage)) thresholds = numpy.arange(max_usage, min_usage, step) for threshold in thresholds: capacity = find_minimum_capacity_recursive(data, threshold, .001, 1) capacity = round_decimals_up(capacity, 3) assert run_sim(data, threshold, capacity)
def test_find_threshold_recursive(): #Test the find_threshold_recursive() with #multiple capacities. data = setUp() capacities = range(-50, 10**3, 50) precision = .001 for capacity in capacities: threshold = find_threshold_recursive(data, capacity, precision) threshold = round_decimals_up(threshold, 3) if capacity < 0: assert threshold == -1 continue assert run_sim(data, threshold, capacity)
#Monthly Operations. if args.objective1 or args.objective2: print('Beginning Monthly Operations...\n') starttime = time.time() currentDate = startDate while currentDate.strftime('%Y-%m') != endDate.strftime('%Y-%m'): data = df.loc[(df.Date.dt.month == currentDate.month) & (df.Date.dt.year == currentDate.year)].Usage write_str = '{}-{}'.format(currentDate.year, currentDate.month) if args.objective1: threshold = find_threshold_recursive(data, 100, .001) threshold = round_decimals_up(threshold, 3) result = [write_str, threshold] threshold_by_month.append(result) if args.objective2: capacity_needed = find_minimum_capacity_iterative(data, 20, 1, 10) capacity_needed = round_decimals_up(capacity_needed, 0) result = [write_str, capacity_needed] capacity_by_month.append(result) Letter = currentDate.strftime("%B")[0]