def __init__(self, binary): Lifter.__init__(self, binary) # return self.__debug = False for func in self.get_all_functions(): self.__optimize_function(func)
def lift(self, lines): best_points = 0 best_commands = '' count = 0 while True: l = Lifter() l.emu = Emulator(lines) l.emu.suppress_prints = True commands = l.createCommands() time_out, commands, points = l.time_out, commands, l.emu.points if best_points < points: best_points = points best_commands = commands if time_out: if not self.hide_print: print best_commands sys.stdout.flush() break return best_commands
def evaluate(): #Set this color as the default print white, '' maps_list = glob.glob('maps/*.map') maps_list.sort() maps_points = {} maps_points_old = {} if os.path.exists(cache_file): maps_points_old = pickle.load(open(cache_file, 'r')) for map_file in maps_list: lifterEmu = Emulator(open(map_file, 'r'), '') lifterEmu.suppress_prints = True lifterEmu.print_points = False l = Lifter() l.emu = lifterEmu commands = l.createCommands() emu = Emulator(open(map_file, 'r'), commands) emu.suppress_prints = True emu.print_points = False while not emu.quit: emu.processCommand() points = emu.points maps_points[map_file] = points delta_points = 0 delta_value = '' #Check cache... old_points = maps_points_old.get(map_file) if old_points: delta_points = points - old_points if old_points > points: color = red elif old_points < points: delta_value = '+' color = green else: color = brown else: color = brown if delta_points == 0: delta_points = '' print map_file, '\t' + color + str(points) + ' ' + delta_value + str(delta_points) + white #Dump to the cache pickle.dump(maps_points, open(cache_file, 'w'))
def __init__(self, line, debug): reader = EffectReader(line) reader.parse_trace() signal.signal(signal.SIGALRM, handler) signal.alarm(15) lifter = Lifter(reader.code) InstructionExecutor(reader, lifter, debug) signal.alarm(0)
def test_equal(self): for x in data: dvigalec = Lifter.make_lifter(x["Ime"], x["Poteg"], x["Sunek"]) # for every x in data got from Sheet 1, creates a dvigalec based on three characteristics "Ime", "Poteg", "Sunek" lifterList.append(dvigalec) # opens Chrome browser and gets the path to MojaSpletnaStran.html file where you downloaded it browser = webdriver.Chrome() current_dir = os.getcwd() browser.get(current_dir + "\\MojaSpletnaStran.html") # finds elements in html file based on ID elem_name = browser.find_element_by_id("Ime") elem_poteg = browser.find_element_by_id("Poteg") elem_sunek = browser.find_element_by_id("Sunek") # for every l in lifterList array of dvigalec, sends keys from data to certain element ID and at the end clicks a button on html page for l in lifterList: elem_name.send_keys(l.name) elem_poteg.send_keys(l.snatch) elem_sunek.send_keys(l.cj) browser.find_element_by_class_name('buttonDodaj').click() # Test for comparrison between Excell sheet and output table on HTML webpage elem_table_rows = browser.find_elements_by_class_name('tr') # defining array of strings with values same as elements by class name tr keys = ["Ime", "Poteg", "Sunek", "Biatlon"] indexE = 1 # indexE = 1 as long as it is shorter then the length of elem table rows which is in our case 8 (lifters) and we start at 1 cuz that's the position of the first lifter while indexE < len(elem_table_rows): # splits the text by the empty string so that we have 3 values of name, snatch, cj lifter_array = elem_table_rows[indexE].text.split(' ') indexL = 0 while indexL < len(lifter_array)-1 : #compares if the a is equal to b on a lifter array which is on the site and with the data extracted from googledrive sheet 1, finds them by the keys we selected self.assertEqual(lifter_array[indexL], str(data[indexE-1][keys[indexL]]))# {["Ime":"Luka", "Poteg": "110", ....], ["Ime": "Jure", ....]} # this whole commented section is the alternative path to compare if the inserted data on html is equal to data in excell document. # if lifter_array[indexL] != str(data[indexE-1][keys[indexL]]): # print('Error!') # else: # print(lifter_array[indexL] + ": OK") indexL += 1 indexE += 1 print("Konec!")