def test_payoff_summary(dpp): debt_name = "payoff summary check" starting_balance = randint(1001, 10000000) number_of_payments = randint(2, 15) minimum_payment = math.ceil(starting_balance / number_of_payments) apr = randint(3, 15) payoff_progress = 0 base_page = page.BasePage(dpp) main_page = base_page.open_main_page_as_guest() main_page.add_debt_parametrized(debt_name, starting_balance, minimum_payment, apr) total_interest = common.get_total_interest(starting_balance, minimum_payment, number_of_payments, apr) current_balance = starting_balance - payoff_progress first_month_interest = round(current_balance * apr * 0.01 / 12, 2) date = common.get_datetime() debt_free_on = common.add_months(date, number_of_payments + 1).strftime("%b %Y") total_of_payments = starting_balance + total_interest total_interest_percent = round((total_interest / total_of_payments) * 100, 1) main_page.check_payoff_summary( current_balance, starting_balance, minimum_payment, first_month_interest, debt_free_on, number_of_payments + 1, total_of_payments, total_interest, total_interest_percent, ) # Add payment amount main_page.add_payment_ammount(minimum_payment) current_balance = starting_balance - minimum_payment first_month_interest = round(current_balance * apr * 0.01 / 12, 2) date = common.get_datetime() debt_free_on = common.add_months(date, number_of_payments).strftime("%b %Y") total_interest = common.get_total_interest(current_balance, minimum_payment, number_of_payments - 1, apr) total_of_payments = current_balance + total_interest total_interest_percent = round((total_interest / total_of_payments) * 100, 1) main_page.check_payoff_summary( current_balance, starting_balance, minimum_payment, first_month_interest, debt_free_on, number_of_payments, total_of_payments, total_interest, total_interest_percent, )
def check_payoff(self, debt_1, debt_2): # Check first step of payment debt_1_payment = debt_1.minimum_payment debt_2_payment = debt_2.minimum_payment step_number = 0 if debt_1.remainder: step_number = 1 self.check_step_details(0, debt_1.debt_name, debt_1.minimum_payment, (debt_1.number_of_payments - 1)) self.check_step_details(0, debt_2.debt_name, debt_2.minimum_payment, (debt_1.number_of_payments - 1)) # Check the last step of the first payment debt_1_payment = debt_1.starting_balance - debt_1.minimum_payment * (debt_1.number_of_payments - 1) debt_2_payment = debt_2.minimum_payment + debt_1.minimum_payment - debt_1_payment self.check_step_details(1, debt_1.debt_name, debt_1_payment, 1) if debt_2.remainder: self.check_step_details(1, debt_2.debt_name, debt_2_payment, 1) else: self.check_step_details(0, debt_1.debt_name, debt_1_payment, debt_1.number_of_payments) self.check_step_details(0, debt_2.debt_name, debt_2_payment, debt_1.number_of_payments) self.check_step_debt_paid(0, debt_1) if debt_1.number_of_payments != debt_2.number_of_payments: # Check first step of the second debt after payoff of the first debt minimum_payment = debt_2.minimum_payment + debt_1.minimum_payment left_to_pay = debt_2.starting_balance - ( debt_2.minimum_payment * debt_1.number_of_payments + debt_1.minimum_payment - debt_1_payment ) left_duration = int(left_to_pay / minimum_payment) if left_to_pay <= minimum_payment: self.check_step_details(step_number + 1, debt_2.debt_name, left_to_pay, 1) if left_duration > 1: self.check_step_details(step_number + 1, debt_2.debt_name, minimum_payment, left_duration) last_payment = left_to_pay - minimum_payment * left_duration self.check_step_details(step_number + 2, debt_2.debt_name, last_payment, 1) debt_2.debt_free_on = common.add_months( common.get_datetime(), debt_1.number_of_payments + left_duration + 1 ).strftime("%b %Y") debt_2.debt_free_years_month = common.get_years_month_debt_free( debt_1.number_of_payments + left_duration + 1 ) self.check_step_debt_paid(1, debt_2)
def __init__(self, debt_name, starting_balance, minimum_payment = None, apr = None, number_of_payments = None, category = None, payment_due_date = None, payoff_progress = None): self.debt_name = debt_name self.starting_balance = starting_balance self.minimum_payment = minimum_payment self.number_of_payments = number_of_payments self.apr = apr self.category = category self.payment_due_date = payment_due_date self.payoff_progress = apr self.remainder = False if minimum_payment == None and number_of_payments != None: self.minimum_payment = math.ceil(starting_balance / number_of_payments) if starting_balance % number_of_payments != 0: self.number_of_payments = int(number_of_payments + 1) self.remainder = True if number_of_payments == None and minimum_payment != None: self.number_of_payments = math.ceil(starting_balance / minimum_payment) if starting_balance % minimum_payment != 0: self.number_of_payments = int(self.number_of_payments + 1) self.remainder = True if apr == None: self.apr = 0 self.total_interest = 0 else: self.total_interest = common.get_total_interest(self.starting_balance, self.minimum_payment, self.number_of_payments, self.apr) self.number_of_payments = math.floor((self.starting_balance + self.total_interest) / self.minimum_payment) if (self.starting_balance + self.total_interest) % self.minimum_payment != 0: self.number_of_payments = int(self.number_of_payments + 1) self.remainder = True if payoff_progress == None: self.payoff_progress = 0 date = common.get_datetime() self.debt_free_on = common.add_months(date, self.number_of_payments).strftime('%b %Y') self.debt_free_years_month = common.get_years_month_debt_free(self.number_of_payments)
def preprocess_out_files(): """ Extracts some general information about the averaging files to generate. Mainly, determines which files to read and weights for each averaging file. Also returns avg_intervals """ if args.v and comm.Get_rank() == 0: print("pre-processing files") # beginning and ending dates for this proc date0_proc = add_months( glob.date0_out, min(glob.m_per_proc * (comm.Get_rank()), glob.nmonths)) date1_proc = add_months( glob.date0_out, min(glob.m_per_proc * (comm.Get_rank() + 1), glob.nmonths)) # determine the averaging intervals (months) to process for this proc: avg_intervals = [] interval_date0 = date0_proc # first intervals's date0 while True: interval_date1 = next_month_1st( interval_date0) # date1 of current interval if interval_date1 <= date1_proc: avg_intervals.append( AvgInterval(interval_date0, "month", glob.fprefix, glob.fsuffix)) interval_date0 = interval_date1 # move to next potential interval else: # the end of this interval is beyond the extent of input files. # do not add this interval and break here. break fi = 0 # file index for interval in avg_intervals: interval_preprocessed = False while not interval_preprocessed: # Read the input file with xr.open_dataset(glob.filePaths[fi](), decode_times=False, cache=False, decode_cf=False) as ncfile_in: day0_in = ncfile_in[glob.time_bound_str].data[0][ 0] # beginning day of this input file day1_in = ncfile_in[glob.time_bound_str].data[-1][ 1] # ending day of this input file date0_in = nc4.num2date( day0_in, glob.nc_dtime_unit, glob.nc_calendar) # beginning date of this file date1_in = nc4.num2date( day1_in, glob.nc_dtime_unit, glob.nc_calendar) # ending date of this file if ( date1_in <= interval.date0 ): # The dates of this file (fi) precede the time interval that # this proc is responsible for. So, move on to next file. (fi++) pass elif ( date0_in >= interval.date1 ): # The dates of this file (fi) are later than the time interval that # this file (fi) covers. so, stop reading files. interval_preprocessed = True elif (date0_in <= interval.date0 and date1_in > interval.date0) or \ (date0_in >= interval.date0 and date1_in <= interval.date1) or \ (date0_in < interval.date1 and date1_in >= interval.date1): # The dates of this file (fi) falls within the time interval that this proc is responsible for. # so, read in this file. # Determine the weight of this file (fi): ndays_within_interval = ( min(interval.date1, date1_in) - max(interval.date0, date0_in)).days weight = float(ndays_within_interval) / interval.ndays interval.in_files.append([glob.filePaths[fi], weight]) else: print(date0_in, date1_in, interval.date0, interval.date1) raise RuntimeError( "Error detected in the file read/write logic", comm.Get_rank()) # check if this was the final file to read for this interval if date1_in >= interval.date1: interval_preprocessed = True fi = fi + 1 # skip to next file to read, which may have information for this interval (month) # Done preprocessing this interval (month). Move to the next interval fi = fi - 1 # (and move to previous file in case it had information for the next interval) return avg_intervals