def update_ft_state_to_atomspace(self, enabled): if enabled: state = 'on' else: state = 'off' face = '(StateLink face-tracking-state face-tracking-%s)\n' % state netcat(self.hostname, self.port, face)
def saliency(self, x, y, z, deg): sal = '(StateLink (AnchorNode "Salient location")' + \ '(List (NumberNode '+ str(x)+ ')' + \ ' (NumberNode '+ str(y) + ')' + \ ' (NumberNode '+ str(z) + ')))\n' + \ '(StateLink (AnchorNode "Salient degree")' + \ ' (NumberNode '+ str(deg) + '))\n' netcat(self.hostname, self.port, sal)
def parse_status(self): self.status=dict() for entry in self.hosts: host,port=entry.split(':') self.status[host]=dict() self.status[host]['ok']=True if netcat.netcat(host,int(port),'ruok') == 'imok' else False self.status[host]['rw']=True if netcat.netcat(host,int(port),'isro') == 'rw' else False self.status[host]['version'],self.status[host]['mode'],self.status[host]['latency']=Zookeeper.get_status(host,port)
def saliency(self, x, y, z, deg): sal = '(StateLink (AnchorNode "locations")' + \ '(List (NumberNode '+ str(x)+ ')' + \ '(NumberNode '+ str(y)+ ')' + \ '(NumberNode '+ str(z) + ')))\n' + \ '(StateLink (AnchorNode "Degree value")' + \ '(NumberNode '+ str(deg)+'))\n' netcat(self.hostname, self.port, sal)
def create_face_octomap(self): ldcmd = '(use-modules (opencog pointmem))' cmd = '(cog-pointmem-create-map (ConceptNode "' + self.OCTOMAP_NAME + '") \ (ListLink (NumberNode "' + self.SPATIAL_RESOLUTION + '") \ (NumberNode "' + self.TIME_RESOLUTION + '") \ (NumberNode "' + self.TIME_UNITS + '")))' cmd = ldcmd + "\n" + cmd + "\n" print("Sending message %s " % cmd) netcat(self.hostname, self.port, cmd)
def update_face_octomap(self, faceid, xx, yy, zz): face = '(cog-pointmem-map-atom (ConceptNode "' + self.OCTOMAP_NAME + '") \ (NumberNode "' + str(faceid) + '" (av 5 0 0)) \ (ListLink (NumberNode "' + str(xx) + '") \ (NumberNode "' + str(yy) + '") \ (NumberNode "' + str(zz) + '")))' face = face + "\n" print("Sending message %s " % face) netcat(self.hostname, self.port, face)
def create_face_octomap(self): ldcmd = '(use-modules (opencog pointmem))' cmd = '(cog-pointmem-create-map (ConceptNode "'+self.OCTOMAP_NAME+'") \ (ListLink (NumberNode "'+ self.SPATIAL_RESOLUTION+'") \ (NumberNode "'+ self.TIME_RESOLUTION+'") \ (NumberNode "'+ self.TIME_UNITS+'")))' cmd = ldcmd + "\n" + cmd + "\n" print("Sending message %s " % cmd) netcat(self.hostname, self.port, cmd)
def update_face_octomap(self, faceid, xx, yy, zz): face = '(cog-pointmem-map-atom (ConceptNode "'+self.OCTOMAP_NAME+'") \ (NumberNode "'+ str(faceid)+'" (av 5 0 0)) \ (ListLink (NumberNode "'+ str(xx)+'") \ (NumberNode "'+ str(yy)+'") \ (NumberNode "'+ str(zz)+'")))' face = face + "\n" print("Sending message %s " % face) netcat(self.hostname, self.port, face)
def face_recognition(self,tracker_id,rec_id): ''' tracker_id is id for tracking, needs to map to recocgzed or unrecognized rec_id. rec_id is "0" for un recognized face and some other string for recognized face if THIS evaluation link does not exist then face is seen but not determined as known or unknown rec_id is a string and is stored as ConceptNode tracker_id is integer stored as NumberNode ''' stl = "(EvaluationLink (Predicate \"name\") (ListLink (ConceptNode \"" + str(tracker_id) + "\") (ConceptNode \"" + rec_id + "\")))\n" #stl = "(StateLink (NumberNode \"" + str(faceid) + "\") (ConceptNode \"" + rec_id +"\"))\n" netcat(self.hostname, self.port, stl + "\n")
def parse_status(self): self.status = dict() for entry in self.hosts: host, port = entry.split(':') self.status[host] = dict() self.status[host]['ok'] = True if netcat.netcat( host, int(port), 'ruok') == 'imok' else False self.status[host]['rw'] = True if netcat.netcat( host, int(port), 'isro') == 'rw' else False self.status[host]['version'], self.status[host][ 'mode'], self.status[host]['latency'] = Zookeeper.get_status( host, port)
def face_recognition(self, tracker_id, name): ''' Associate a face-recognition ID with a face-tracker ID. `tracker_id` is the ID that the 3D face-location tracker is using. Currently, the tracker-ID is an integer, stored as a NumberNode in the atomspace. `rec_id` is "0" for an unrecognized face and some other string for a recognized face. It is currently stored as a ConceptNode. ''' fc = '(make-recognized-face ' + str(tracker_id) + ' "' + name + '")\n' netcat(self.hostname, self.port, fc)
def face_recognition(self, tracker_id, rec_id): ''' Associate a face-recognition ID with a face-tracker ID. `tracker_id` is the ID that the 3D face-location tracker is using. Currently, the tracker-ID is an integer, stored as a NumberNode in the atomspace. `rec_id` is "0" for an unrecognized face and some other string for a recognized face. It is currently stored as a ConceptNode. ''' stl = "(EvaluationLink (Predicate \"name\") " + \ "(ListLink (ConceptNode \"" + \ str(tracker_id) + "\") (ConceptNode \"" + rec_id + "\")))\n" netcat(self.hostname, self.port, stl)
def GetSuddenClass(self, msg): change = msg.data print "sudden sound change value {}".format(msg.data) loud = "(StateLink (AnchorNode \"Sudden sound change value\")" + \ "(ListLink(NumberNode {})))\n".format(msg.data) netcat(self.hostname, self.port, loud + "\n") if int(change) >= 10: l = "(cog-evaluate! (EvaluationLink (DefinedPredicateNode \"Show expression\")" + \ "(ListLink (ConceptNode \"surprised\") (NumberNode 2) (NumberNode 0.5))))\n" netcat(self.hostname, self.port, l + "\n") else: self.AudioEnergy(self.Decibel)
def home(name='茫茫大海'): # Server Title SERVER_TITLE = "TreeGateway Daemon v1.0 \r\n" # 設定裝置名稱 # deviceName = ["0號機","1號機","2號機","NANO","4號機"] deviceName = ["大會議室","小魚缸","UX","NANO","Edith"] # 設定最大距離 maxDistance = 15.0 # receive data from TreeGateway # nc localhost 8888 # format: [ID,ADDRESS,ONLINE,DISTANCE] # passData.append([0,"00",int("1"),0.0]) # passData.append([1,"041",int("1"),0.0]) # passData.append([2,"03",int("1"),0.0]) # passData.append([4,"01",int("0"),0.0]) currentDistance = 100 currentNode = -1 passData = [] results = '' try: # TreeGateway results = netcat('192.168.200.102',8888,'INFO') except socket.error as e: print "Socket Error" if len(results)>len(SERVER_TITLE): nodes = results[len(SERVER_TITLE):].split('\n') for node in nodes: if node: s = node.split(' ') if (float(s[3])<0.1): dist = '???' else: if currentDistance > float(s[3]) and int(s[2]) > 0: currentDistance = float(s[3]) currentNode = int(s[0]) if float(s[3]) > maxDistance: dist = "{:.2f}m!".format(float(s[3])) else: dist = "{:.2f}m".format(float(s[3])) passData.append([int(s[0]),s[1],int(s[2]),dist]) if currentNode < 0: name = name else: name = deviceName[currentNode] # 搜尋目錄 ./ 及 ./views 下 gatewap.tpl # tpl 檔案裡的 {{變數}} 會被相對應的 變數 取代 # location=name 是指 tpl 裡的 {{location}} 會被 name 取代 # 傳入的 name 如果含有 html tag 會被 escape # 如果不要 escape 請在前面加上驚嘆號 {{!location}} return template('gateway',deviceName=deviceName,location=name,passData=passData)
def send_command(self, script): self.script = script self.command = ("echo '%s' > run.py;python3 run.py" % (script)) self.result = netcat(self.host, self.port, self.command) dec = [ i.decode().replace("[", "").replace("]", "").split(",") for i in self.result ] res = [i for i in dec[0]] if len(res) == 1: res = res[0] print(res + "\r")
async def NetCatRank(ctx): if ctx.message.mentions and ctx.message.mentions[0]: try: cls = netcat.netcat(ctx.message.mentions[0].id) await bot.send_message( ctx.message.channel, "[NetCat API] ~ User {}'s rank is {}".format( cls.username, cls.rank)) except ValueError as e: await bot.send_message(ctx.message.channel, "[NetCat API] ~ {}".format(e)) return
def get_status(host,port): version="" latency="" mode="" status = netcat.netcat(host,int(port),'stat') for line in status.splitlines(): m = re.match('^Zookeeper version:\s*(?P<VERSION>.+)',line) if m: version = m.group('VERSION') m = re.match('Mode:\s(?P<MODE>.+)',line) if m: mode = m.group('MODE') m = re.match('Latency min/avg/max:\s*\d+/(?P<AVG>\d+)/\d+',line) if m: latency=int(m.group('AVG')) return version,mode,latency
def get_status(host, port): version = "" latency = "" mode = "" status = netcat.netcat(host, int(port), 'stat') for line in status.splitlines(): m = re.match('^Zookeeper version:\s*(?P<VERSION>.+)', line) if m: version = m.group('VERSION') m = re.match('Mode:\s(?P<MODE>.+)', line) if m: mode = m.group('MODE') m = re.match('Latency min/avg/max:\s*\d+/(?P<AVG>\d+)/\d+', line) if m: latency = int(m.group('AVG')) return version, mode, latency
async def NetCatChallenges(ctx): if ctx.message.mentions and ctx.message.mentions[0]: try: cls = netcat.netcat(ctx.message.mentions[0].id) challengelist = "" for challenge in cls.complete_challenges: challengelist += challenge + "\n" await bot.send_message( ctx.message.channel, "[NetCat API] ~ User {} has completed {} challenges:\n{}". format(cls.username, len(cls.complete_challenges), challengelist)) except ValueError as e: await bot.send_message(ctx.message.channel, "[NetCat API] ~ {}".format(e)) return
def wholeshow_start(self): netcat(self.hostname, self.port, "(enable-all-demos)") netcat(self.hostname, self.port, '(run)')
def remove_face_from_atomspace(self, faceid): # AtomSpace cog-delete takes handle as an argument. msg = self.delete_face(faceid) netcat(self.hostname, self.port, msg) print "Removed face from atomspace: ", faceid
def add_face_to_atomspace(self, faceid): face = "(EvaluationLink (PredicateNode \"visible face\") " + \ "(ListLink (NumberNode \"" + str(faceid) + "\")))\n" netcat(self.hostname, self.port, face) print "New visible face in atomspace: ", faceid
def add_tracked_face_to_atomspace(self, faceid): face = '(StateLink request-eye-contact-state (NumberNode "' + \ str(faceid) + '"))\n' netcat(self.hostname, self.port, face) print "Force focus of attention on face: ", faceid
def add_face_to_atomspace(self, faceid): face = self.define_face(faceid) netcat(self.hostname, self.port, face + "\n") print "New visible face in atomspace: ", faceid
def who_said(self,stt): spoke = "(who-said? \""+stt+"\")\n" print spoke netcat(self.hostname, self.port, spoke + "\n")
def vocalization_started(self): netcat(self.hostname, self.port, "(State chat-state chat-start)")
def wholeshow_stop(self): netcat(self.hostname, self.port, "(disable-all-demos)") netcat(self.hostname, self.port, "(halt)")
def audio_energy(self, decibel): # A StateLink is used because evaluation of psi-rules should # only depend on the most recent value. deci = '(StateLink (AnchorNode "Decibel value") ' + \ ' (NumberNode ' + str(decibel) + '))\n' netcat(self.hostname, self.port, deci)
def room_brightness(self, bright): room = '(StateLink (AnchorNode "luminance")' +\ ' (NumberNode ' + str(bright) +'))\n' netcat(self.hostname, self.port, room)
def audio_bang(self, decibel): loud = '(StateLink (AnchorNode "Sudden sound change value")' + \ ' (NumberNode ' + str(decibel) + '))\n' netcat(self.hostname, self.port, loud)
def save_snd1(self,x,y,z): snd="(map-sound "+str(x)+" "+str(y)+" "+str(z)+")\n" netcat(self.hostname, self.port, snd + "\n")
def evaluate_scm(self, scm_string): netcat(self.hostname, self.port, scm_string)
def vocalization_ended(self): netcat(self.hostname, self.port, "(State chat-state chat-stop)")
def update_ft_state_to_atomspace(self, ft_enabled): str = self.set_face_tracking_state(ft_enabled) netcat(self.hostname, self.port, str + "\n")
def update_face_octomap(self, faceid, xx, yy, zz): face="(map-ato \"faces\" (NumberNode \""+str(faceid)+"\" (av 5 0 0)) "+str(xx)+" "+str(yy)+" "+str(zz)+")\n" netcat(self.hostname, self.port, face + "\n")
def AudioEnergy(self, value): # A StateLink is used b/c evaluation of psi-rules should only depend on # the most value. deci = "(StateLink (AnchorNode \"Decibel value\")" + \ "(ListLink (NumberNode {})))\n".format(value) netcat(self.hostname, self.port, deci + "\n") # TODO: Convert each if/elif clause into a psi-rule. if value < 35: print "very low sound", value x = "(cog-evaluate! (EvaluationLink (DefinedPredicateNode \"Show expression\")" + \ "(ListLink (ConceptNode \"happy\") (NumberNode 3) (NumberNode 0.5))))\n" netcat(self.hostname, self.port, x + "\n") return 'Quiet Whisper' elif value < 65: print "Normal conversation:", value y = "(cog-evaluate! (EvaluationLink (DefinedPredicateNode \"Show expression\")" + \ "(ListLink (ConceptNode \"amused\") (NumberNode 3) (NumberNode 0.5))))\n" netcat(self.hostname, self.port, y + "\n") m = "(cog-evaluate! (EvaluationLink (DefinedPredicateNode \"Show gesture\")" + \ "(ListLink (ConceptNode \"nod-1\") (NumberNode 0.2) (NumberNode 2) (NumberNode 0.8))))\n" netcat(self.hostname, self.port, m + "\n") return 'Normal Conversation' elif value < 90: print "high sound:", value z = "(cog-evaluate! (EvaluationLink (DefinedPredicateNode \"Show expression\")" + \ "(ListLink (ConceptNode \"irritated\") (NumberNode 3) (NumberNode 0.5))))\n" netcat(self.hostname, self.port, z + "\n") n = "(cog-evaluate! (EvaluationLink (DefinedPredicateNode \"Show gesture\")" + \ "(ListLink (ConceptNode \"think-browsDown.001\") (NumberNode 0.2) (NumberNode 2) (NumberNode 0.8))))\n" netcat(self.hostname, self.port, n + "\n") return 'Loud: Shouted Conversation' else: print 'critical:', value t = "(cog-evaluate! (EvaluationLink (DefinedPredicateNode \"Show expression\")" + \ "(ListLink (ConceptNode \"afraid\") (NumberNode 3) (NumberNode 0.5))))\n" netcat(self.hostname, self.port, t + "\n") return 'Loud: Critical'
def who_said(self, stt): spoke = "(who-said? \"" + stt + "\")\n" netcat(self.hostname, self.port, spoke)
def add_tracked_face_to_atomspace(self, faceid): face = self.set_tracked_face(faceid) netcat(self.hostname, self.port, face + "\n") print "Force focus of attention on face: ", faceid
def update_sound(self, x, y, z): snd = "(map-sound " + str(x) + " " + str(y) + " " + str(z) + ")\n" netcat(self.hostname, self.port, snd)
def affect_happy(self): netcat(self.hostname, self.port, "(State chat-affect chat-happy)")
def affect_negative(self): netcat(self.hostname, self.port, "(State chat-affect chat-negative)")
def update_face_octomap(self, faceid, xx, yy, zz): face = "(map-ato \"faces\" (NumberNode \"" + str(faceid) + \ "\" (av 5 0 0)) " + str(xx) + " " + str(yy) + \ " " + str(zz) + ")\n" netcat(self.hostname, self.port, face)
def perceived_text(self, text): netcat( self.hostname, self.port, '(cog-evaluate! (PutLink (DefinedPredicate "heard text")' + ' (SentenceNode "' + text + '")))')