def run_form(): # 初始化:读取文件,初始化第一条文本,初始化第一个词 function.read_file() function.init_text(0) function.init_word(0) # 显示主页面 app = QtGui.QApplication(sys.argv) win = form.Ui_Dialog() win.show() # 数据填充 function.fill(win) sys.exit(app.exec_())
def Encryption(): print('请输加密文件路径:', end='') file_path = input() print('请输入用户公钥文件路径:', end='') pubkey_path = input() pubkey = RSA.read_pubkey(pubkey_path) text = function.read_file(file_path) text = RSA.rsaEncrypt(text, pubkey) function.save_file(file_path, text) print('文件加密成功!')
def Decryption(): print('请输入姓名:', end='') name = input() print('请输解密文件路径:', end='') file_path = input() privkey_path = config.certificate + name + '.pem' privkey = RSA.read_privkey(privkey_path) text = function.read_file(file_path) text = RSA.rsaDecrypt(text, privkey) function.save_file(file_path, text) print('文件解密成功!')
def autograph(): print('请输入姓名:', end='') name = input() print('请输入用户私钥文件路径:', end='') privkey_path = input() CApubkey = RSA.creat_key(5120) text = function.read_file(privkey_path) text = RSA.rsaEncrypt(text, CApubkey) function.save_file(config.certificate + name + '.pem', text) print('CA私钥文件路径为:', config.CAprivkey_path) print('申请认证成功!')
def authenticate(): print('请输入姓名:', end='') name = input() print('请输入CA私钥文件路径:', end='') CAprivkey_path = input() if os.path.exists(config.certificate + name + '.pem'): CAprivkey = RSA.read_privkey(CAprivkey_path) text = function.read_file(config.certificate + name + '.pem') text = RSA.rsaDecrypt(text, CAprivkey) function.save_file(config.certificate + name + '.pem', text) print('认证成功!') else: print('认证失败!')
# Isaac Li # 1.23.2018 import time import numpy as np import xgboost as xgb from sklearn.model_selection import KFold from sklearn.metrics import mean_squared_error import function train, test = function.read_file() train = train.loc[train['血糖'] > 5] train["血糖"] = np.log1p(train["血糖"]) train, test = function.transform(train, test) pred = test.copy() pred.drop('血糖', axis=1, inplace=True) model_xgb = xgb.XGBRegressor(colsample_bytree=0.7, gamma=0.15, learning_rate=0.03, max_depth=5, min_child_weight=80, n_estimators=1100, reg_alpha=0.5, reg_lambda=0.7, subsample=0.9, silent=True, nthread=8, early_stopping_rounds=100) ''' model_xgb = xgb.XGBRegressor(colsample_bytree=0.4603, gamma=0.0468, learning_rate=0.05, max_depth=3, min_child_weight=1.7817, n_estimators=2200, reg_alpha=0.4640, reg_lambda=0.8571, subsample=0.5213, silent=True, nthread = 8)''' print('\n\nStart...')
from math import atan, pi from function import createCountry, read_file, write_country_file, write_individual def trade_function(d, s): return (1.2) * (2 / pi) * atan((d - s) * (1 / 5000)) + 1.2 if __name__ == "__main__": print("開始執行程式") resources = ["糧食", "木頭", "鐵礦", "石頭"] trade_info = read_file( "系統貿易(回應)") # [時間, 國家名, 賣糧, 賣木, 賣鐵, 賣石, 買糧, 買木, 買鐵, 買石] countryDict = createCountry() print("讀檔完成\n") # 定價 price_list, demand, supply = [], [0] * 4, [ 0 ] * 4 # [糧食, 木頭, 鐵礦, 石頭], 物資的總需求,總供給 [糧食, 木頭, 鐵礦, 石頭] for j in trade_info: name = j[1] if countryDict[name].food < j[2]: # 如果物資不夠賣,將當回賣的物資量等同現有物資存量,並顯示錯誤 j[2] = countryDict[name].food print(f"{name}沒有足夠的糧食去貿易") if countryDict[name].wood < j[3]: j[3] = countryDict[name].wood print(f"{name}沒有足夠的木頭去貿易")
elif command == "create_file": name = sys.argv[2] create_file(name) elif command == "del_file": name = sys.argv[2] del_file(name) elif command == "del_dir": name = sys.argv[2] del_dir(name) elif command == "re_name": name = sys.argv[2] n_name = sys.argv[3] re_name(name, n_name) elif command == "move_file": name = sys.argv[2] n_name = sys.argv[3] move_file_in_dir(name, n_name) elif command == "copy_file": name = sys.argv[2] n_name = sys.argv[3] copy_file(name, n_name) elif command == "read_file": name = sys.argv[2] read_file(name) elif command == "cls": cls() elif command == "help": name = sys.argv[2] help_list(name)
# Isaac Li # 1.23.2018 import time import numpy as np from sklearn.model_selection import KFold from sklearn.metrics import mean_squared_error import function train, test = function.read_file(path='a') train["血糖"] = np.log1p(train["血糖"]) train, test = function.add_column(train, test) train, test = function.transform(train, test) print('\n\nStart...') t0, mses = time.time(), [] train_preds, test_preds = np.zeros(train.shape[0]), np.zeros((test.shape[0], 5)) predictors = [f for f in test.columns if f not in ['血糖']] kf = KFold(n_splits=5, shuffle=True, random_state=520) for i, (train_index, test_index) in enumerate(kf.split(train)): print(' .{}/5.'.format(i + 1)) train_feat1, train_feat2 = train.iloc[train_index], train.iloc[test_index] gbm = function.settings.model_lgb.fit(train_feat1[predictors], train_feat1['血糖'], categorical_feature=['性别', '体检日期']) predict = gbm.predict(train_feat2[predictors]) train_preds[test_index] += predict mses.append(.5 * mean_squared_error(np.expm1(train_feat2['血糖']), np.expm1(predict))) test_preds[:, i] = gbm.predict(test[predictors]) cv = .5 * mean_squared_error(np.expm1(train['血糖']), np.expm1(train_preds))
import function import os ID, CATEGORY, PRODUCT, QUANTITY, PRICE = range(5) list_options_for_main_menu = [ "Press A to add to basket", "Press P to pay", "Press X to exit" ] list_options_for_basket_menu = [ "Press R to remove item to basket", 'Press F to complete the oreder', 'Press C to change quantity to basket', 'Press X to exit', "Press B to continue shopping" ] column_labels = ["ID", "Category", "Product", "Quantity", "Price"] inventory = function.read_file("stock.csv") h_char = "-" v_char = " " * 5 def find_longest_item(list_of_items, label): str_length = len(column_labels[label]) for item in list_of_items: if len(str(item[label])) > str_length: str_length = len(str(item[label])) return str_length def max_lengths(list_of_items): return [find_longest_item(inventory, x) for x in range(5)]
# ------------ import -------------------------------------------------------------------------------------------------- import function import pandas as pd from sklearn.metrics import mean_squared_error import time import numpy as np from sklearn.model_selection import KFold # ------------ read file ----------------------------------------------------------------------------------------------- base, power, minimum = 1.7, 1, 7.2 s = input(' s: ') if not s: print(' s. ') train_a, test_a = function.read_file(path='sa') train_b, test_b = function.read_file(path='sb') else: train_a, test_a = function.read_file(path='a') train_b, test_b = function.read_file() train_a, train_b = train_a.sample(frac=1), train_b.sample(frac=1) ans_path = function.settings.source_path + 'd_answer_a_20180128.csv' ans = pd.read_csv(ans_path, encoding='gbk') # NOTICE: add a row in file as index! # ------------ predict a ----------------------------------------------------------------------------------------------- a = input('Part A? -> ') if a: print('Done.')
import pandas as pd from time import sleep from function import (read_file, write_country_file, createCountry, write_individual, consume, education, handle_action, production, read_card, card, war, wonder, write_wonders) if __name__ == "__main__": print("開始執行程式") countryDict = createCountry() actionList, cardDict = handle_action(countryDict), read_card() wonderlist = read_file("世界奇觀") produceNum = pd.read_csv("生產函數表.csv", index_col=0, encoding="ANSI") countryName = [ "亞特蘭提斯", "阿斯嘉", "奧林帕斯", "瓦干達", "香格里拉", "瓦拉納西", "瑪雅", "塔爾塔洛斯", "特奧蒂瓦坎", "復活節島" ] defeated, messageDict = {i: False for i in countryName }, {i: [] for i in countryName} print("讀取檔案完成") for i in actionList: production(countryDict, produceNum, i.name, i.produceList, i.occupyMan, messageDict) if i.useCard or i.soldCard: card(countryDict, i.name, cardDict, i.useCard, i.soldCard, defeated, messageDict) education(countryDict, i.name, i.education, messageDict)
def main(): basket = [] while True: option = "0" if option == "0": stock = function.read_file("stock.csv") display.print_table(stock, "inventory") display.print_menu(list_options_for_main_menu) get_input = display.get_input(["Enter your option!"], "") option = get_input[0] if option.lower() == "a": while True: items_for_basket = display.get_single_input("Choose id: ") if function.check_id(items_for_basket, stock): quantity_for_basket = display.get_single_input( "Quantity: ") if function.check_quantity(items_for_basket, quantity_for_basket, stock): function.add_basket(items_for_basket, quantity_for_basket, basket, stock) else: print("Not enough quantity! ") else: print("Not in stock!") second_choose = display.get_input( ["Do you want to add something? "], "") if second_choose[0].lower() == "no": os.system('clear') break option = "0" if option.lower() == "x": os.system('clear') exit() while option.lower() == "p": os.system('clear') display.print_table(basket, "basket") display.print_menu(list_options_for_basket_menu) second_choose = display.get_single_input('Choose the option: ') if second_choose.lower() == "r": id_for_remove = display.get_single_input( "Choose the item for complet remove! ") function.remove_from_bascket(id_for_remove, basket) os.system('clear') option = "p" if second_choose.lower() == 'c': id_for_cahnge_quantity = display.get_single_input( "Choose the item to change the quantity! ") if function.check_id(id_for_cahnge_quantity, basket): quantity_for_cahange = display.get_single_input( "Choose quantity! ") if function.check_quantity(id_for_cahnge_quantity, quantity_for_cahange, basket): function.change_qunatity_from_bascket( id_for_cahnge_quantity, quantity_for_cahange, basket) option = 'p' else: print('You do not have this quantity in the basket!') option = "p" else: print('You do not have this item in the basket!') option = 'p' if second_choose.lower() == 'f': a = 0 while a < 3: to_valid = function.card_payment() if function.validate_card_details(to_valid): function.write(function.update_stock(basket)) print( "Nu ai bani pe card sarakule!!!, Mars la munca baaa, lepra ce esti! Oricum nu stii sa citesti. " ) exit() else: a += 1 if second_choose.lower() == 'b': option = "0" break if second_choose.lower() == 'x': os.system('clear') exit()