def get_DH_T(): alpha = si.get_real_number("Enter link twist (alpha) in degrees. >>> ") a = si.get_real_number("Enter link length (a). >>> ") theta = si.get_real_number("Enter link rotation (theta) in degrees. >>> ") d = si.get_real_number("Enter link offset (d). >>> ") T = robotics.DH(alpha, a, theta, d) return (T)
def manual_entry(): print("Enter the coordinates of the obstacle.") o_pos = si.get_coords() o_r = si.get_real_number("Enter the radius of the obstacle >>> ", lower = 0) o_h = si.get_real_number("Enter the height of the obstacle. (leave blank for infinite height). >>> ", lower = 0) obst = A_star.obstacle(o_pos, o_r, o_h) print("Enter the starting position. >>> ") start = A_star.node(si.get_coords()) print("Enter the payload position. >>> ") end = A_star.node(si.get_coords()) n = si.get_integer("Enter the approximate number of nodes along the path. >>> ", lower = 0) return(obst, start, end, n)
def get_T(): '''This function generates a homogeneous transform matrix given a position vector and a rotation describing the location of frame B with respect to frame A.''' print("Enter the position of frame B with respect to frame A.") P_B_origin = si.get_coords() axis = si.get_letter("X, Y, or Z axis? >>> ", ['x', 'X', 'y', 'Y', 'z', 'Z']) theta = si.get_real_number("Enter the angle of rotation in degrees. >>> ") R = get_R(axis, theta) T = robotics.HT_from_R_and_Porg(R, P_B_origin.vec) return (T)
def order(watch_list): today = dt.date.today() orders = ['Buy', 'Sell', 'Back'] date_options = ['Today', 'Enter date', 'Back'] print("What kind of order?") order = orders[si.select(orders)] if order == 'Back': print("\n", end='') return () print("When was this order?") date_selection = date_options[si.select(date_options)] if date_selection == 'Today': date = today year = today.year month = today.month day = today.day elif date_selection == 'Enter date': year = si.get_integer("Enter year.\n>>>", upper=today.year + 1, lower=1970) month = si.get_integer("Enter month.\n>>>", upper=13, lower=0) day = si.get_integer("Enter day.\n>>>", upper=32, lower=0) elif date_selection == 'Back': print("\n", end='') return () date_str = str(year) + '-' + str(month) + '-' + str(day) tick = input("Enter stock ticker.\n>>>").upper() shares = si.get_integer("Enter number of shares.\n>>>", lower=0) price = si.get_real_number("Enter share price.\n>>>", lower=0) comm = si.get_real_number("Enter commission.\n>>>", lower=-0.0001) fee = si.get_real_number("Enter fees.\n>>>", lower=-0.0001) watch_list.enter_order(order[0].lower(), date_str, tick, shares, price, comm, fee) watch_list.calc_cost_basis()
cond_temp = CP.PropsSI('T', 'P', cond_pres * 1000000, 'Q', 1, fluid) - 273 boil_temp = CP.PropsSI('T', 'P', boil_pres * 1000000, 'Q', 1, fluid) - 273 return (W_m, efficiency, boil_temp, cond_temp, Qin_m, Qout_m) #------Main------# if __name__ == '__main__': R245fa_db = '\\R245fa Saturated properties temperature table.csv' os.chdir("..") # Navigate up a directory db_path = os.path.abspath( os.curdir) + r"\GHSP study\Additional references" + R245fa_db # Navigate to the directory containing the working fluid database. '''Manual entry begins here.''' condenser_pressure = si.get_real_number( "Enter condenser pressure (MPa).\n>>>", lower=0) boiler_pressure = si.get_real_number("Enter boiler pressure (MPa).\n>>>", lower=condenser_pressure) turbine_efficiency = si.get_real_number( "Enter the turbine efficiency (0-1).\n>>>", upper=1.0, lower=0) pump_efficiency = si.get_real_number( "Enter the pump efficiency (0-1).\n>>>", upper=1.0, lower=0) max_heat = si.get_real_number( "Enter maximum heat source temperature (C).\n>>>", lower=-273) m = si.get_real_number("Enter the mass flow rate (kg/s).\n>>>", lower=0) (Wm, efficiency, boil_temp, cond_temp, Qin_m, Qout_m) = ORC_model(condenser_pressure, boiler_pressure, turbine_efficiency, pump_efficiency, db_path) print("Power: {:4.2f} kW\nEfficiency: {:4.2f}\nCondenser temperature: {:4.2f} C\nBoiler temperature: {:4.2f} C"\ .format(Wm*m,efficiency,cond_temp,boil_temp))
.format(c_temp, b_temp)) print("Boiler pressure: {:4.2f} MPa".format(boiler_pressure)) R245fa_db = '\\R245fa Saturated properties temperature table.csv' db_upper_pressure_limit = 3.651 db_lower_pressure_limit = 0.00127 os.chdir("..") # Navigate up a directory db_path = os.path.abspath( os.curdir) + r"\GHSP study\Additional references" + R245fa_db # Navigate to the directory containing the working fluid database. p_boiler_max = si.get_real_number( "Enter the boiler working pressure upper limit (MPa):\n", upper=db_upper_pressure_limit, lower=db_lower_pressure_limit) p_boiler_min = si.get_real_number( "Enter the boiler working pressure lower limit (MPa):\n", upper=p_boiler_max, lower=db_lower_pressure_limit) p_condenser_max = si.get_real_number( "Enter the condenser working pressure upper limit (MPa):\n", upper=p_boiler_min, lower=db_lower_pressure_limit) p_condenser_min = si.get_real_number( "Enter the condenser working pressure lower limit (MPa)(0.123 corresponds to a 20C working temp):\n", upper=p_condenser_max, lower=db_lower_pressure_limit) turbine_efficiency = si.get_real_number(
def V1(r, h): V = (4 / 3 * math.pi * r**3) + (math.pi * h * r**2) return (V) def V2(P1, P2, r, h): V = P1 * math.pi * r**2 * (4 / 3 * r + h) / P2 return (V) import math import sanitize_inputs as si print(V1(6, 32)) P1 = 14.7 P2 = si.get_real_number( "Enter absolute working pressure of expansion tank (psi)\n>>> ", lower=0) print(V2(P1, P2, 6, 32))
def stock_watcher(): watch_list = positions() print('\033[2J') # Clear the terminal watch_list.load_positions() watch_list.calc_cost_basis() watch_list.sort_open_positions() watch_list.calc_portfolio_value() watch_list.calc_average_yield() today = dt.date.today() while (True): selections = [ 'Order', 'View', 'Indicators', 'Edit', 'Other', 'Save', 'Quit' ] selection = selections[si.select(selections)] if selection == 'Order': order(watch_list) elif selection == 'View': print("\n", end='') # Add whitespace between this and previous menu. viewlist = ["Portfolio"] + watch_list.list_positions() viewlist.append('Back') view_pos = viewlist[si.select(viewlist)] if view_pos == "Portfolio": for pos in watch_list.position_list: if pos["current shares"] != 0: pos_value = pos["last price"] * pos["current shares"] print("{:<6} Shares: {:<5} @ ${:<7.2f} = Value: ${:<7.2f}"\ .format(pos["ticker"], pos["current shares"], pos["last price"], pos_value)) watch_list.calc_portfolio_value() print("Total value: ${:<7.2f}".format\ (watch_list.meta_data["portfolio value"])) print("Average dividend yield: {:<7.2f}%\n".format\ (watch_list.meta_data["average yield"]*100)) elif view_pos == 'Back': print("\n", end='') pass else: for pos in watch_list.position_list: if pos["ticker"] == view_pos: view(watch_list, pos) else: pass elif selection == 'Indicators': print("Force?") force_sel = ['Yes', 'No'] force_sel = force_sel[si.select(force_sel)] if force_sel == 'Yes': force = True else: force = False ind_dict = { "Last Transaction": [], # Looks for opportunities to reverse the last transaction recorded "Matched Transactions": [], # Looks for opportunities to improve cost-basis "High Dividend Yield": [], # Looks for high dividend yields with respect to a specified target "Recent Passed Dividend": [], # Looks for opportunities in response to recent or upcoming ex-dates "Over-exposure": [], # Looks for opportunities to improve exposure with respect to a specified target "Dividend Yield and Exposure composite": [], # Weighs dividend target against exposure target and makes a recommendation "Cost Basis": [] } # Looks at the last price compared to the cost basis of a position print("\nWorking on \"Last Transaction\" indicator.\n") watch_list, ind_dict = last_transaction_indicator( watch_list, ind_dict, force) print("\033[1A\033[K", end='') print("Done checking.\n") ind_dict["Last Transaction"].sort(key=lambda x: x["Score"], reverse=True) print_indicator(ind_dict, "Last Transaction", ind_format="${:<7.2f}", score_scale=1) print("\nWorking on \"Over-exposure\" indicator.\n") watch_list, ind_dict = over_exposure_indicator( watch_list, ind_dict) ind_dict["Over-exposure"].sort(key=lambda x: abs(x["Score"]), reverse=True) print("Exposure target: {:<7.2f}% (Position value: ${:<7.2f})".format\ (watch_list.meta_data["exposure target"]*100, watch_list.meta_data["portfolio value"]*watch_list.meta_data["exposure target"])) print_indicator(ind_dict, "Over-exposure", ind_format="{:<7.2f}%", score_scale=100) print("\nWorking on \"Dividend Yield\" indicator.\n") watch_list, ind_dict = div_yield_indicator(watch_list, ind_dict) ind_dict["High Dividend Yield"].sort(key=lambda x: abs(x["Score"]), reverse=True) print("Dividend target: {:<7.2f}%".format( watch_list.meta_data["dividend target"] * 100)) print_indicator(ind_dict, "High Dividend Yield", ind_format="{:<7.2f}%", score_scale=100) print("\n", end='') print("Working on \"Exposure-dividend composite\" indicator.\n") watch_list, ind_dict = div_exp_composite_indicator( watch_list, ind_dict) ind_dict["Dividend Yield and Exposure composite"].sort( key=lambda x: abs(x["Score"]), reverse=True) print_indicator(ind_dict, "Dividend Yield and Exposure composite", ind_format="{:<7.2f}", score_scale=100) print("\n", end='') print("Working on \"Cost Basis\" indicator.\n") watch_list, ind_dict = cost_basis_indicator(watch_list, ind_dict) ind_dict["Cost Basis"].sort(key=lambda x: abs(x["Score"]), reverse=True) print_indicator(ind_dict, "Cost Basis", ind_format="{:<7.2f}", score_scale=1) print("\n", end='') for indicator in ind_dict["Recent Passed Dividend"]: pass elif selection == 'Edit': edit(watch_list) elif selection == 'Other': print('\n', end='') selections = [ 'Get all dividends', 'Get dividends for current positions', 'Edit target exposure', 'Edit dividend target', 'Clear console', 'About', 'Back' ] selection = selections[si.select(selections)] if selection == 'Get all dividends': get_dividends(watch_list, force_all=True) elif selection == 'Get dividends for current positions': get_dividends(watch_list) elif selection == 'Edit target exposure': print("Current target: {:<7.2f}%".format\ (watch_list.meta_data["exposure target"]*100)) new_target = si.get_real_number( "Enter new target (0-100).\n>>>", lower=0, upper=100) watch_list.meta_data["exposure target"] = new_target / 100 print("New target: {:<7.2f}%".format\ (watch_list.meta_data["exposure target"]*100)) elif selection == 'Edit dividend target': print("Current target: {:<7.2f}%".format\ (watch_list.meta_data["dividend target"]*100)) new_target = si.get_real_number( "Enter new target (0-100).\n>>>", lower=0, upper=100) watch_list.meta_data["dividend target"] = new_target / 100 print("New target: {:<7.2f}%".format\ (watch_list.meta_data["dividend target"]*100)) elif selection == 'Clear console': print('\033[2J') # console command to clear console and return to (0,0) elif selection == 'About': print("\nVersion: {}\nSanitize inputs version: {}\nMisc_functions version: {}\n" \ .format(__version__,si.__version__,mf.__version__)) elif selection == 'Back': pass elif selection == 'Save': watch_list.save_positions() print("Saving...\n") elif selection == 'Quit': print("Save changes?") yn = ['Yes', 'No'] sav = yn[si.select(yn)] if sav == 'Yes': watch_list.save_positions() else: pass break
def edit(watch_list): print("\n", end='') edit_list = ['Transactions', 'Dividends', 'Tickers', 'Back'] viewlist = watch_list.list_positions() # used in several options viewlist.append('Back') edit_sel = edit_list[si.select(edit_list)] if edit_sel == 'Transactions': print("\n", end='') print("For which position would you like to edit a transaction?") edit_pos = viewlist[si.select(viewlist)] print("\nEditing", edit_pos, "\n") for pos in watch_list.position_list: if pos["ticker"] == edit_pos: print("Which transaction would you like to edit?") tran_list = [] for t in pos["transactions"]: trans_str = "{}: {} {} @ ${:<7.4f}"\ .format(t['date'], t['b/s'].upper(), t['shares'], t['price']) tran_list.append(trans_str) t_sel = tran_list[si.select(tran_list)] for i, t in enumerate(tran_list): # get index of transaction if t_sel == t: break print("What would you like to edit?") edit_choices = [ 'Date', 'Buy/Sell', 'Shares', 'Price', 'Commission', 'Fees', 'Delete transaction', 'Back' ] e_choice = edit_choices[si.select(edit_choices)] if e_choice == 'Date': today = dt.date.today() year = si.get_integer("Enter year.\n>>>", upper=today.year + 1, lower=1970) month = si.get_integer("Enter month.\n>>>", upper=13, lower=0) day = si.get_integer("Enter day.\n>>>", upper=32, lower=0) date_str = str(year) + '-' + str(month) + '-' + str(day) pos["transactions"][i]['date'] = date_str elif e_choice == 'Buy/Sell': orders = ['Buy', 'Sell'] print("What kind of order?") order = orders[si.select(orders)] pos["transactions"][i]['b/s'] = order[0].lower() elif e_choice == 'Shares': shares = si.get_integer("Enter number of shares.\n>>>", lower=0) pos["transactions"][i]['shares'] = shares elif e_choice == 'Price': price = si.get_real_number("Enter share price.\n>>>", lower=0) pos["transactions"][i]['price'] = price elif e_choice == 'Commission': commission = si.get_real_number("Enter commission.\n>>>", lower=-0.01) pos["transactions"][i]['commission'] = commission elif e_choice == 'Fees': fees = si.get_real_number("Enter fees.\n>>>", lower=-0.01) pos["transactions"][i]['fees'] = fees elif e_choice == 'Delete transaction': pos["transactions"].pop(i) elif e_choice == 'Back': pass elif edit_sel == 'Dividends': print("For which position would you like to edit a dividend?") edit_pos = viewlist[si.select(viewlist)] for pos in watch_list.position_list: if pos["ticker"] == edit_pos: print("Which dividend would you like to edit?") div_list = [] for d in pos["dividends"]: div_str = "{}: {} x ${:<7.2f} = ${:<7.2f}"\ .format(d['date'], d['shares'], d['amount'], d['total']) div_list.append(div_str) div_list.append('Back') d_sel = div_list[si.select(div_list)] if d_sel == 'Back': print("\n", end='') return () for i, d in enumerate(div_list): # get index of transaction if d_sel == d: break print("What would you like to edit?") edit_choices = [ 'Date', 'Amount', 'Shares', 'Total', 'Delete dividend', 'Back' ] e_choice = edit_choices[si.select(edit_choices)] if e_choice == 'Date': today = dt.date.today() year = si.get_integer("Enter year.\n>>>", upper=today.year + 1, lower=1970) month = si.get_integer("Enter month.\n>>>", upper=13, lower=0) day = si.get_integer("Enter day.\n>>>", upper=32, lower=0) date_str = str(year) + '-' + str(month) + '-' + str(day) pos["dividends"][i]['date'] = date_str elif e_choice == 'Amount': amount = si.get_real_number("Enter dividend amount.\n>>>", lower=0) pos["dividends"][i]['amount'] = amount elif e_choice == 'Shares': shares = si.get_integer("Enter number of shares.\n>>>", lower=0) pos["dividends"][i]['shares'] = shares elif e_choice == 'Total': price = si.get_real_number("Enter total dividend.\n>>>", lower=0) pos["dividends"][i]['total'] = price elif e_choice == 'Delete dividend': pos["dividends"].pop(i) elif e_choice == 'Back': pass elif edit_sel == 'Tickers': tick_options = [ 'Edit symbol', 'Delete symbol', 'Track/Untrack symbol', 'Back' ] print("Which ticker would you like to edit?") edit_pos = viewlist[si.select(viewlist)] if edit_pos != 'Back': print("What would you like to do with this position?") edit_sel = tick_options[si.select(tick_options)] for i, pos in enumerate(watch_list.position_list): if pos["ticker"] == edit_pos: if edit_sel == 'Edit symbol': tick = input("Enter stock ticker.\n>>>").upper() pos["ticker"] = tick # There will need to be logic here to merge two identical # symbols. elif edit_sel == 'Delete symbol': watch_list.position_list.pop(i) elif edit_sel == 'Back': pass elif edit_sel == 'Track/Untrack symbol': tick_edit_options = ['Track', 'Untrack'] tick_edit_sel = tick_edit_options[si.select( tick_edit_options)] if tick_edit_sel == 'Track': pos["track"] = True elif tick_edit_sel == 'Untrack': pos["track"] = False elif edit_sel == 'Back': return () watch_list.calc_cost_basis()
elif units.lower() == 'm': length_units = "mm" force_units = "N" mass_units = "kg" else: print("Units error.") acceptable_shapes = ['c','r','C','R'] shape = si.get_letter("(R)ectangular or (C)ylindrical cross-section") tube = si.get_letter("Hollow tube? (y/n)") if shape.lower() == 'r': hgt_prompt = "Enter the height of the cross-section (" + length_units + ")" height = si.get_real_number(hgt_prompt, positive = True, negative = False) wid_prompt = "Enter the width of the cross-section (" + length_units + ")" height = si.get_real_number(wid_prompt, positive = True, negative = False) elif shape.lower() == 'c': OD_prompt = "Enter the outer diameter of the cross-section (" + length_units + ")" OD = si.get_real_number(OD_prompt, positive = True, negative = False) if tube == 'y': wall_prompt = "Enter the wall thickness of the cross-section (" + length_units + ")" wall = si.get_real_number(wall_prompt, positive = True, negative = False) area = calc_cross_area(shape, height, width, OD, wall) acceptable_loading = ['c','o','t','s','C','O','T','S']