def refresh_students (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object stm = Students_Table_Management() # Delete the table if it already exists stm.drop (database) # Create students table stm.create (database) # Create a Student Object student = Student(oyd_id=15505, first_name='Thomas', middle_name = 'Alan', last_name='Grate', age= 53, birth_date = '5/10/1964', school=1, start_date = '5/31/2006', position = 'HI', rank = '3D', next_rank = '4D', class_group = 'Instructor') result = student.put (database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} Students Table: Added Students to Database" print_table (database, 'students', title) database.close_db()
def refresh_regions (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object stm = Regions_Table_Management() # Delete the table if it already exists stm.drop (database) # Create students table stm.create (database) region = Region (region_name='Pacific NW', region_abbrev="PNW", nat_area=1, main_reg_id='15500', email='*****@*****.**', street='7858 Leary Way', city='Redmond', state='WA', postal_code='98052', phone='(425) 202-4898', status='0', standing='0') region.put(database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} Regions Table: Added Regions to Database" print_table (database, 'regions', title) database.close_db()
def compare_searchers(problems, header, searchers=[breadth_first_tree_search, breadth_first_search, depth_first_graph_search, iterative_deepening_search, depth_limited_search, recursive_best_first_search]): def do(searcher, problem): p = InstrumentedProblem(problem) searcher(p) return p table = [[name(s)] + [do(s, p) for p in problems] for s in searchers] print_table(table, header)
def refresh_schools (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object schtm = Schools_Table_Management() # Delete the table if it already exists schtm.drop (database) # Create students table schtm.create (database) # Create and Insert a New Student if not silent_mode: print(f"Refresh {filename} Schools Table: Adding first school") print("--------------------------") school = School(school_name='Redmond', school_region=1, main_ins_id='15507', email='*****@*****.**', street='7858 Leary Way', city='Redmond', state='WA', postal_code='98052', school_phone='(425) 202-4898', status='0', standing='0') school.put(database) school = School(school_name='Kirkland', school_region=1, main_ins_id='15519', email='*****@*****.**', street='11506 124th Ave NE', city='Kirkland', state='WA', postal_code='98033', school_phone='(425) 803-6800', status='0', standing='0') school.put(database) school = School(school_name='Seattle', school_region=1, main_ins_id='15500', email='*****@*****.**', street='12354', city='Seatle', state='WA', postal_code='98125', school_phone='(206) 817-2600', status='0', standing='0') school.put(database) school = School(school_name='Root Academy', school_region=1, main_ins_id='99999', email='*****@*****.**', street='2332 N 116th St', city='Seattle', state='WA', postal_code='98133', school_phone='(206) 817-2600', status='0', standing='0') school.put(database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} Schools Table: Added Schools to Database" print_table (database, 'schools', title) database.close_db()
def get_qie_shift_reg(ts , crate , slot , qie_list = range(1,5) ): qie_settings = [ "CalMode", "CapID0pedestal", "CapID1pedestal", "CapID2pedestal", "CapID3pedestal", "ChargeInjectDAC", "DiscOn", "FixRange", "IdcBias", "IsetpBias", "Lvds", "PedestalDAC", "RangeSet", "TGain", "TimingIref", "TimingThresholdDAC", "Trim"] table = [qie_settings] qieLabels = ["setting"] commands = [] for qie in qie_list : #print qie for setting in qie_settings : commands.append("get HF{0}-{1}-QIE{2}_{3}".format(crate,slot,qie,setting)) ngccm_output = send_commands_parsed(ts , commands) for qie in qie_list : qieLabels.append("QIE {0}".format(qie)) values = [] for i in ngccm_output["output"] : for setting in qie_settings : if setting in i["cmd"] and "QIE{0}".format(qie) in i["cmd"]: values.append( i["result"] ) table.append( values ) #print table table_ = [ qieLabels ] for i in zip(*table) : table_.append(i) print_table(table_)
def refresh_MLTattendance (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object atm = MLTAttendance_Table_Management() # Delete the table if it already exists atm.drop (database) # Create students table atm.create (database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} MLT Attendance Table: Added mltattendance to Database" print_table (database, 'mltattendance', title) database.close_db()
def signal_bind(port_dict): ''' 该函数用于让用户在提供的信号内选择绑定的信号用作时钟或复位 ''' print('Valid Input Signal:') print_table(['Name'], [i['Name'] for i in port_dict if i['IO Type'] == 'input']) clk_sig = read_value( 'Plese Select the Clock Signal', str, [i['Name'] for i in port_dict if i['IO Type'] == 'input'] + ['none']) print('You have select {} as input clock resource .'.format(clk_sig)) rst_sig = read_value( 'Plese Select the Reset Signal', str, [i['Name'] for i in port_dict if i['IO Type'] == 'input'] + ['none']) print('You have select {} as input reset resource .'.format(rst_sig)) return { 'clk_sig': clk_sig, 'rst_sig': rst_sig, 'data_sig': 's_axis_tdata', 'valid_sig': 's_axis_tvalid', 'ready_sig': 's_axis_tready' }
def refresh_masterevents (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object stm = Master_Events_Table_Management() # Delete the table if it already exists stm.drop (database) # Create students table stm.create (database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} Master Events Table: Added MasterEvents to Database" print_table (database, 'masterevents', title) database.close_db()
def reversi(): table = create_table() players = ['W', 'B'] current_player = 'W' count = 0 while True: # Switch player for player in players: if current_player != player: current_player = player break # Show valide valid move valid_moves = valid_choice_optimize(table, current_player) encoded_valid_moves = encode_valid_moves(valid_moves) # Check if have any available move or not if valid_moves == []: print('Player %s cannot play.' % current_player) count += 1 if count == 2: score(table) break continue print('Valid choices:', encoded_valid_moves) try: player_move = input('Player %s: ' % current_player) except EOFError: pass # User input's availability x = check_move(valid_moves, player_move) if x is False: print('Valid choices:', encoded_valid_moves) break _, encoded_player_move = check_move(valid_moves, player_move) # table = update_table_optimize(table, choice(valid_moves), current_player) table = update_table_optimize(table, encoded_player_move, current_player) # print(table) # Show result print_table(table) # Running mode count = 0 # If a player can move, reset the count
def testbench_analyze(dut_fid): ''' 分析Verilog代码并产生对应的测试文本 ''' ''' 未考虑到函数里的端口定义,与线网 signed情况 ''' print_info('Start Verilog File Analyze!') file = dut_fid.read() # 去除所有注释部分 file = format_delete('(/{2,}.*?\n)|(?:/\*(\n|.)*?\*/)', file) # 模块名位于'module'后,若有参数列表则位于'#'前,否则则位于'('前 module_name = format_get('module\s*(\S*)\s*[#|\(]', file)[0] print('Module Name Table : \n') print_table(['Name'], module_name) # 提取参数列表中的参数 提取逻辑可以表示如下 位于#右侧的第一个括号内以,分割 param_info = format_get( '((?:parameter)|(?:localparam))\s*(\w*)\s*=\s*(.*?)\s*[;,)]', file) print('Parameter Information Table :') print_table(['Type', 'Name', 'Value'], param_info) param_dict = list2dict(['Type', 'Name', 'Value'], param_info) # 提取端口具体信息 file = format_delete('(?:function)(?:.|\n)*(?:endfunction)', file) # 提前删除function->endfunction防止function中有端口声明 port_info = format_get( '((?:input)|(?:output)|(?:inout))(?:\s+(?:(?:reg)|(?:wire)))?\s+((?:signed)|(?:unsigned))?\s*(?:\[\s*(\S*)\s*:\s*(\S*)\s*\])?\s*(\w*)(?:\n|.)*?[;,)]', file) print('Port Information Table :') print_table(['IO Type', 'SIGNED', 'MSB', 'LSB', 'Name'], port_info) port_dict = list2dict(['IO Type', 'SIGNED', 'MSB', 'LSB', 'Name'], port_info) # 生成例化原型 return (module_name, param_dict, port_dict)
def refresh_areas (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object stm = NatAreas_Table_Management() # Delete the table if it already exists stm.drop (database) # Create students table stm.create (database) natarea = NatArea (area_name='West', area_abbrev="WST") natarea.put(database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} National Areas Table: Added Areas to Database" print_table (database, 'areas', title) database.close_db()
def refresh_courses (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object schtm = Courses_Table_Management() # Delete the table if it already exists schtm.drop (database) # Create students table schtm.create (database) course = Course (course_name='Bagua Program Year 1', course_abbrev="Bagua1") course.put(database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} Courses Table: Added Courses to Database" print_table (database, 'courses', title) database.close_db()
def refresh_informations (filename, silent_mode): # Open the database designated by filename database = Database() database.open_db(filename) # Instantiate a Table object stm = Informations_Table_Management() # Delete the table if it already exists stm.drop (database) # Create students table stm.create (database) information = Information(school=1, date='9/1/2017', first_name='John', last_name='Doe', age=37) result = information.put (database) if not silent_mode: # Print the updated students table title = f"Refresh {filename} Informations Table: Added Informations to Database" print_table (database, 'informations', title) database.close_db()
from print_table import * table = [ bin , vColumnBreak , vGJets_iso , vColumnBreak , vZgamRatio , vColumnBreak , vZestimate , vColumnBreak , vZinv , vEndLine ] table_ratios = [ bin , vColumnBreak , veffAcc , vColumnBreak , veffID , vColumnBreak , veffISO , vEndLine ] print_table( zip(*table) ) print_table( zip(*table_ratios) )
def indianFoker(): deck, present = fresh_deck() player_card = None com_card = None player_turn = False com_turn = False player_chips = 30 com_chips = 30 print("*순서를 정하는 중입니다.") time.sleep(0.5) if random.randint(0, 1) == 0: #선 정하기 player_turn = True print("\n\n*플레이어님이 선플레이어 입니다.") else: com_turn = True print("\n\n*컴퓨터가 선플레이어 입니다.") ro_und = 0 table_chips = 0 while deck != []: ro_und += 1 # 카드 한장씩 나눠가짐. player_card = deck[0] deck = deck[1:] com_card = deck[0] deck = deck[1:] player_betting_chips = 0 com_betting_chips = 0 table_chips += 2 #기본 베팅금 player_chips -= 1 player_betting_chips += 1 com_chips -= 1 com_betting_chips += 1 print("\n\n*자신의 카드를 이마 위에 붙여주세요.\n") time.sleep(0.5) print_table(ro_und, com_card, com_chips, player_chips, table_chips) player_betting_win = False com_betting_win = False player_value = player_card[ "rank"] if not player_card["rank"] == "A" else 1 com_value = com_card["rank"] if not com_card["rank"] == "A" else 1 present.remove(player_value) isAllIn = False while True: #베팅시작############################################################################### if player_turn: print("*플레이어님의 차례입니다. 베팅을 해주시지요.") response = playerBetting(com_betting_chips, player_betting_chips, player_chips) while player_chips < response and not response >= ( com_betting_chips) - (player_betting_chips): print("*보유 칩 개수보다 높은 숫자를 입력할 수 없습니다.") response = playerBetting() table_chips += response player_chips -= response player_betting_chips += response print_table(ro_und, com_card, com_chips, player_chips, table_chips) print("● 플레이어님께서", response, "개의 칩을 베팅하셨습니다.", "\n● 플레이어님은 총", player_betting_chips, "개의 칩을 베팅하셨습니다.") print("○ 컴퓨터는 총", com_betting_chips, "개 의 칩을 베팅했습니다.") time.sleep(1) if response == 0: print("*플레이어님께서 다이를 하셨으므로 베팅은 컴퓨터의 승리로 종료되었습니다.\n") #다이해서 끝 player_turn = False com_turn = True com_betting_win = True break elif player_betting_chips == com_betting_chips: print("*플레이어님과 컴퓨터의 베팅한 칩의 개수가 같아졌으므로 베팅을 종료합니다.\n") #동률로 베팅 끝 player_turn = False com_turn = True break elif player_chips == 0: isAllIn = True if player_betting_chips < com_betting_chips: #상대랑 같아지려면 칩수 부족해서 올인 print("*칩 수가 부족했지만, 플레이어님께서 올인을 함으로써 베팅이 종료되었습니다.\n") player_turn = False com_turn = True break else: print("*플레이어님께서 올인을 하셨습니다.") player_turn = False com_turn = True elif com_turn: print("*컴퓨터 차례입니다.") print("*컴퓨터가 베팅을 하기를 기다려주세요.") time.sleep(1.5) if isAllIn: isAllIn = False if player_betting_chips - com_betting_chips > com_chips: behavior = select_behavior(present, player_value, com_chips, com_chips) # 다이 or 올인 else: behavior = select_behavior( present, player_value, (player_betting_chips) - (com_betting_chips), (player_betting_chips) - (com_betting_chips)) # 다이 or 격차만큼 베팅 else: if (player_betting_chips) - ( com_betting_chips) >= com_chips: # 칩 부족:다이 or 올인 behavior = select_behavior(present, player_value, com_chips, com_chips) # 다이 or 올인 else: if com_chips - ( player_betting_chips - com_betting_chips ) - player_chips >= 0: # 칩 많음:컴퓨터가 베팅에서 손해보지 않게 손봐줌. 최댓값의 경계값을 정해줌 behavior = select_behavior( present, player_value, (player_betting_chips) - (com_betting_chips), (player_betting_chips) - (com_betting_chips) + player_chips) #불필요한 베팅을 자제함. else: behavior = select_behavior(present, player_value, (player_betting_chips) - (com_betting_chips), com_chips) table_chips += behavior com_chips -= behavior com_betting_chips += behavior print_table(ro_und, com_card, com_chips, player_chips, table_chips) print("○ 컴퓨터가", behavior, "개의 칩을 베팅했습니다.", "\n○ 컴퓨터는 총", com_betting_chips, "개의 칩을 베팅했습니다.") print("● 플레이어님은 총", player_betting_chips, "개 의 칩을 베팅하셨습니다.") time.sleep(1) if behavior == 0: print("*컴퓨터가 다이를 했으므로 베팅은 플레이어님의 승리로 종료되었습니다.\n") #다이해서 끝 player_betting_win = True player_turn = True com_turn = False break elif player_betting_chips == com_betting_chips: print("*컴퓨터의 베팅한 칩의 개수가 플레이어님과 같아졌으므로 베팅을 종료합니다.\n") #동률로 베팅 끝 player_turn = True com_turn = False break elif com_chips == 0: if player_betting_chips > com_betting_chips: #상대랑 같아지려면 칩수 부족해서 올인 print("*칩 수가 부족했지만, 컴퓨터가 올인을 함으로써 베팅이 종료되었습니다.\n") player_turn = True com_turn = False break else: print("*컴퓨터가 올인을 했습니다.") player_turn = True com_turn = False #베팅끝############################################################################### #베팅결과가지고 칩나눠갖고 present.remove(com_value) time.sleep(0.5) print("*카드를 공개하겠습니다!") time.sleep(0.7) print("* 플레이어", player_card["suit"] + " " + str(player_card["rank"]), "vs", "컴퓨터", com_card["suit"] + " " + str(com_card["rank"]), "*") if com_betting_win: time.sleep(0.5) print("*플레이어님은 칩", player_betting_chips, "개를 잃으셨고, 컴퓨터는 칩", table_chips - com_betting_chips, "개를 얻었습니다.\n") time.sleep(0.5) if player_value == 10: #패널티 print("*플레이어님께서 10 을 든 상태로 '다이'를 외쳤으므로 칩 10개라는 패널티를 주겠습니다.\n") time.sleep(0.5) player_chips -= 10 com_chips += 10 com_chips += table_chips table_chips = 0 elif player_betting_win: time.sleep(0.5) print("*플레이어님은 칩", table_chips - player_betting_chips, "개를 얻으셨고, 컴퓨터는 칩", com_betting_chips, "개를 잃었습니다.\n") time.sleep(0.5) if com_value == 10: #패널티 print("*컴퓨터는 10 을 든 상태로 '다이'를 외쳤으므로 칩 10개 패널티를 주겠습니다.\n") time.sleep(0.5) com_chips -= 10 player_chips += 10 player_chips += table_chips table_chips = 0 elif player_value > com_value: time.sleep(0.5) print("*숫자 비교를 해보았을 때, 플레이어님이", ro_und, "라운드에서 승리하셨습니다.") time.sleep(0.5) print("*플레이어님은 칩", table_chips - player_betting_chips, "개를 얻으셨고, 컴퓨터는 칩", com_betting_chips, "개를 잃었습니다.\n") time.sleep(0.5) player_chips += table_chips table_chips = 0 elif player_value < com_value: print("*숫자 비교를 해보았을 때, 컴퓨터가", ro_und, "라운드에서 승리했습니다.") print("*플레이어님은 칩", player_betting_chips, "개를 잃으셨고, 컴퓨터는 칩", table_chips - com_betting_chips, "개를 얻었습니다.\n") time.sleep(0.5) com_chips += table_chips table_chips = 0 time.sleep(0.5) else: #숫자가 같을때 print("*숫자가 같네요. 비겼습니다. 테이블 위의 베팅된 칩은 그대로 두고 다음 라운드 진행하겠습니다.\n") time.sleep(0.5) if not (player_chips - 1 > 0 and com_chips - 1 > 0): break while not more("*다음 라운드를 시작하시겠습니까? (y/n) : "): print("*준비되시면 y 를 입력해주시길 바랍니다.") pass if not (player_chips - 1 > 0 and com_chips - 1 > 0): if (player_chips - 1) == (com_chips - 1): print( "*양쪽 플레이어의 칩 부족으로 더 이상 게임 진행이 불가능한 상태입니다.\n*최종승패를 가르도록 하겠습니다.\n" ) print("!인디언포커 무승부! <플레이어 칩 개수 : ", player_chips, "개", " vs ", "컴퓨터 칩 개수 : ", com_chips, "개>\n", sep='') time.sleep(1) if not (player_chips - 1) > 0: print( "*플레이어님의 칩 부족으로 더 이상 게임 진행이 불가능한 상태입니다.\n*최종승패를 가르도록 하겠습니다.\n") time.sleep(1) print("!컴퓨터 인디언포커 최종승리! < 컴퓨터 칩 개수 : ", com_chips, "개", " vs ", "플레이어 칩 개수 : ", player_chips, "개\n(음수는 빚진 것 입니다.)\n", sep='') time.sleep(0.5) elif not (com_chips - 1) > 0: print("*컴퓨터의 칩 부족으로 더 이상 게임 진행이 불가능한 상태입니다.\n*최종승패를 가르도록 하겠습니다.\n") time.sleep(1) print("!플레이어 인디언포커 최종승리! <플레이어 칩 개수 : ", player_chips, "개", " vs ", "컴퓨터 칩 개수 : ", com_chips, "개>\n(음수는 빚진 것 입니다.)\n", sep='') time.sleep(0.5) else: print("*덱이 모두 소진된 이유로 칩의 개수에 근거하여 최종 승패를 가리도록 하겠습니다.\n") time.sleep(1) if com_chips > player_chips: print("!컴퓨터 인디언포커 최종승리! < 컴퓨터 칩 개수 : ", com_chips, "개", " vs ", "플레이어 칩 개수 : ", player_chips, "개\n", sep='') elif com_chips < player_chips: print("!플레이어 인디언포커 최종승리! <플레이어 칩 개수 : ", player_chips, "개", " vs ", "컴퓨터 칩 개수 : ", com_chips, "개>\n", sep='') else: print("!인디언포커 무승부! <플레이어 칩 개수 : ", player_chips, "개", " vs ", "컴퓨터 칩 개수 : ", com_chips, "개>\n", sep='') time.sleep(0.5) #more if more("*게임을 한 판 더 하겠습니까? (y/n) : "): print("*새 게임 세트를 준비합니다.\n") time.sleep(1) print("*새 게임을 시작합니다.\n") indianFoker() else: print("*게임을 종료합니다")
from print_table import * testTable = [['1','2','3','4'],['5','6','7','8'],['9','10','11','12'] ] print_table( zip(*testTable) )
## Create Modelsim Tcl Script tcl_gen(TB_NAME, dir='./script/', opt=False, xilinx_sim=True) # 关闭优化,开启xilinx选项 print_info('Create Modelsim Do Script Done!') ## Copy File to Destination Path file_filter = lambda file_lst, format_lst: [ item for item in file_lst if item.partition('.')[2] in format_lst ] src_lst = [ shutil.copy('../' + PROJ_DIR_NAME + '/' + item, 'verilog/') for item in file_filter(os.listdir('../' + PROJ_DIR_NAME), ['sv', 'v']) ] #src_lst=[shutil.copy('../'+PROJ_DIR_NAME+'/'+item,'verilog/') for item in file_filter(os.listdir('../'+PROJ_DIR_NAME),['v'])] print_table(['Module Name'], src_lst) ## Create glbg glbl_gen('./verilog/') ## Regex Function Get & Delete format_get = lambda format, string: re.compile(format).findall(string) format_delete = lambda format, string: re.compile(format).sub('', string) ## This Function Convert List to Dictionary list2dict = lambda keys, vals: [dict(zip(keys, item)) for item in vals] def select_delete(src_str, spec_str, status): if status: return format_delete(