def UserInput(self): adminview = Welcomeview() while True: option = input("等待用户输入:") if option == "1": atm_create = ATM() atm_create.createUser() break elif option == "2": atm_search = ATM() atm_search.searchUser() return -1 elif option == "3": print("取款") elif option == "4": print("存款") elif option == "5": print("转账") elif option == "6": print("改密") elif option == "7": print("锁定") elif option == "8": print("解锁") elif option == "9": print("补卡") elif option == "10": print("销户") elif option == "q": verifty_admin = VerifyAdmin() if verifty_admin.verify() == 1: break else: print("请输入正常的数字:") time.sleep(2)
def main(): #实例化Admin对象 admin=Admin() #管理员开机(显示系统欢迎界面) admin.printaDMINvIEW() #验证管理员身份 if admin.adminOption(): return ''' 序列化allUsers散装数据到程序中还原成为allUsers对象 ''' try: with open('allUsers.txt','rb') as fr: allUsers=pickle.load(fr) print(allUsers) #实例化ATM对象 atm=ATM(allUsers) except: print('except...') #实例化ATM对象 allUsers={} atm=ATM(allUsers) while 1: #如果程序能够执行到此处说明身份信息没问题 admin.printSysFuncView() num=input('请选择您需要执行的操作...') if num=='1': atm.createUser() elif num=='2': atm.searchUserInfo() elif num=='3': atm.getMoney() elif num == '4': atm.saveMoney() elif num == '5': atm.transferMoney() elif num == '6': atm.updatePWD() elif num == '7': atm.unlockCard() elif num == '8': atm.lockCard() elif num=='t': ''' 对象序列化操作:将allUsers对象数据存储到allUser.txt文件中 ''' with open('allUser.txt','wb') as fw: pickle.dump(atm.allUsers,fw) return time.sleep(2)
def main(): #银行对象 #界面对象 admin = Admin() #管理员开机 admin.printAdminView() if admin.adminOption(): return -1 #提款机对象 absPath = os.getcwd() filepath = os.path.join(absPath, 'allUsers.txt') if os.path.exists(filepath): #判断是否已经有账户号 f = open(filepath, 'rb') allUsers = pickle.load(f) atm = ATM(allUsers) #读取对象 else: allUsers = {} atm = ATM(allUsers) #首次开户 while True: admin.symsFunctionView() #等待用户的操作 option = input('请输入您的操作:') if option == '1': atm.OpenAccount() elif option == '2': atm.searchUserInfo() elif option == '3': atm.Withdraw() elif option == '4': atm.Deposit() elif option == '5': atm.Transfer() elif option == '6': atm.PasswordChange() elif option == '7': atm.lockUser() elif option == '8': atm.unlockUser() elif option == '9': atm.Replacement() elif option == 'a': atm.Cancellation() elif option == 'e': if not admin.adminOption( ): #admin.adminOption()正常执行时返回0,因此要执行return -1,需要加not return -1 time.sleep(2)
def main(): #存储用户信息 #allUsers = {} #管理员对象 view = Admin() view.printAdminView() if view.adminOption() == -1: return -1 filepath = os.path.join(os.getcwd(), 'allusers.txt') f = open(filepath, 'rb') allUsers = pickle.load(f) print(allUsers) atm = ATM(allUsers) while True: view.sysFunctionView() option = input('请输入操作:') if option == '1': print('开户') atm.createUser() elif option == '2': print('查询') atm.searchUserInfo() elif option == '3': print('取款') atm.getMoney() elif option == '4': print('存款') atm.saveMoney() elif option == '5': print('转账') atm.transferMoney() elif option == '6': print('改密') atm.changePasswd() elif option == '7': print('锁定') atm.lockUser() elif option == '8': print('解锁') atm.unlockUser() elif option == '9': print('补卡') atm.newCard() elif option == '0': print('销户') atm.killUser() elif option == 'a': print('退出') if not view.adminOption() == -1: #将用户保存到文件中 #filepath = os.path.join(os.getcwd(), '账户信息.txt') f = open(filepath, 'wb') pickle.dump(atm.allUsers, f) f.close() #print(filepath) return -1 time.sleep(2)
def main(): admin = Admin() #管理员对象 admin.printAdminView() #管理员开机 if admin.adminOperation(): return -1 atm = ATM() while True: #等待用户操作 admin.sysFunctionView() option = input("请输入你的操作:") if option == '0': atm.createUser() if option == '1': pass elif option == '2': pass elif option == '3': pass elif option == '4': pass elif option == '5': pass elif option == '6': pass elif option == '7': pass elif option == '8': pass elif option == '9': if admin.adminOperation(): return -1
def train_atm_model(cross_validation): current_dir = path.abspath('.') cross_validation_data_dir = '{}/dataset/{}'.format(current_dir, cross_validation) train_file = path.join(cross_validation_data_dir, 'atm_train.csv') np.random.seed(0) # for replication purposes random.seed(0) atm_models_dir = '{}/atm-models'.format(current_dir) cross_validation_atm_model_dir = '{}/{}'.format(atm_models_dir, cross_validation) if not path.exists(cross_validation_atm_model_dir): makedirs(cross_validation_atm_model_dir) chdir(cross_validation_atm_model_dir) clf = ATM() results = clf.run(train_path=train_file, name=cross_validation, budget=200, budget_type='classifier', metric='accuracy', methods=['svm']) best_classifier_pkl_file = '{}/model_{}.pkl'.format( cross_validation_atm_model_dir, cross_validation) results.export_best_classifier(best_classifier_pkl_file) chdir(current_dir) return cross_validation
def main(): try: f = open(filePath, "rb") allUsers = pickle.load(f) except EOFError: allUsers = {} # 初始化实例 admin = Admin() atm = ATM(allUsers) # 登录界面 admin.printLoginView() # 验证信息 if admin.logCheck(): return -1 # 进入操作界面 else: admin.printFuncView() while 1: option = input("$ Please input your choice: ") if option == 'q': print("Thanks for support! Bye~") # 将用户信息保存在本地 f = open(filePath, "wb") pickle.dump(atm.allUsers, f) f.close() return 0 # 验证身份 # 进行操作 optionSel(atm, option)
def main(): # 管理员登录为'admin',密码为'123' view = View("admin", "123") view.initface() atm = ATM() view.login() user = Users() while True: view.sysInit() c = input("Please input business: ") if c == "1": user.createAccount(atm) elif c == "2": if user.log(atm): while True: if func(view, atm, user) == None: continue else: break elif c == "3": user.findBackPwd(atm) elif c == "4": user.lockAccount(atm) elif c == "T": if user.exitSys(atm): # 管理员注销系统 if view.logout(): return True else: print("The input have something wrong")
def test_choice(sb_mock): atm = ATM() atm.choice(1) sb_mock.assert_called_once() with pytest.raises(InvalidChoice): assert atm.choice(99)
def test_get_currency_amount(print_mock, input_mock): input_mock.side_effect = ['A', '1000'] atm = ATM() result = atm._get_currency_amount() assert result == '1000' print_mock.assert_called_once()
def test_get_account(print_mock, input_mock, build_account): input_mock.sid_effect = ['5', '1'] atm = ATM() account = build_account() atm.accounts.append(account) assert atm._get_account() == account
def test_s3_get(self): teller = ATM(s3_cache_dir) s3_content = teller.get_cache(s3_file).content requests_content = requests.get(s3_file).content assert s3_content == requests_content
def login(accountListFile, transactionSummary): try: choice = input("Welcome to the front end: \n") if choice == 'login': # use correctly input login print("Successfully login.") status = False # check the validation of input while status == False: # loop if user input invalid command mode = input("Select mode to enter: \n") # select mode if mode == "atm": # user correctly input atm print("Successfully entered ATM mode.") newAtm = ATM(accountListFile, transactionSummary) # create new atm object status = True elif mode == "agent": # user correctly input agent print("Successfully entered agent mode.") newAgent = AGENT(accountListFile, transactionSummary) # create new agent object status = True elif mode == "logout": status = True f = open(transactionSummary, "w") f.writelines("EOS") f.close() else: # error for anything else print("Error:Invalid mode choice, please input a valid mode choice!") print("Successfully logout.") login(accountListFile, transactionSummary) else: # invalid input print("Error:Please login first!") login(accountListFile, transactionSummary) except: quit # exit program
def test_add_account(input_mock, print_mock): input_mock.side_effect = ['3', '1', '1000.00'] atm = ATM() account = atm.add_account() assert print_mock.call_count > 2 assert account.amount == Decimal('1000.00')
def main(): #存储所有用户的信息 allUsers = {} #管理员对象 admin = Admin() #管理员开机 admin.printAdminView() if admin.adminOption(): return -1 #提款机对象 filePath = os.path.join(os.getcwd(), 'allusers.txt') f = open(filePath, 'rb') allUsers = pickle.load(f) atm = ATM(allUsers) while True: admin.printSysFunctionView() #等待用户的操作 option = raw_input('请输入您的操作:') if option == '1': #print '开户' atm.createUser() elif option == '2': #print '查询' atm.searchUserInfo() elif option == '3': #print '取款' atm.getMoney() elif option == '4': print '存款' elif option == '5': print '转账' elif option == '6': print '改密' elif option == '7': #print '锁定' atm.lockUser() elif option == '8': #print '解锁' atm.unlockUser() elif option == '9': print '补卡' elif option == '0': print '销户' elif option == 't': if not admin.adminOption(): #将当前系统中的用户信息保存到文件中 #path = r'D:\test\bank.txt' #filePath = os.path.join(os.getcwd(), 'allusers.txt') f = open(filePath, 'wb') pickle.dump(atm.allUsers, f) f.close() return -1 time.sleep(2)
def __init__(self, win,passwd): self.passwd = passwd self.win = win self.atm = ATM() # self.header = Label(self.win, text="TAN BANK", bg="#50A8B0", fg="white", font=("arial", 20, "bold")) # self.header.grid(row = 0, column = 0) self.uentry = Entry(win, bg="honeydew", highlightcolor="#50A8B0", highlightthickness=2, highlightbackground="white", width=40) self.pentry = Entry(win, bg="honeydew", show="*", highlightcolor="#50A8B0", highlightthickness=2, highlightbackground="white", width=40) self.top_frame = Frame(self.win, bg="#50A8B0") self.frame = Frame(self.win, bg="#728B8E", width=40, height=12) self.left_frame = Frame(self.win) self.right_frame = Frame(self.win) self.top_frame.grid(row=0, columnspan=3) self.frame.grid(row=1, column=1) self.left_frame.grid(row=1, column=0) self.right_frame.grid(row=1, column=2) self.header = Label(self.top_frame, text="TAN BANK", bg="#50A8B0", fg="white", font=("arial", 20, "bold"), width=40) self.header.grid() self.content = tkinter.Text(self.frame, width=40, height=12, font=("arial", 15, "bold"), bg="#728B8E", fg="white") self.content.grid(row=0) info = self.inputPasswd() self.content.insert(tkinter.INSERT, info) self.content.config(stat=DISABLED) self.lb1 = Button(self.left_frame, text="LB1", width=10, height=3) self.lb2 = Button(self.left_frame, text="LB2", width=10, height=3) self.lb3 = Button(self.left_frame, text="LB3", width=10, height=3) self.lb4 = Button(self.left_frame, text="LB4", width=10, height=3) # self.lb1.pack(side=tkinter.LEFT, fill=tkinter.Y) # self.lb2.pack(side=tkinter.LEFT, fill=tkinter.Y) # self.lb3.pack(side=tkinter.LEFT, fill=tkinter.Y) self.lb1.grid(row=0, column=0, sticky=E, padx=5, pady=5) self.lb2.grid(row=1, column=0, sticky=E, padx=5, pady=5) self.lb3.grid(row=2, column=0, sticky=E, padx=5, pady=5) self.lb4.grid(row=3, column=0, sticky=E, padx=5, pady=5) self.rb1 = Button(self.right_frame, text="RB1", width=10, height=3) self.rb2 = Button(self.right_frame, text="RB2", width=10, height=3) self.rb3 = Button(self.right_frame, text="RB3", width=10, height=3) self.rb4 = Button(self.right_frame, text="RB4", width=10, height=3) # self.rb1.pack(side=tkinter.RIGHT ,fill=tkinter.Y) # self.rb2.pack(side=tkinter.RIGHT, fill=tkinter.Y) # self.rb3.pack(side=tkinter.RIGHT, fill=tkinter.Y) self.rb1.grid(row=0, column=0, sticky=W, padx=5, pady=5) self.rb2.grid(row=1, column=0, sticky=W, padx=5, pady=5) self.rb3.grid(row=2, column=0, sticky=W, padx=5, pady=5) self.rb4.grid(row=3, column=0, sticky=W, padx=5, pady=5)
def test_withdraw(print_mock, input_mock, build_account): input_mock.side_effect = ['1', '500.00'] atm = ATM() assert atm.withdraw() is None atm.accounts.append(build_account()) atm.withdraw() assert atm.accounts[0].amount == Decimal('700.00')
def main(): # 管理员对象 view = Admin() # 管理员开机 view.printAdminView() if view.adminOption(): return -1 print("登陆成功!") time.sleep(1) #提款机对象 filePath = os.path.join(os.getcwd(), "alluser.txt") f= open(filePath,"rb") allUser = pickle.load(f) atm=ATM(allUser) while True: view.printsysFunctionView() #等待用户操作 option =input("请输入您的选择:") if option =="1": atm.createUser() time.sleep(1) elif option=="2": atm.searchUserInfo() time.sleep(1) elif option == "3": atm.getMoney() elif option == "4": atm.saveMoney() elif option == "5": atm.transferMoney() elif option == "6": print('改密') elif option == "7": atm.lockUser() elif option == "8": atm.unlockUser() elif option == "9": print('补卡') elif option == "0": print('销户') elif option == 'Q': if not view.adminOption(): #将当前的用户信息保存到文件中 f= open(filePath,"wb") pickle.dump(atm.allUser,f) f.close() print('退出成功!') return -1 time.sleep(2)
def ok(self): atm = ATM() # print(self.passwd,self.name,atm.passwd,atm.account) if self.passwd.get() != atm.passwd or self.name.get() != atm.account: self.tip.set("账号或密码错误!请重新输入") self.name.set("") self.passwd.set("") else: self.destroy() # 销毁窗口 self.isLogin = self.passwd.get()
def setUp(self): """ create initial instances on which all test will be performed :return: """ self.account_balance = 15000 self.person = Person(self.account_balance) ATM.currency_numbers = (THOUSANDS, FIVE_HUNDREDS, HUNDREDS) self.atm = ATM() self.atm_balance = self.atm.total_amount
def test_show_balance(print_mock, input_mock, build_account): input_mock.side_effect = ['1'] atm = ATM() assert atm.show_balance() is None atm.accounts.append(build_account()) atm.show_balance() assert print_mock.call_count > 1
def test_availability_of_notes(self): """ test if right combination of notes are present to serve the request :return: """ ATM.currency_numbers = (THOUSANDS, FIVE_HUNDREDS, 3) self.atm = ATM() withdraw_amount = 400 self.person.dispense(withdraw_amount, self.atm) self.assertAccountBalanceUnchanged()
def train_atm(X_train, X_test, y_train, y_test, mtype, common_name_model, problemtype, classes, default_featurenames, transform_model, settings, model_session): # create file names model_name = common_name_model + '.pickle' csvname = common_name_model.split('_')[0] files = list() # initialize and train classifier atm = ATM() # create a temporary directory for all models curdir = os.getcwd() try: os.mkdir('atm_temp') os.chdir('atm_temp') except: shutil.rmtree('atm_temp') os.mkdir('atm_temp') os.chdir('atm_temp') try: shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_train_transformed.csv', os.getcwd() + '/train.csv') shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_test_transformed.csv', os.getcwd() + '/test.csv') except: shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_train.csv', os.getcwd() + '/train.csv') shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_test.csv', os.getcwd() + '/test.csv') # train models results = atm.run(train_path='train.csv', class_column='class_') data_results_ = str(results.describe()) bestclassifier = str(results.get_best_classifier()) scores = str(results.get_scores()) # export classifier / transfer to model directory results.export_best_classifier(model_name, force=True) shutil.move(os.getcwd() + '/' + model_name, curdir + '/' + model_name) files.append('atm_temp') files.append(model_name) files.append('atm.db') os.chdir(curdir) model_dir = os.getcwd() return model_name, model_dir, files
def main(): # 字典写有问题,如果创建的文件中没有数据会报错 absPath = os.getcwd() # 获取当前程序文件所在路径 filepath = os.path.join(absPath, "allusers.txt") # 在当前路径下创建一个名为alluser.txt的文件 f = open(filepath, "rb") allUsers = pickle.load(f) # print(allUsers) admin = Admin() admin.printAdminView() if admin.adminLong(): return -1 atm = ATM(allUsers) while True: print(allUsers) admin.printsysFunctionView() option = input("请输入您的操作:") if option == "1": # 当用户选择选项后调用ATM类 # 开户 atm.createUser() elif option == "2": # 查询 atm.searchUserInfo() elif option == "3": # 取款 atm.getMoney() elif option == "4": # 存款 atm.saveMoney() elif option == "5": # 转账 atm.transferMoney() elif option == "6": # 改密码 atm.changePasswd() elif option == "7": # 锁定 atm.lockUser() elif option == "8": # 解锁 atm.unlokUser() elif option == "9": # 补卡 atm.newCard() elif option == "0": # 销户 atm.killUser() elif option == "q": # 如果输入的账号和密码正确判定为false就结束程序,如果账号密码是错误的就判断为正确的继续循环执行程序 if not admin.adminLong(): f = open(filepath, "wb") pickle.dump(atm.allUser, f) f.close() return -1
def main(): # 管理员对象 admin = Admin() # 管理员账号 # 管理员开机 admin.printAdminView() if admin.adminOption(): return -1 # # 存储所有用户的信息 # allUsers = {} filePath = os.path.join(os.getcwd(), "allUsers.txt") f = open(filePath, 'rb') allUsers = pickle.load(f) # 提款机对象 atm = ATM(allUsers) while True: admin.printSysFunctView() # 等待用户操作 option = input("Please input your option:") if option == "1": atm.createUsers() elif option == "2": atm.searchUserInfo() elif option == "3": atm.withdrawals() elif option == "4": atm.saveMoney() elif option == "5": print("转账") elif option == "6": print("改密") elif option == "7": atm.lockUser() elif option == "8": atm.unlockUser() elif option == "9": print("补卡") elif option == "0": print("销户") elif option == "q": if not admin.adminOption(): # 将当前系统账户信息,保存到文件中 f = open(filePath, "wb") pickle.dump(atm.allUsers, f) f.close() return -1 time.sleep(3)
def test_local_liquidate(self): teller = ATM(local_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) files = [f for f in teller.liquidate()] # remove cache directory shutil.rmtree(local_cache_dir) assert len(files) == 2
def test__url_to_filepath(self): filepath1 = local_cache_dir + '/' + sha1(url).hexdigest() + '.txt' teller = ATM(local_cache_dir) filepath2 = teller._url_to_filepath(url, interval_string=None) # remove cache directory shutil.rmtree(local_cache_dir) # test assert filepath1 == filepath2
def test_s3_liquidate(self): teller = ATM(s3_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) assets = [f for f in teller.liquidate()] # remove files teller.default() assert len(assets) == 2
def test_source(self): teller = ATM(s3_cache_dir, interval=10) r = teller.get_cache(url) source1 = r.source r = teller.get_cache(url) source2 = r.source teller.default() assert source1=="url" and source2=="cache"
def main(): # 管理员对象 admin=Admin() admin.printAdminView() if admin.adminOption(): return -1 # allUsers={} # 存储所以用户信息 filepath = os.path.join(os.getcwd(), "allusers.txt") f = open(filepath, "rb") allUsers=pickle.load(f) atm = ATM(allUsers) time.sleep(1) while True: admin.printSysFunctionView() # 等待用户操作 option=input("请输入您的操作:") if option == "1": atm.creatUser() if option == "2": atm.searchUserInfo() if option == "3": atm.getMonsy() if option == "4": atm.saveMoney() if option == "5": atm.transferMoney() if option == "6": atm.changePasswd() if option == "7": atm.lockUser() if option == "8": atm.unlockUser() if option == "9": atm.newCard() if option == "10": atm.killUser() if option == "q": if not admin.adminOption(): filepath=os.path.join(os.getcwd(),"allusers.txt") f=open(filepath,"wb") pickle.dump(atm.allUsers,f) f.close() return -1