def get_usercommand(self): self.last_at_time = self.get_last_at_time() log("LAST_AT_TIME:%s" % self.last_at_time) self.last_at_time = Helper.str2date(self.last_at_time) try: list = self.api.mentions(5) #TODO: 5不靠谱. for listat in list: if listat.created_at>self.last_at_time: if "zf@0904201".decode("utf-8") in listat.text: log("ReceiveCommand %s From %s!" % \ (listat.user.name, "zf")) Helper.add_command_log(listat.user.name, "zf", listat.text, str(listat.created_at)) try: retid = listat.retweeted_status.id except: retid = listat.id self.repost_message(retid) else: log("ReceiveUnknownCommand.Text:%s" % listat.text) else: log("Break Loop at %s" % str(listat.created_at)) break except: log("Get User Command Except Exception!") raise Helper.refresh_at_time()
def classify(img, featureRepresentation='image', model_file=CLASSIFIER_FILE, shouldSaveResult=False): ''' Classifies a sub-image or list of sub-images as grain (1) or not grain (0). Args: img: Input sub-image or list of input sub-images. featureRepresentation: Type of features to be used in classification. Can ake of one of the values 'image', 'pca' or 'glcm'. Note that the classifier must have also been built using the same feature representation. model_file: filepath of serialized classifier to be used. shouldSaveResult: If this boolean flag is set to true, this function will save the sub-images and their classifictions to the "Results" folder after classification. Return: scalar or list of 1 if grain and 0 otherwise. ''' if(isinstance(img, np.ndarray)): img_features = None if(featureRepresentation == 'image'): img_features = img.flatten() elif(featureRepresentation == 'pca'): img_features = decomposition.PCA(n_components=8).fit_transform(img.flatten()) elif(featureRepresentation == 'glcm'): img_features = Helper.get_textural_features(img, 1, True) clf = get_model(model_file) return clf.predict(img_features.reshape(1,-1)) elif(isinstance(img, list)): if(featureRepresentation == 'glcm'): sample_size = 16 else: sample_size = 20*20 test_data = np.zeros((len(img), sample_size)) i = 0 for image in img: if(featureRepresentation == 'image'): test_data[i] = image.flatten() elif(featureRepresentation == 'pca'): test_data[i] = decomposition.PCA(n_components=8).fit_transform(image.flatten()) elif(featureRepresentation == 'glcm'): test_data[i] = Helper.get_textural_features(image, 1, True) i = i+1 clf = get_model(model_file) result = clf.predict(test_data) if(shouldSaveResult == True): # Save image with result in filename if os.path.exists("Results"): shutil.rmtree("Results") os.makedirs("Results") for i in xrange(0,len(img)): io.imsave("Results/{}_{}.png".format(Helper.generate_random_id(8), result[i]), img[i]) else: return None
def colorAt(self, ray, t, objectlist): sp = ray.pointAtParameter(t) # Schnittpunkt am Objekt d = ray.direction n = self.normalAt(sp) Ca = np.array(self.color) c_out = 0 for light_source in helper.light_sources: light = helper.normalize(sp - light_source) # Vektor vom Licht zum Schnittpunkt lr = light - 2 * np.dot(n, light) * n lightV = helper.normalize(light_source - sp) c_ambient = Ca * helper.ka c_diffus = helper.Cin * helper.kd * np.dot(lightV, n) c_spec = helper.Cin * helper.ks * math.pow(np.dot(lr, d), 32) c_tmp = c_ambient + c_diffus + c_spec newRay = Ray(sp, light_source - sp) for o in objectlist: if o is self: pass else: x = o.intersectionParameter(newRay) if x and x > 0: c_tmp *= 0.5 break c_out += c_tmp return c_out
def calculate(grid, maxdepth, is_it_max): if maxdepth == 0: return Helper.heuristic(grid) if not Helper.canMove(grid): return Helper.heuristic(grid) if is_it_max: v = -np.inf [children, moving] = Helper.getAvailableChildren(grid) for child in children: v = max(v,calculate(child,maxdepth-1,False)) return v else: cells = [i for i, x in enumerate(grid) if x == 0] children = [] v = np.inf for c in cells: gridcopy = list(grid) gridcopy[c]=2 children.append(gridcopy) gridcopy = list(grid) gridcopy[c]=4 children.append(gridcopy) for child in children: v = min(v,calculate(child,maxdepth-1,True)) return v
def run(self): message_url = "http://weibo.cn/msg/chat/list?tf=5_010&vt=4&gsid=%s" % self.gsid message_page = self._request(message_url).read() #TODO: try: total_page_count = int(re.findall(r'<input type="submit" value="跳页" />(?:.*?)/((?:\d)+)(?:.*?)</div>', message_page)[0]) except: raise Exception("got an error!") log("TOTAL_PAGE_COUNT: %s" % total_page_count) page_index = 1 conversations = self.get_conversations(message_page) while page_index<total_page_count: page_index += 1 conversations.extend(self.fetch_conversations(page_index)) log("Total %d Conversations!" % len(conversations)) messages = [] for conversation in conversations: peoples = [conversation["p1"],conversation["p2"]] detail = conversation["detail"] message_page = self._request(BASE_URL+detail).read() messages.extend(self.get_messages(message_page, peoples)) log("Messages Total %d Counts!" % len(messages)) Helper.save_2_sqlite(messages)
def summary(state): """ Provides a summary of selected player :param state: current state of variables :return: prints a summary of the player """ # Initialize variables stat_rankings = defaultdict(lambda: (defaultdict(float))) for player in state.normalized_player_statistics[state.iteration]: for statistic_name in state.normalized_player_statistics[state.iteration][player]: stat_rankings[statistic_name][player] = \ state.normalized_player_statistics[state.iteration][player][statistic_name] # Decide which player to view the stats of while state.player_to_obtain is None: desired_player = raw_input("Enter a player name: ").lower() # If the input is valid, remove player from draft and add them to a team if desired_player in state.cumulative_player_statistics[state.iteration]: state.update_player_to_obtain(desired_player) # Suggests player names if input is incorrect else: Helper.check_incorrect_input(desired_player, state.normalized_player_statistics[state.iteration].keys()) return Helper.calculate_player_summary(stat_rankings, state.player_to_obtain)
def get_messages(self, html, peoples): status = 0 conversations = re.findall("<div class=\"c\">(.*?)</div>", html) conversations = conversations[2:-3] ret = [] for conversation in conversations: msg = {} tokens = re.findall(r'(.*?)<span', conversation)[0] tokens = re.sub(r'<(?:.*?)>', '', tokens) # 去除html标记 tokens = re.sub(r'\[(在线|忙碌|离开)\]', '', tokens) # 去除在线标记 tokens = re.sub(r'\[\d+条新\]', '', tokens) tokens = re.split(r':', tokens, 1) people = tokens[0] message = tokens[1] time = re.findall(r'<span class="ct">(.*?)</span>', conversation)[0] time = Helper.datetime_formater(time) cnt_datetime = Helper.str2date(time) if not cnt_datetime>self.last_time: status = 1 return ret,status if people == peoples[0]: msg["dst"] = peoples[1] else: msg["dst"] = peoples[0] msg["src"] = people msg["message"] = Helper.sql_escape(message) msg["time"] = time ret.append(msg) return ret, status
def get_conversations(self, html): status = 0 conversations = re.findall("<div class=\"c\">(.*?)</div>(?=<div class=\"(?:[cs])\"\>)", html) conversations = conversations[1:-2] parser = HTMLParser.HTMLParser() ret = [] for conversation in conversations: item = {} tokens = re.findall(r'(.*?)<span class="ct">', conversation)[0] tokens = re.sub(r'<(?:.*?)>', '', tokens) # 去除html标记 tokens = re.sub(r'\[(在线|忙碌|离开)\]', '', tokens) # 去除在线标记 tokens = re.sub(r'\[\d+条新\]', '', tokens) tokens = re.split(r' ', tokens) latest = tokens[3] latest = re.split(r':', latest, 1)[1] time = re.findall(r'<span class="ct">(.*?)</span>', conversation)[0] time = Helper.datetime_formater(time) cnt_datetime = Helper.str2date(time) if not cnt_datetime>self.last_time: status = 1 return ret,status detail = re.findall(r'语音通话(?:.*?)<a href="(.*?)" class="cc">(?:.*?)</a>', conversation)[0] detail = parser.unescape(detail)+"&type=record" count = re.findall(r'共(\d+)条对话', conversation)[0] item.update(dict(p1=tokens[0],p2=tokens[2],latest=latest,time=time,detail=detail,count=count)) ret.append(item) return ret,status
def info_online(self): """ First good use of HELP_URL in addonpy template :return: Opens the Help URL in default browser """ url = self.get_help_url() print("Opening URL '{0}'".format(url)) Helper.open_url(url)
def _process(process): ''' Generate the code for a complete process (AST Top level) ''' # In case model has nested states, flatten everything Helper.flatten(process) # Make an maping {input: {state: transition...}} in order to easily # generate the lookup tables for the state machine runtime mapping = Helper.map_input_state(process)
def __StatusUpdateAS(self, curlen, akttests, tests, count, killed, dictLen): self.parent.SetStatusText("cur-len: "+str(curlen+1)+\ " tests: "+hlp.intToStringWithCommas(akttests)+\ " / "+hlp.intToStringWithCommas(tests)+\ " total: "+hlp.intToStringWithCommas(count)+\ " removed: "+hlp.intToStringWithCommas(killed)+\ " dict: "+hlp.intToStringWithCommas(dictLen), 0) wx.Yield()
def resultfiletopairs(filename, outname): print "init gene level proteins ..." proteinsA, proteinsB, orthologs = GeneLevelProtein.initGeneLevelProteins(filename, None, None, False) print "pairwise orthology mappings ..." pairwise = Helper.pairwiseOrthologs(orthologs, proteinsA, proteinsB) Helper.printPairsToFile(pairwise, outname)
def get_model(filename=MLP_FILE): ''' Fetch MLP classifier object from file''' classifier = Helper.unserialize(filename) if(classifier == None): classifier = build_model('glcm', dataset_file='../Datasets/old_data.data', iters=2) Helper.serialize(filename, classifier) return classifier
def setUp(self): self._logger.info("_______________UI TestCase setUp_______________") ''' Unlock the device ''' self.phone._viewclient.dump() if(self.phone.getConfigItem('needunlock') =='1'): Helper.unlockDevice(self.phone) self.phone.sleep(2)
def _process(process): ''' Generate LLVM IR code (incomplete) ''' process_name = process.processName LOG.info('Generating LLVM IR code for process ' + str(process_name)) # In case model has nested states, flatten everything Helper.flatten(process) # Make an maping {input: {state: transition...}} in order to easily # generate the lookup tables for the state machine runtime mapping = Helper.map_input_state(process) # Initialise LLVM global structure LLVM['module'] = core.Module.new(str(process_name)) LLVM['pass_manager'] = passes.FunctionPassManager.new(LLVM['module']) LLVM['executor'] = ee.ExecutionEngine.new(LLVM['module']) # Set up the optimizer pipeline. # Start with registering info about how the # target lays out data structures. # LLVM['pass_manager'].add(LLVM['executor'].target_data) # # Do simple "peephole" optimizations and bit-twiddling optzns. # LLVM['pass_manager'].add(passes.PASS_INSTRUCTION_COMBINING) # # Reassociate expressions. # LLVM['pass_manager'].add(passes.PASS_REASSOCIATE) # # Eliminate Common SubExpressions. # LLVM['pass_manager'].add(passes.PASS_GVN) # # Simplify the control flow graph (deleting unreachable blocks, etc). # LLVM['pass_manager'].add(passes.PASS_CFG_SIMPLIFICATION) # LLVM['pass_manager'].initialize() # Create the runTransition function run_funct_name = 'run_transition' run_funct_type = core.Type.function(core.Type.void(), [ core.Type.int()]) run_funct = core.Function.new( LLVM['module'], run_funct_type, run_funct_name) # Generate the code of the start transition: # Clear scope LLVM['named_values'].clear() # Create the function name and type funct_name = str(process_name) + '_startup' funct_type = core.Type.function(core.Type.void(), []) # Create a function object function = core.Function.new(LLVM['module'], funct_type, funct_name) # Create a new basic block to start insertion into. block = function.append_basic_block('entry') builder = core.Builder.new(block) # Add the body of the function builder.call(run_funct, (core.Constant.int( core.Type.int(), 0),)) # Add terminator (mandatory) builder.ret_void() # Validate the generated code, checking for consistency. function.verify() # Optimize the function (not yet). # LLVM['pass_manager'].run(function) print function
def isSolved(self, pgs, pgdp, zfl): if len(zfl)>len(pgdp): # es gibt mehr Goal squares als Boxen for i in pgdp: if hlp.punpack(i) not in zfl: return(False) else: # es gibt mehr Boxen als Goal squares oder gleich viele for i in zfl: if hlp.ppackt(i) not in pgdp: return(False) return(True)
def processQueue(currentTracks, indicesToDownload): print('') print(indicesToDownload) filesSkipped = False disconnectionError = False numberOfSongsToDownload = len(indicesToDownload) for downloadNumber in range(numberOfSongsToDownload): try: songIndex = indicesToDownload[downloadNumber] currentSong = currentTracks[songIndex] currentDownload = Download.Download(currentSong, downloadNumber, numberOfSongsToDownload, downloadFolder) except Exception, e: print(str(e)) print('Other library disconnected') disconnectionError = True break currentDownload.printSongInfo() updateFlashWithDownloadInfo(downloadNumber, numberOfSongsToDownload) currentDownload.artist = Helper.fixFileName(currentDownload.artist) currentDownload.album = Helper.fixFileName(currentDownload.album) currentDownload.title = Helper.fixFileName(currentDownload.title) if(currentDownload.isAlreadyExists()): print('Already downloaded, skipping!\n') continue if(currentDownload.isWrongType()): print('Song is protected or is non-audio, skipping!\n') filesSkipped = True continue # reset internal iTunes counter currentSong.Play() iTunes.Stop() # begin waiting capture = CapturePacket.CapturePacket(iTunesSock) capture.start() # bait it out... try: currentSong.Play() except Exception, e: print(str(e)) print('File missing!\n') # flip killswitch for thread capture.kill() # tell flash something's up filesSkipped = True continue
def filetodb(c, filehandle, tax): fileAsList = [] accessions = [] for line in filehandle.readlines(): if not line.startswith("#") and not line.startswith("<"): # header usually starts with < split = line.split("\n")[0].split() if len(split) == 0: continue acc = Helper.retrieveAccessionNumber(split[0]) fileAsList.append( [ acc, split[1], split[2], split[3], split[4], split[5], split[6], split[7], split[8], split[9], split[10], split[11], split[12], split[14], ] ) accessions.append(acc) lengths = Helper.getSequenceLengthsForAccessionsIds(accessions) i = c.execute("select count(*) from tsv_storage").fetchone()[0] for split in fileAsList: writetodb( c, i, split[0], tax, split[1], split[2], split[3], split[4], split[5], split[6], split[7], split[8], split[9], split[10], split[11], split[12], split[13], int(lengths[split[0]]), ) i = i + 1
def initDomainLevelProteins(domainfile): handle = open(domainfile, 'r') proteinsA = {} proteinsB = {} orthologGroups = {} groupsStarted = False ort = None lineStarts = ['Group', 'Score', 'Boots', '_____'] #header, protein, start, end for line in handle.readlines(): if groupsStarted: if line[0:5] not in lineStarts: hasA = not line.startswith(' ') splittedLine = line.split() temp = ort.getBasicProteins(splittedLine) for p in temp: p.__class__ = DomainLevelProtein if hasA: splittedHeader = Helper.retrieveDomainHeaderInformation(splittedLine[0]) temp[0].domain = splittedHeader[1] temp[0].start = int(splittedHeader[2]) temp[0].end = int(splittedHeader[3]) temp[0].header = splittedLine[0] proteinsA[temp[0].header] = temp[0] score = float(splittedLine[1].split('%')[0]) ort.inparalogsA[temp[0].header] = score if not hasA or len(temp) > 1: splittedHeader = Helper.retrieveDomainHeaderInformation(splittedLine[-2]) temp[-1].domain = splittedHeader[1] temp[-1].start = int(splittedHeader[2]) temp[-1].end = int(splittedHeader[3]) temp[-1].header = splittedLine[-2] proteinsB[temp[-1].header] = temp[-1] score = float(splittedLine[-1].split('%')[0]) ort.inparalogsB[temp[-1].header] = score elif line.startswith('Group'): ort = OrthologyGroup.getBasicOrthologyGroup(line, False, orthologGroups) elif line.startswith('Bootstrap'): ort.addSeeds(line) else: if line.startswith('_'): groupsStarted = True handle.close() return proteinsA, proteinsB, orthologGroups
def run(self): n = 9 max = 0 while True: n = n - 1 for perm in Helper.listPermutations(n): if Helper.isPrime(int(perm)): if int(perm) > max: max = int(perm) if max > 0: print(max) break
def inverseMovePlayer(self, pgs, pgd, pp, d): np=(pp[0]+self.mx[d], pp[1]+self.my[d]) # Koordinaten Player-Zielfeld if pgs[np[1]][np[0]]!="#": # kein Wall auf dem Player-Zielfeld if hlp.ppackt(np) not in pgd: # und keine Box auf dem Player-Zielfeld bp=hlp.ppack(pp[0]+self.ix[d], pp[1]+self.iy[d]) # Koordinaten Box-Startfeld if bp in pgd: # ziehbare Box am Player-Startfeld pgd.remove(bp) pgd.append(hlp.ppackt(pp)) return((2, np)) else: return((1, np)) return((0, pp))
def findBestPushTrackTo(self, pgs, dof, pgdp, pp, box_from, box_to): bfp=hlp.ppack(box_from[0], box_from[1]) btp=hlp.ppack(box_to[0], box_to[1]) if bfp not in pgdp: # wenn auf der StartPos box_from keine Box steht... return(1, "") # ...dann kommen wir hier nicht weiter if pgs[box_to[1]][box_to[0]]=="#" or btp in pgdp: # wenn die ZielPos box_to nicht frei ist... return(2, "") # ...dann kommen wir hier nicht weiter # Hier wird eine Kopie des statischen Spielfeldes erzeugt, in der alle Boxen ausser # der zu schiebenden Box box_from als Walls enthalten sind. pgst=[] for y in range(len(pgs)): ln=[] for x in range(len(pgs[y])): c=pgs[y][x] if hlp.ppack(x, y) in pgdp: if box_from!=(x, y): c="#" ln.append(c) pgst.append(ln) queue=deque([]) visited={} for d in range(4): if pgst[pp[1]+self.my[d]][pp[0]+self.mx[d]]!="#": queue.append((bfp, pp, d, "")) # (BoxPosPacked, PlayerPos, Schieberichtung, Bewegungsstring) visited.update({(bfp, pp, d):1}) # (BoxPosPacked, PlayerPos, Schieberichtung) pushed=False while queue: pgdp, pp, d, ks=queue.popleft() pgdpl=[pgdp] rc, ms, pp, bp, isdead=self.movePlayer(pgst, dof, pgdpl, pp, d) pgdp=pgdpl[0] # ggf. geänderte BoxPos holen if rc==2: pushed=True if btp==pgdp: # wenn Box das Zielfeld erreicht hat... return(0, ks+ms) # ...fertig if rc!=0: # wenn der movePlayer einen legalen Zug meldet... for d in range(4): # ...alle vier möglichen Folgezüge... if (pgdp, pp, d) not in visited: # ...testen, ob sie schon probiert wurden... if pgst[pp[1]+self.my[d]][pp[0]+self.mx[d]]!="#": # ...und legal sind... queue.append((pgdp, pp, d, ks+ms)) # ...wenn ja, dann zum weiteren Testen auf die Queue visited.update({(pgdp, pp, d):1}) if pushed==False: return(4, "") return(5, "")
def execute(self, data, output=True, reverse=False, very_verbose=False): """ Just wrapper around algorithm logic, why such redirection? try it out it will be fun... """ self.log("{0} >> Before Sorting : {1}".format(self.__addon__(), data), output) self.log(Helper.insert_separator(), very_verbose) self.logic(data, output, reverse, very_verbose) self.log(Helper.insert_separator(), very_verbose) self.log("{0} >> After Sorting : {1}".format(self.__addon__(), data), output) self.log("{0} >> Total Loop Count : {1}".format(self.__addon__(), self.loop_count), output)
def refineTokens(data, debug = False, force = True): #find all .tokens.json files files = Helper.derivedFiles(Helper.relevantFiles(data['data']), inputFileExt) if (not force): files = Helper.disregardFiles(files, inputFileExt, outputFileExt) for file in files: tokenized = Tokenization.tokenizeFile(file) if (debug): json.dump(tokenized, open(file.replace(inputFileExt, outputDebugFileExt), 'w')) map = createMap(tokenized) json.dump(map, open(file.replace('.tokens.json', outputFileExt), 'w')) Helper.incProgress() print ''
def findProteinsOrthologyOnlyByDomains(proteinsA, proteinsB, pairsDomains, pairsFull, taxidA, taxidB, cutoff): only = [] other = [] #other contains accession ids of proteins that have no orthology but at least one domain of them has tsvA = Helper.initTsvForOrganism(taxidA) tsvB = Helper.initTsvForOrganism(taxidB) for pair in pairsDomains: if pair not in pairsFull: amount = min(len(tsvA[pair.first]), len(tsvB[pair.second])) if pairsDomains[pair] >= amount: only.append(pair) other.append(pair) return only
def didClickSubmitButton(self, event): print(self.imageFilePath) img = img_as_ubyte(io.imread(CLUSTER_IMAGE_FILENAME)) roi_img = spectral_roi.extract_roi(img, gui_checkbox_handlers.getSelectedClusters()) roi_img_filename = "{}.png".format(Helper.generate_random_id()) io.imsave(roi_img_filename, roi_img) Display.show_image(roi_img, roi_img_filename)
def run(self): CONS = 4 primes = [2, 3, 5, 7, 11, 13, 17, 19] n = 19 consecutive = 0 # Counting up while True: n = n + 1 if Helper.isPrime(n): primes.append(n) consecutive = 0 continue # loop through primes count = 0 #ps = [] for p in primes: if n % p == 0: count = count + 1 #ps.append(p) if count == CONS: #print('at n=' + str(n) + ' with consecutive: ' + str(consecutive)) consecutive = consecutive + 1 #print(ps) break if count != CONS: # We didn't find distinct prime factors... consecutive = 0 if consecutive == CONS: print(n) return
def __finalizeDegreeOfFreedom(self, pgs, dof, pgdp, pp): rlst=[] floors, bList=self.__findReachableBoxes(pgs, pgdp, pp) for b in bList: # über alle erreichbaren Boxen bx, by=hlp.punpack(b) dof[by][bx]&=0x10FF for r in range(4): # über alle Schiebe-Koordinaten x=bx+self.rp[r][0] y=by+self.rp[r][1] # Player-Pos für aktuelle Schiebe-Richtung xyp=hlp.ppack(x, y) if xyp in floors: # wenn Player-Pos innerhalb der erreichbaren Felder... # rlst.append(((bx, by), self.sr[r])) # dof[by][bx]|=self.sm[r] dof[by][bx]|=(self.sm[r] & ((dof[by][bx]&0x00F0)<<4))
def start(): check , message = Helper.check_connection() if check: return True else: Dict['warning'].append(message) return False
def run(self): print('Caching primes...') # NOTE: This is slow right now... To speed this up, I guess I should check if it's cyclical # while calculating the primes primes = Helper.primesLessThan(1000000) print('Finding cyclical primes...') count = 0 iterations = 0 for prime in primes: if prime == 1: continue iterations = iterations + 1 if iterations % 10000 == 0: print("I'm up to: " + str(prime)) if primes[prime]: next_prime = self.cycle(prime) is_circular = True counter = 0 while int(next_prime) != prime: counter = counter + 1 if counter > 1000: print('I seem to be stuck:') print(prime) print(next_prime) if not primes[int(next_prime)]: is_circular = False next_prime = self.cycle(next_prime) if is_circular: count = count + 1 print(count)
from packages import Paste from pubsublogger import publisher from packages import lib_words import os import Helper if __name__ == "__main__": publisher.port = 6380 publisher.channel = "Script" config_section = 'PubSub_Words' config_channel = 'channel_0' subscriber_name = "curve" h = Helper.Redis_Queues(config_section, config_channel, subscriber_name) # Subscriber h.zmq_sub(config_section) # REDIS # r_serv1 = redis.StrictRedis( host=h.config.get("Redis_Level_DB", "host"), port=h.config.get("Redis_Level_DB", "port"), db=h.config.get("Redis_Level_DB", "db")) # FUNCTIONS # publisher.info("Script Curve subscribed to {}".format(h.sub_channel)) # FILE CURVE SECTION # csv_path = os.path.join(os.environ['AIL_HOME'],
def importPlayground(self, lines): minspc, maxlen = self.__getPlaygroundSize(lines) self.pg_stat = [ ] # das statische Spielfeld als Matrix (Zeichenvorrat: "#", " ", ".", "u", "i", "_") self.pg_schk = [ ] # wie pg_stat, allerdings nur mit dem Zeichenvorrat "Hindernis" ("#") und "überquerbar" (" ") self.pg_zfl = [] # Koordinaten-Liste der Zielfelder self.pg_dynp = [ ] # das dynamische Spielfeld als gepackte Koordinaten-Liste von Boxen self.playerpos = () # die Koordinaten der Spielfigur self.size = () # die Abmessungen des Spielfeldes (breite, höhe) lines_new = [] y = 0 for l in lines: # über alle Zeilen ln = [] x = 0 l += " " * maxlen # Zeilen verlängern lines_new.append(l[minspc:maxlen].rstrip()) for c in l[minspc:maxlen]: # über alle Spalten der jew. Zeile # Zeile als Liste von Characters aufbauen if c in ("#", " ", "."): # Mauer, Boden, Zielfeld ln.append(c) if c in ("*", "+"): # Box/Spielfigur auf Zielfeld ln.append(".") self.pg_zfl.append((x, y)) if c == ".": # Zielfeld self.pg_zfl.append((x, y)) if c in ("@", "$"): # Spielfigur oder Box ln.append(" ") if c in ("@", "+"): # Spielfigur [auf Zielfeld] self.playerpos = (x, y) if c in ("$", "*"): # Box [auf Zielfeld] self.pg_dynp.append(hlp.ppack(x, y)) x += 1 self.pg_stat.append(ln) y += 1 self.size = (x, y) self.__markUnreachableFloors() gf = SokoGoodFloors.SokoGoodFloors(self.pg_stat, self.pg_dynp, self.pg_zfl, self.playerpos) goodfloors = gf.findGoodFloors() # Spielfeld in ein weiteres kopieren, das nur Walls und Floors enthält. # Zusätzlich noch badFloors im Haupt-Spielfeld markieren. for y in range(self.size[1]): ln = [] for x in range(self.size[0]): if self.pg_stat[y][x] in ("#", "i", "u"): ln.append("#") else: ln.append(" ") if self.pg_stat[y][x] == " " and ( x, y ) not in goodfloors: # wenn Floor und nicht guter Floor... if hlp.ppack( x, y ) not in self.pg_dynp: # ...und initial keine Box drauf steht... self.pg_stat[y][ x] = "_" # ...dann als badFloor markieren self.pg_schk.append(ln) self.pg_dof = self.degreeOfFreedom(self.pg_stat, self.size) # for y in range(len(self.pg_dof)): # ln=[] # for x in range(len(self.pg_dof[y])): # ln.append("{0:09b}".format(self.pg_dof[y][x])) # print ln self.pg_dynp.sort() return (self.pg_stat, self.pg_schk, self.pg_dof, self.size, self.pg_dynp, self.pg_zfl, self.playerpos, lines_new)
def _parse_call(self, call_cexpr, arg_cexpr, offset): _, tinfo = Helper.get_func_argument_info(call_cexpr, arg_cexpr) if tinfo: return self.__deref_tinfo(tinfo) # TODO: Find example with UTF-16 strings return Const.CHAR_TINFO
def __repr__(self): return "{} : {}".format(self.name, Helper.to_hex(self.expression_address))
def __init__(self): self.localboughtscache = [] self.config = Helper.Config() self.sequencialbuys = int(self.config.sequencialbuying)
def get_models(): #setup cost function for fitting #realmin = np.finfo(np.double).tiny #smallest possible floating point number cost = lambda y, h: -np.sum( y * np.log(np.max([h, np.ones(len(h)) * realmin], axis=0)) + (1 - y) * np.log(np.max([1 - h, np.ones(len(h)) * realmin], axis=0))) #get information about singleton prior in flat log odds trialset flatlo = Helper.getFlatLOTrialset() pcs = flatlo['pcs'] pcs_var = pcs * (1 - pcs) #setup gaussian approximate number model from Dehaene 2007, single scaling factor and intercept #2 parameter dm_onescale = lambda w, data: 1 - scipy.stats.norm( w[0] + data['augend'] + data['addend'] - data['singleton'], w[1] * np. sqrt(data['augend']**2. + data['addend']**2 + data['singleton']**2 )).cdf(0) #Full Dehaene 2007, separate scaling factor for each group #3 parameters dm_sd = lambda w, data: np.sqrt((w[0]**2) * data['augend']**2 + (w[1]**2) * data['addend']**2 + (w[2]**2) * data['singleton']**2) dm_noweight = lambda w, data: 1 - scipy.stats.norm( data['augend'] + data['addend'] - data['singleton'], dm_sd(w, data) ).cdf(0) dm_var_nonlinear = lambda w, data: np.power( (w[0]**(1.0 / w[3])) * data['augend']**2 + (w[1]**(1.0 / w[3])) * data['addend']**2 + (w[2]**(1.0 / w[3])) * data['singleton']**2, w[3]) # dm_var_nonlinear = lambda w,data: np.power((w[0])*data['augend']**2 # + (w[1])*data['addend']**2 + (w[2])*data['singleton']**2,np.exp(w[3])) dm_full_nonlinear = lambda w, data: 1 - scipy.stats.norm( w[0] + w[1] * data['augend'] + w[2] * data['addend'] - w[3] * data[ 'singleton'], np.sqrt(dm_var_nonlinear(w[4:], data))).cdf(0) #Dehaene model w/ one scaling factor, and separate weight for each element of prior. #Meant for FlatLO experiment only. #13 parameters dm_prior_weighting = lambda w,data: (1-w[data['singleton']])*dm_onescale(w[[0,1]],data) \ + w[data['singleton']+1]*pcs[data['singleton']-1] logistic = lambda x: 1. / (1. + np.exp(-x)) #Dehaene model plus prior w/ optimal weighting of each #3 parameters weightfun = lambda w, data: dm_sd(w, data) / (dm_sd(w, data) + pcs_var[ data['singleton'] - 1]) dm_prior_optimal = lambda w, data: (1 - weightfun(w, data)) * dm_noweight( w, data) + weightfun(w, data) * pcs[data['singleton'] - 1] #Linear addition model. #4 parameters linear = lambda w, data: logistic(w[0] + w[1] * data['augend'] + w[ 2] * data['addend'] + w[3] * data['singleton']) #Average of the difference and the prior's predictions, weighted by the ratio of sum and singleton. #2 parameters ratiofun = lambda data: data[['sum', 'singleton']].min(axis=1) / data[ ['sum', 'singleton']].max(axis=1) weighted_diff_singprior = lambda w, data: logistic(w[0] + (1 - ratiofun( data) * w[1]) * (data['sum'] - data['singleton']) + ratiofun(data) * w[ 1] * data['sing_prior']) #2 parameters norm_coef = lambda w, q1, q2: 1.0 / (1.0 + w[0] * np.power( np.power(np.abs(q1, dtype='float64'), w[1]) + np.power( np.abs(q2, dtype='float64'), w[1]), (1.0 / w[1]))) livingstone_norm = lambda w, data: logistic(w[2] * ( norm_coef(w[0:2], data['addend'], data['singleton']) * data['augend'] + norm_coef(w[0:2], data['augend'], data['singleton']) * data['addend'] - norm_coef(w[0:2], data['augend'], data['addend']) * data['singleton'])) #a model in which the ratio of the sum and singleton are compared. #coefficients are on the aug,add,sing prior to log transform. #4 parameters logarithmic = lambda w, data: logistic(w[0] + np.log(w[1] * data[ 'augend'] + w[2] * data['addend']) - np.log(w[3] * data['singleton'])) #a model in which the ratio of the sum and singleton are compared. #coefficients are on the log of the sum and singleton. #4 parameters logarithmic2 = lambda w, data: logistic(w[0] + w[1] * np.log(data[ 'augend'] + data['addend']) - w[2] * np.log(data['singleton'])) #a model where the log of the aug, add, sing are combined #4 parameters log_aas = lambda w, data: logistic(w[0] + w[1] * np.log(data[ 'augend']) + w[2] * np.log(data['addend']) + w[3] * np.log(data[ 'singleton'])) #a model where the power of the augend, addend, and singleton are free parameters #7 free parameters power = lambda w, data: logistic(w[0] + w[1] * data['augend']**w[4] + w[ 2] * np.abs(data['addend'])**w[5] + w[3] * data['singleton']**w[6]) models = { 'cost': cost, 'dm_onescale': dm_onescale, 'dm_noweight': dm_noweight, 'dm_full_nonlinear': dm_full_nonlinear, 'dm_prior_weighting': dm_prior_weighting, 'linear': linear, 'dm_prior_optimal': dm_prior_optimal, 'weightfun': weightfun, 'weighted_diff_singprior': weighted_diff_singprior, 'livingstone_norm': livingstone_norm, 'logarithmic': logarithmic, 'logarithmic2': logarithmic2, 'log_aas': log_aas, 'power': power } return models
"parse_output_mtag", s + 1) call = "java -cp ../mate/anna-3.61.jar is2.%s -model %s -test %s -out %s" % ( "mtag.Tagger", "../mate/morphology-ger-3.6.model", input_file, output_file) print call subprocess.call([call], shell=True) if i == 3: # do parsing # java -cp anna-3.61.jar is2.parser.Parser -model parser-ger-3.6.model -test test2.output -out test4.output for s in range(num_files): input_file = self.settings['parse_dir'] + "%s%s" % ( "parse_output_mtag", s + 1) output_file = self.settings['parse_dir'] + "%s%s" % ( "parse_output_parse", s + 1) call = "java -cp ../mate/anna-3.61.jar is2.%s -model %s -test %s -out %s" % ( "parser.Parser", " ../mate/parser-ger-3.6.model", input_file, output_file) print call subprocess.call([call], shell=True) Helper.prep_parse_files = prep_parse_files Helper.parse_pipeline = parse_pipeline Helper.prep_parse_files2 = prep_parse_files2 if __name__ == '__main__': H = Helper() H.prep_parse_files2('../data/test_data') #H.parse_pipeline([0, 1, 2, 3], 1) #H.parse_pipeline([0], 1)
# load whole environment targetPos = [41, 0.0, 1.25] env = Env(robotId, targetPos) env.setMotorName(motorName) env.addBonusBlock() plan = RobotControl.generateTraj(env.robotId) # print infomation for all the joints for jointId in range(p.getNumJoints(env.robotId)): print(p.getJointInfo(env.robotId, jointId)) p.enableJointForceTorqueSensor(env.robotId, jointId, 1) if recordVideo: videoFile = Helper.findLog(prefix + '.mp4') videoLogId = p.startStateLogging(p.STATE_LOGGING_VIDEO_MP4, videoFile) t = 0 while True: p.stepSimulation() time.sleep(1 / 240) controlSignal = RobotControl.realTimeControl(env.robotId, plan) env.control(controlSignal) env.cameraControl() RobotControl.addDebugItems(env.robotId) env.checkBonus() t += 1 / 240
cur = conn.cursor() tests = [] #list to store output of tests #==============================================EXP1 ############### description1 = 'one-sample t-test on sum - singleton coef in logistic regression' query1 = ''' SELECT augend,addend,singleton,augend+addend-singleton as diff, chose_sum,session,trial,trialset,animal FROM behavioralstudy WHERE experiment='Addition' ORDER BY animal,session,trial ''' data1 = Helper.getData(cur,query1) model1 = 'chose_sum ~ diff' mout1 = Analyzer.logistic_regression(data1,model1,groupby=['animal','session']) t1_x = scipy.stats.ttest_1samp(mout1['b_diff'].loc[mout1['animal']=='Xavier'],0) n1_x = len(mout1['b_diff'].loc[mout1['animal']=='Xavier']) t1_r = scipy.stats.ttest_1samp(mout1['b_diff'].loc[mout1['animal']=='Ruffio'],0) n1_r = len(mout1['b_diff'].loc[mout1['animal']=='Ruffio']) tests.append({'description':description1+'(Xavier)','p':t1_x.pvalue,'stat':t1_x.statistic, 'mean':np.mean(mout1['b_diff'].loc[mout1['animal']=='Xavier']),'n':n1_x,'df':n1_x-1}) tests.append({'description':description1+'(Ruffio)','p':t1_r.pvalue,'stat':t1_r.statistic, 'mean':np.mean(mout1['b_diff'].loc[mout1['animal']=='Ruffio']),'n':n1_r,'df':n1_r-1}) ############### description2 = 't-test on set 1 vs. set 2 accuracy for both animals' query2 = '''
def __init__(self): self.config = Helper.Config() # Pro realtimepricepolicy navyšuju offset o 0.5%. self.priceoffset = - float(self.config.pricePolicyOffset + 0.5) self.tops = [] self.currentticker = None
cv2.rectangle(img, (x, y), (x + w, y + h), (225, 0, 0), 1) ids, conf = recognizer.predict(gray_face) print('confidence' + str(round(conf, 2))) c.execute("select name from users where id = (?);", (ids, )) result = c.fetchall() name = result[0][0] # Determine the ID of the photo if (conf < 2): output = name else: output = "Unknown" cv2.putText(img, str(output), (x - 50, h), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), lineType=cv2.LINE_AA) cv2.putText(img, str(round(conf, 2)), (x + 90, h - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), lineType=cv2.LINE_AA) Helper.DispID(x, y, w, h, name, gray) cv2.imshow('Face Recognizer', img) k = cv2.waitKey(30) & 0xff if k == 27: break cap.release() cv2.destroyAllWindows()
if raw_sentences_fn == None: raw_sentences_fn = self.raw_sentences_fn with open(raw_sentences_fn, 'r') as f: sentences = f.read().split("\n") ooved_sentences = ''; for line_num in range(num_sentences): en_words = set() grammar = self.get_grammar(line_num, grammar_base_fn) for rule in grammar: if rule == "": continue parts = rule.split(" ||| ") english = parts[1].split(" ") for word in english: en_words.add(word) # Replace all the unknown words with OOV and add the OOV'ed line to ooved_lines replace_oov = lambda word: word if word in en_words else self.OOV ooved_words = map(replace_oov, sentences[line_num].split(" ")) ooved_sentences += " ".join(ooved_words) + "\n" with open(self.sentences_fn, 'w') as f: f.write(ooved_sentences) # Add to helper class Helper.preprocess_oov = preprocess_oov if __name__ == '__main__': H = Helper(type="all-monotone") H.preprocess_oov('../data/dev.en')
env = Env() # load your robot here robotId = RobotControl.load() env.robotId = robotId # print joint info for jointId in range(p.getNumJoints(robotId)): print(p.getJointInfo(robotId, jointId)) # add your debug items RobotControl.addDebugItems(robotId) if recordVideo: # videoFile = os.path.join('project', 'proj2_baseball', 'log', prefix+'.mp4') videoFile = Helper.findLog(prefix + '.mp4') videoLogId = p.startStateLogging(p.STATE_LOGGING_VIDEO_MP4, videoFile) # Loop over 4 tests for i in [1, 2, 4, 8]: # reset your robot for jointId in range(p.getNumJoints(robotId)): p.resetJointState(robotId, jointId, 0) # init the baseball and avoid collision between baseball and the base of the robot arm env.addBaseball() # get random target env.setTarget(i) # generate trajectory with your function, env.randPos is the position of baseball and env.randTarget is the target position
def check_member_assignment(self, expression, index): """ We are now in cexpr_t == idaapi.cot_var. This function checks if expression is part of member assignment statement. Returns None if not. :param expression: idaapi.cexpr_t :param index: int :return: Structures.AbstractField """ parents_type = map(lambda x: idaapi.get_ctype_name(x.cexpr.op), list(self.parents)[:0:-1]) parents = map(lambda x: x.cexpr, list(self.parents)[:0:-1]) for parent in parents: if parent.ea != idaapi.BADADDR: self.expression_address = parent.ea break else: self.expression_address = idaapi.BADADDR offset = 0 if parents_type[0:2] == ['asg', 'expr']: if parents[0].y == expression: # Assignment like (v1 = v2) where v2 is scanned variable if parents[0].x.op == idaapi.cot_var: self.add_variable(parents[0].x.v.idx) else: # if expression is (var = something), we have to explore whether continue to scan this variable or not if parents[0].y.op != idaapi.cot_num: if parents[0].y.op == idaapi.cot_call: # Check if expression: var = function((TYPE) var, ...) or var = function(var, ...) args = parents[0].y.a if args and ( ( args[0].op == idaapi.cot_cast and args[0].x.op == idaapi.cot_var and args[0].x.v.idx == index ) or ( args[0].op == idaapi.cot_var and args[0].v.idx == index ) ): return try: self.protected_variables.remove(index) except KeyError: print "[Info] Remove variable {0} from scan list, address: 0x{1:08X}".format( index, self.expression_address ) self.variables.pop(index) return # Assignment like v1 = (TYPE) v2 where TYPE is one the supported types elif parents_type[0:3] == ['cast', 'asg', 'expr']: if parents[1].x.op == idaapi.cot_var: if filter(lambda x: x.equals_to(parents[0].type), Const.LEGAL_TYPES): self.add_variable(parents[1].x.v.idx) return # Universal call with no cast conversion and offsets: call(..., this, ...) if parents_type[0] == 'call': arg_index, _ = Helper.get_func_argument_info(parents[0], expression) if SCAN_ALL_ARGUMENTS or not arg_index: self.scan_function(parents[0].x.obj_ea, 0, arg_index) return # -------------------------------------------------------------------------------------------- # When variable is DWORD, int, __int64 etc # -------------------------------------------------------------------------------------------- elif self.variables[index].equals_to(Const.X_WORD_TINFO): if parents_type[0:2] == ['add', 'cast']: if parents[0].theother(expression).op != idaapi.cot_num: return offset = parents[0].theother(expression).numval() if parents_type[2] == 'ptr': if parents_type[3] == 'asg' and parents[3].x == parents[2]: # *(TYPE *)(var + x) = ??? return self.get_member( offset, index, object=parents[3].y, default=parents[1].type.get_pointed_object() ) return self.create_member(offset, index, parents[1].type.get_pointed_object()) elif parents_type[2] == 'call': # call(..., (TYPE)(var + x), ...) if parents[0].theother(expression).op != idaapi.cot_num: return offset = parents[0].theother(expression).numval() return self.get_member(offset, index, call=parents[2], arg=parents[1]) elif parents_type[2] == 'asg': # other_var = (LEGAL TYPE) (var + offset) if parents[2].y == parents[1] and parents[2].x.op == idaapi.cot_var: if filter(lambda x: x.equals_to(parents[1].type), Const.LEGAL_TYPES): self.scan_function(self.function.entry_ea, offset, parents[2].x.v.idx) return cast_type = parents[1].type if cast_type.is_ptr(): return self.create_member(offset, index, cast_type.get_pointed_object()) elif parents_type[0:2] == ['cast', 'ptr']: if parents_type[2] == 'asg' and parents[2].x == parents[1]: # *(TYPE *)var = ??? return self.get_member(0, index, object=parents[2].y, default=parents[0].type.get_pointed_object()) return self.create_member(0, index, parents[0].type.get_pointed_object()) elif parents_type[0:2] == ['cast', 'call']: # call(..., (TYPE)(var + x), ...) return self.get_member(0, index, call=parents[1], arg=parents[0]) elif parents_type[0] == 'add': # call(..., var + x, ...) if parents[0].theother(expression).op != idaapi.cot_num: return offset = parents[0].theother(expression).numval() if parents_type[1] == 'call': return self.get_member(offset, index, call=parents[1], arg=parents[0]) elif parents_type[1] == 'asg': if parents[1].y == parents[0] and parents[1].x.op == idaapi.cot_var: self.scan_function(self.function.entry_ea, offset, parents[1].x.v.idx) # -------------------------------------------------------------------------------------------- # When variable is void *, PVOID, DWORD *, QWORD * etc # -------------------------------------------------------------------------------------------- else: # print "[DEBUG] D* Parents:", parents_type offset = 0 if parents_type[0] == 'idx': if parents[0].y.op != idaapi.cot_num: # There's no way to handle with dynamic offset return None offset = parents[0].y.numval() * self.variables[index].get_ptrarr_objsize() if parents_type[1] == 'asg' and parents[1].x == parents[0]: # var[idx] = ??? return self.get_member( offset, index, object=parents[1].y, default=self.variables[index].get_pointed_object() ) elif parents_type[1] == 'cast': # (TYPE) var[idx] return self.create_member(offset, index, parents[1].type) return self.create_member(offset, index, Const.X_WORD_TINFO) elif parents_type[0:2] == ['ptr', 'asg']: # *var = ??? return self.get_member( 0, index, object=parents[1].y, default=self.variables[index].get_pointed_object() ) else: if parents_type[0:2] == ['cast', 'ptr']: if parents_type[2] == 'call': # call(..., *(TYPE *) var, ...) return self.get_member(0, index, call=parents[2], arg=parents[1]) elif parents_type[2] == 'asg' and parents[2].x == parents[1]: # *(TYPE *) var = ??? return self.get_member( 0, index, object=parents[2].y, default=parents[0].type.get_pointed_object() ) elif parents_type[0:2] == ['cast', 'add']: if parents[1].theother(parents[0]).op != idaapi.cot_num: return None offset = parents[1].theother(parents[0]).numval() offset *= parents[0].type.get_ptrarr_objsize() if parents[0].type.is_ptr() else 1 if parents_type[2] == 'ptr': if parents_type[3] == 'asg' and parents[3].x == parents[2]: # *((TYPE *)var + x) = ??? return self.get_member( offset, index, object=parents[3].y, default=parents[0].type.get_pointed_object() ) return self.create_member(offset, index, parents[0].type.get_pointed_object()) elif parents_type[2] == 'call': # call(..., (TYPE)var + offset, ...) return self.get_member(offset, index, call=parents[2], arg=parents[1]) elif parents_type[2] == 'cast' and parents[2].type.is_ptr(): # (TYPE *) ((TYPE *)var + x) return self.create_member(offset, index, parents[2].type.get_pointed_object()) elif parents_type[0:2] == ['add', 'cast']: if parents[0].theother(expression).op != idaapi.cot_num: return None offset = parents[0].theother(expression).numval() * self.variables[index].get_ptrarr_objsize() if parents_type[2] == 'call': # call(..., (TYPE)(var + x), ...) return self.get_member(offset, index, call=parents[2], arg=parents[1]) elif parents_type[2] == 'asg': if parents[2].y == parents[1] and parents[2].x.op == idaapi.cot_var: if filter(lambda x: x.equals_to(parents[1].type), Const.LEGAL_TYPES): self.scan_function(self.function.entry_ea, offset, parents[2].x.v.idx) return else: return self.create_member(offset, index, parents[1].type.get_pointed_object()) elif parents_type[0] == 'add': # call(..., var + offset, ...) if parents[0].theother(expression).op != idaapi.cot_num: return None offset = parents[0].theother(expression).numval() * self.variables[index].get_ptrarr_objsize() if parents_type[1] == 'call': return self.get_member(offset, index, call=parents[1], arg=parents[0]) if parents_type[1] == 'asg': # other_var = var + offset if parents[1].y == parents[0] and parents[1].x.op == idaapi.cot_var: self.scan_function(self.function.entry_ea, offset, parents[1].x.v.idx) return elif parents_type[0:2] == ['cast', 'call']: # call(..., (TYPE) var, ...) return self.get_member(0, index, call=parents[1], arg=parents[0]) elif parents_type[0] == 'ptr': if parents_type[1] == 'cast': # (TYPE) *var return self.create_member(0, index, parents[0].type) # *var return self.create_member(0, index, self.variables[index].get_pointed_object()) if 'return' not in parents_type[0:2] and parents_type[0] not in ('if', 'band', 'eq', 'ne', 'cast'): print "[DEBUG] Unhandled type", self.variables[index].dstr(), \ "Index:", index, \ "Offset:", offset, \ "Function:", idaapi.get_ea_name(self.function.entry_ea), \ "Address: 0x{0:08X}".format(expression.ea), \ "Parents:", parents_type
'id': item }).find('a', { 'class': 'post-list-item-title-link' }).attrs['href'] # Получаем информацию о стоимости на статью данного блока for i in soup.find('article', { 'class': 'post-list-item', 'id': item }).find_all('p'): if i.getText() is not None: if 'стоимость' in i.getText().lower(): rink_ticket_cost = i.getText() break # Получаем дополниельную информацию из каждой статьи info = Helper.GetInfo(home_url + link, rink_ticket_cost) if info is not None: # Если пользователь ввел 0 , то возвращаем всю информацию о катках if int(weekday) == 0: rinks_info.append(info) # Если пользователь ввел число !=0 , то ищем катки , которые работают в определенный день else: if info[6].get(int(weekday)) is not None: rinks_info.append(info) df = pd.DataFrame(rinks_info) df.columns = [ 'url', 'title', 'description', 'address', 'phone', 'schedule', 'normalized_schedule', 'cost' ]
def writeData(self): try: helper.writeToFile(self.data,self.config['File_Name']['datafile']) except Exception as e: log.error(str(e))
def to_list(self): """ Creates list that is acceptable to MyChoose2 viewer """ return [ "0x{0:04X}".format(self.origin), self.function_name, self.name, Helper.to_hex(self.expression_address) ]
def from_dict_to_sorted_list(players): parts = Helper.from_dict_to_list(players) return sorted(parts, key=by_value, reverse=True)
def __init__(self, cfunc, origin, obj, temporary_structure): super(DeepReturnVisitor, self).__init__(cfunc, origin, obj, temporary_structure) self.__callers_ea = Helper.get_funcs_calling_address(cfunc.entry_ea) self.__call_obj = obj
def divide_teams_smart(players): parts = from_dict_to_sorted_list(players) return fill_teams(Helper.from_dict_to_list(players), [], [], 0)
def apply_type(self, tinfo): if self._applicable: logger.warn( "Changing type of structure field is not yet implemented. Address - {}" .format(Helper.to_hex(self.expression_address)))
'captureHeaders': 'true', 'captureContent': 'true' }) driver.get("https://www.google.co.in") element = driver.find_element_by_xpath('//*[@id="lst-ib"]') element.send_keys('datalicious') element.send_keys(Keys.ENTER) try: WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "resultStats"))) driver.find_element_by_xpath( ".//*[@id='rso']/div[1]/div/div[1]/div/div/h3/a").click() print("Task 1 Completed") except TimeoutException: print("It is taking more time") time.sleep(15) server.stop() answer = proxy.har requiredParameters = Helper.DataHelper().getRequiredDataFrom(answer) with open('dict.csv', 'w') as csv_file: writer = csv.writer(csv_file) for key, value in requiredParameters.items(): writer.writerow([key, value]) print("Task 3 Completed") driver.quit()
clf1.fit(X_train, np.ravel(y_train)) #Prediction des Subsets von "Test"-Trainingsdaten mit clf1 prediction_clf1 = pd.DataFrame(clf1.predict(X_test)) prediction_clf1 = prediction_clf1.set_index(X_test.index) prediction_clf1.columns = ['Predictions'] prediction_clf1_solution = pd.concat([X_test, prediction_clf1, y_test], axis=1, join_axes=[X_test.index]) print("Prediction using svr (clf1): ") print(prediction_clf1_solution) ###Berechnung des Prediktion-Errors error_clf1 = clf1.score(X_train, y_train) print("R^2 of svr (clf1) on training data: ", error_clf1) errorFunction_clf1 = hlpr.errorFunction(prediction_clf1, y_test) print("Error-Function of svr (clf1) on test data: ", errorFunction_clf1) errorUsingMedian = hlpr.errorFunction( [np.mean(y_test) for i in range(0, len(y_test))], y_test) print("Error-Function of always predicting mean: ", errorUsingMedian) # Predictions von Test-Set in .csv schreiben prediction_clf1_solution = prediction_clf1_solution[[ 'Feinheit', 'Predictions' ]] if (file == "SnapZero.csv"): prediction_clf1_solution.to_csv("SVRSnapZeroResults.csv") if (file == "SnapLag.csv"): prediction_clf1_solution.to_csv("SVRSnapLagResults.csv") if (file == "TimeSeriesCharac.csv"): prediction_clf1_solution.to_csv("SVRTimeSeriesCharacResults.csv")
def Cleanup(interfaceParams): # Detect and Remove BMC Hang return Helper.DetectAndRemoveBmcHang(interfaceParams)
APPOSITION = "NP=n1 < (NP=n2 $.. (/,/ $.. NP=n3))" parser = StanfordParser(model_path="edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz") def getParserTree(line): ''' return parse tree of the string :param line: string :return: list of tree nodes ''' return list(parser.raw_parse(line)) def getAppositions(tree): url = "http://localhost:9000/tregex" request_params = {"pattern": "NP=n1 < (NP=n2 $.. (/,/ $.. NP=n3))"} r = requests.post(url, data=text, params=request_params) js = r.json() if js['sentences'][0] and '0' in js['sentences'][0] and 'namedNodes' in js['sentences'][0]['0']: return js['sentences'][0]['0']['namedNodes'] return None text = 'Harry Potter, a young boy, is very famous in US' testTree = Helper.getParserTree(text) res = getAppositions(testTree) print 'result',res # print one by one if res: for c in res: print c
# Task 6 from Helper import * import task2 import task3 import task4 if __name__ == '__main__': # We only need to update the helper and can then reuse most of the code H = Helper(type="all-lattice") # First, generate new phrase tables H.generate_phrase_table_fsts() # And combine those with the inputs lattices. H.generate_translation_fsts() # Then get the best derivations H.generate_best_derivations_fsts() # Dump the final translations # To get the bleus score, simply run # ./multi-bleu.perl dev.ja < monotone-translations.map # ./multi-bleu.perl dev.ja < monotone-translations.viterbi # ./multi-bleu.perl dev.ja < lattice-translations.map # ./multi-bleu.perl dev.ja < lattice-translations.viterbi H.dump_translations() H.dump_bleu_scores()
def configureGNUCompiler(config): if config.env["RUN_ON_HAZELHEN"]: config.env["CC"] = 'CC' config.env["CXX"] = 'CC' config.env.Append(CPPPATH = [os.environ['BOOST_ROOT'] + '/include']) config.env.Append(LIBPATH = [os.environ['BOOST_ROOT'] + '/lib']) config.env.Append(CPPFLAGS=["-dynamic"]) config.env.Append(LINKFLAGS=["-dynamic"]) if config.env["COMPILER"] == "openmpi": config.env["CC"] = ("mpicc") config.env["LINK"] = ("mpicxx") config.env["CXX"] = ("mpicxx") Helper.printInfo("Using openmpi.") elif config.env["COMPILER"] == "mpich": if config.env["CC"]: config.env.Append(CFLAGS=["-cc=" + config.env["CC"]]) if config.env["CXX"]: config.env.Append(CPPFLAGS=["-cxx=" + config.env["CXX"]]) config.env.Append(LINKFLAGS=["-cxx=" + config.env["CXX"]]) config.env["CC"] = ("mpicc.mpich") config.env["LINK"] = ("mpicxx.mpich") config.env["CXX"] = ("mpicxx.mpich") Helper.printInfo("Using mpich.") versionString = getOutput([config.env["CXX"], "-dumpversion"]) if "." not in versionString: versionString = getOutput([config.env["CXX"], "-dumpfullversion"]) version = config.env._get_major_minor_revision(versionString) Helper.printInfo("Using {} {}".format(config.env["CXX"], versionString)) if not config.CheckExec(config.env["CXX"]) or not config.CheckExec(config.env["CC"]) or \ not config.CheckExec(config.env["LINK"]) : Helper.printErrorAndExit("Compiler executable not found!") if not config.CheckCompiler(): Helper.printErrorAndExit("Compiler found, but it is not working! (Hint: check flags)") allWarnings = \ "-Wall -Wextra \ -Wcast-qual -Wconversion -Wformat=2 \ -Wformat-nonliteral -Wformat-security -Winit-self \ -Wmissing-format-attribute \ -Wmissing-include-dirs -Wpacked \ -Wunreachable-code -Wunused \ -Wno-unused-parameter".split(" ") if not config.env['USE_HPX']: allWarnings.append(['-Wswitch-enum', '-Wredundant-decls', '-pedantic', '-Wswitch-default']) else: allWarnings.append(['-Wno-conversion', '-Wno-format-nonliteral']) # -fno-strict-aliasing: http://www.swig.org/Doc1.3/Java.html or # http://www.swig.org/Release/CHANGES, 03/02/2006 # "If you are going to use optimizations turned on with gcc > 4.0 (for example -O2), # ensure you also compile with -fno-strict-aliasing" config.env.Append(CPPFLAGS=allWarnings + [ "-fno-strict-aliasing", "-funroll-loops", "-mfpmath=sse"]) # if not config.env["USE_HPX"]: config.env.Append(CPPFLAGS=["-fopenmp"]) config.env.Append(LINKFLAGS=["-fopenmp"]) # # limit the number of errors display to something reasonable (useful for templated code) # config.env.Append(CPPFLAGS=["-fmax-errors=5"]) # required for profiling config.env.Append(CPPFLAGS=["-fno-omit-frame-pointer"]) # GCC has support for colored output since 4.9 if (version >= (4, 9, 0)) and Helper.terminalSupportsColors(): config.env.Append(CPPFLAGS=["-fdiagnostics-color=always"]) if config.env["BUILD_STATICLIB"]: config.env.Append(CPPFLAGS=["-D_BUILD_STATICLIB"]) if config.env["ARCH"] == "sse3": config.env.AppendUnique(CPPFLAGS=["-msse3"]) elif config.env["ARCH"] == "sse42": config.env.AppendUnique(CPPFLAGS=["-msse4.2"]) elif config.env["ARCH"] == "avx": config.env.AppendUnique(CPPFLAGS=["-mavx"]) elif config.env["ARCH"] == "fma4": config.env.AppendUnique(CPPFLAGS=["-mavx"]) config.env.AppendUnique(CPPFLAGS=["-mfma4"]) elif config.env["ARCH"] == "avx2": config.env.AppendUnique(CPPFLAGS=["-mavx2"]) config.env.AppendUnique(CPPFLAGS=["-mfma"]) elif config.env["ARCH"] == "avx512": config.env.AppendUnique(CPPFLAGS=["-mavx512f"]) config.env.AppendUnique(CPPFLAGS=["-mavx512cd"]) config.env.AppendUnique(CPPFLAGS=["-mfma"]) else: Helper.printErrorAndExit("You must specify a valid ARCH value for gnu.", "Available configurations are: sse3, sse42, avx, fma4, avx2, avx512") # check if using MinGW (g++ on win32) if config.env["PLATFORM"] == "win32": # disable warnings which occur when including Boost in the tests # note that definition of hypot is necessary for to the current version of # mingw (6.3) and the python interface (see http://stackoverflow.com/questions/10660524/error-building-boost-1-49-0-with-gcc-4-7-0) # -> could be removed in the future hopefully config.env.Append(CPPFLAGS=["-Wno-switch-enum", "-Wno-deprecated-declarations", "-D_hypot=hypot"]) # also use "lib" prefix on MinGW for consistency with Linux (default is no prefix) config.env["SHLIBPREFIX"] = "lib"
def __init__(self, path, bits_to_rewrite_count): self.Path = os.path.abspath(path) if not os.path.exists(self.Path): sys.exit('File does not exist!') if not os.path.isfile(self.Path): sys.exit(self.Path + ' - is not file!') try: image = open(path, 'rb') except Exception: sys.exit('Can not open file!') current_offset = 0 self.Head = b'' try: read = image.read(2) self.Type = read # sygnatura self.Head += read current_offset += 2 read = image.read(8) self.Head += read current_offset += 8 read = image.read(4) offset_bits = H.bytes_to_int(read) # shift to start of data self.Head += read current_offset += 4 except Exception: sys.exit('Wrong BitMapFileHeader!') try: read = image.read(4) self.Head += read current_offset += 4 read = image.read(4) self.Width = H.bytes_to_int(read) # Width self.Head += read current_offset += 4 read = image.read(4) self.Height = H.bytes_to_int(read) # height self.Head += read current_offset += 4 read = image.read(2) self.Head += read current_offset += 2 read = image.read(2) self.Bit_count = H.bytes_to_int(read) # color depth self.Head += read current_offset += 2 read = image.read(4) self.Head += read current_offset += 4 read = image.read(4) self.Size = H.bytes_to_int(read) # image size self.Head += read current_offset += 4 read = image.read(offset_bits - current_offset) self.Head += read current_offset += offset_bits - current_offset except Exception: sys.exit('Wrong BitMapInfoHeader!') try: self.Image_Data = image.read() except Exception: sys.exit('Wrong Image!') if self.Type != b'BM': sys.exit('Is not BMP image!') self.Bits_to_rewrite_count = bits_to_rewrite_count self.Volume = self.Size // (8 / bits_to_rewrite_count) * 3 image.close()
import GPoperators as op import initGlobal as init import InitPopMethods as initpop import Helper as hp import matplotlib.pyplot as plt # import os inGP = init.GP() pop = initpop.rampinit(5, inGP.maxSub, inGP.maxPat, inGP.maxBlue, 0.5) a = pop[0] m, n, t = hp.getChrom(a) a.tree.childs[1].valueofnode.plot() print(m) #a=op.crossover(pop,inGP.proRed,inGP.prosubBlue,inGP.proBlue,inGP.proSubstrate,inGP.proGensub,inGP.proGenpat) #hp.drawNodeIDs(pop[0].tree) #hp.drawNodeIDs(pop[4].tree) #a = pop[1].tree #hp.drawNodeIDs(a) #m = a.childs[1].valueofnode #hp.drawtree(a,r'C:\Opt_files\myfig') #m.plot() #plt.savefig(r'C:\Opt_files\myfig') #plt.show() [x, y, z] = hp.get_all_para_for_hfss(a.tree) #print(y) from genscript import genscript genscript(x, y, z, r'C:\Users\DELL\Desktop' + r'\test1.vbs', r'C:\Users\DELL\Desktop\test', r'C:\Users\DELL\Desktop' + r'\test.hfss')
def detect(self, fpImg, mskImg): """ Orientation Field Detection: estimate orientations of lines or ridges in an image :param fpImg: a fingerprint image (gray-scale) to estimate orientations in :param mskImg: a mask image (region-of-interest) :returns: An ndarray the same shape as the image, filled with an orientation angles in radians. """ size = 16 # size height, width = fpImg.shape # First we smooth the whole image with a Gaussian filter, to make the # individual pixel gradients less spurious. image = ndimage.filters.gaussian_filter(fpImg, 2.0) # Compute the gradients of both at each pixel gradientX = Helper.convolve(image, self.sobelKernelX) gradientY = Helper.convolve(image, self.sobelKernelY) # Estimate the local orientation of each block yblocks = height // size xblocks = width // size o = np.empty((yblocks, xblocks)) for j in range(yblocks): for i in range(xblocks): v_x = v_y = 0 for v in range(size): for u in range(size): v_x += 2 * gradientX[j * size + v, i * size + u] * gradientY[j * size + v, i * size + u] v_y += gradientX[j * size + v, i * size + u]**2 - gradientY[j * size + v, i * size + u]**2 o[j, i] = 0.5 * np.arctan2(v_x, v_y) # Rotate the orientations so that they point along the ridges, and wrap # them into only half of the circle (all should be less than 180 degrees). o = (o + 0.5 * np.pi) % np.pi # Smooth the orientation field o_p = np.empty(o.shape) o = np.pad(o, 2, mode="edge") for y in range(yblocks): for x in range(xblocks): surrounding = o[y:y + 5, x:x + 5] orientation, deviation = Helper.averageOrientation( surrounding, deviation=True) if deviation > 0.5: orientation = o[y + 2, x + 2] o_p[y, x] = orientation o = o_p # Make an orientation field the same shape as the input image, and fill it # with values interpolated from the preliminary orientation field. orientations = np.full(image.shape, -1.0) halfsize = size // 2 for y in range(yblocks - 1): for x in range(xblocks - 1): for iy in range(size): for ix in range(size): orientations[y * size + halfsize + iy, x * size + halfsize + ix] = Helper.averageOrientation([ o[y, x], o[y + 1, x], o[y, x + 1], o[y + 1, x + 1] ], [ iy + ix, size - iy + ix, iy + size - ix, size - iy + size - ix ]) of = np.where(mskImg == 1.0, orientations, -1.0) return of