def test(store): from Thing import Thing from Person import Person from webware.MiscUtils.DataTable import DataTable dataSource = ''' b:int,i:int,l:long,f:float,s:string,d:int 0,0,0,0,0,0 0,0,0,0.0,0.0,0 1,1,1,1,a,0 0,-1,8589934592,-3.14,'x',0 ''' data = DataTable() data.readString(dataSource) for values in data: print(values) t = Thing() for attr in list('bilfsd'): t.setValueForKey(attr, values[attr]) store.addObject(t) store.saveChanges() # Try an immediate fetch results = store.fetchObjectsOfClass(Thing) assert len(results) == 1, 'len=%s, results=%s' % (len(results), results) # This tests the uniquing feature of MiddleKit: assert id(results[0]) == id(t) # Clear the store's in memory objects and try a fetch again store.clear() results = store.fetchObjectsOfClass(Thing) assert len(results) == 1 assert results[0].allAttrs() == t.allAttrs() # Make sure what we got from the store is what we put in for attr in list('bils'): assert results[0].valueForKey(attr) == values[attr] different = 0.000001 # @@ 2000-11-25 ce: more work needed on floats assert abs(results[0].valueForKey('f') - values['f']) < different # Insert the fetched attributes t2 = Thing() for attr in list('bilfsd'): t2.setValueForKey(attr, results[0].valueForKey(attr)) store.addObject(t2) store.saveChanges() results = store.fetchObjectsOfClass(Thing) assert len(results) == 2, 'len=%r' % len(results) assert results[0].allAttrs() == results[1].allAttrs() # Reset store.clear() store.executeSQLTransaction('delete from Thing;')
def parse_mtree(mtree_file): gz = gzip.open(mtree_file, mode="rt", encoding='utf-8') defaults = {} objects = [] for line in gz: # strip comments, etc #logging.debug(line.strip()) line = re.sub(r'\s*#.*', '', line.strip()) if line == '': logging.debug('Empty line') continue # the /set lines update the default attributes m = re.match(r'^/set\s+(.*)', line) if m: for a in re.split(r'\s+', m.group(1)): k, v = a.split('=') defaults[k] = v logging.debug('new defaults: %s', str(defaults)) continue # handle /unset m = re.match(r'^/unset\s+(.*)', line) if m: for a in re.split(r'\s+', m.group(1)): defaults.pop(a) print(defaults) continue # A "data" line has a path, followed by k=v pairs path, attrstr = line.split(' ', maxsplit=1) # skip these if path in ('./.BUILDINFO', './.PKGINFO', './.INSTALL', './.CHANGELOG'): continue # Set the current defaults, all of which can be overriden # on a per-line basis. Set the default type to be "file", # as that is usually omitted, unless the entry isn't a file. attribs = dict(defaults) attribs['type'] = 'file' # Add metadata for a in attrstr.split(' '): k, v = a.split('=') attribs[k] = v objects.append(Thing(path, attrs=attribs, ignore_dir_mtime=True)) return objects
def createObjects(self): from Thing import Thing for i in range(self._numObjects): t = Thing() t.setB(1) t.setI(2) t.setL(3) t.setF(4.0) t.setS('five') self._store.addObject(t) self._store.saveChanges() things = self._store.fetchObjectsOfClass('Thing') assert len(things)==self._numObjects, '%i, %i' % (len(things), self._numObjects)
# nekem megoldotta az import problémát az, # hogy a .vscode/settings.json -ön belül # "python.languageServer": "Jedi" -re változtattam a # "python.languageServer": "Microsoft" helyett from Fleet import Fleet from Thing import Thing fleet = Fleet() get_milk = Thing("Get milk") remove_obstacles = Thing("Remove the obstacles") stand_up = Thing("Stand up") stand_up.complete() eat_lunch = Thing("Eat lunch") eat_lunch.complete() fleet.add(get_milk) fleet.add(remove_obstacles) fleet.add(stand_up) fleet.add(eat_lunch) # Töltsd fel a fleet példányt olyan módon, hogy a következő legyen a kimenet: # 1. [ ] Get milk # 2. [ ] Remove the obstacles # 3. [x] Stand up # 4. [x] Eat lunch print(fleet)
cx = int(M['m10'] / M['m00']) cy = int(M['m01'] / M['m00']) x, y, w, h = cv2.boundingRect(cnt) new = True for i in things: # 从没有结束的对象里面找 if i.getIsEnd() == False and abs(x - i.getX()) <= w and abs( y - i.getY()) <= h: # 如果新探测到的接近前一帧探测到的 new = False i.updateCoords(cx, cy) #更新那个接近的坐标顺便记录此元素这一次被改变了 break if new == True: # 如果确定有新的 p = Thing(pid, cx, cy) things.append(p) pid += 1 cv2.circle(frame, (cx, cy), 5, (0, 0, 225), -1) #小红点 img = cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 225, 0), 2) cv2.drawContours(frame, cnt, -1, (0, 255, 0), 3) # 检查之后的物品 for i in things: if i.getIsEnd() == False: # 如果在尚存物品中发现本轮未改变的或者发现超出范围的物品 立即将其结束 if i.getIsChanged() == False or i.getY() >= 850: i.setEnd() i = 0 while i <= (len(things) - 1):
from Thing import Thing, on_message import time import threading thing = Thing('"12345"', '"12345"', "http://165.22.121.233:8888/api/authorization/", "165.22.121.233") thing.on_message = on_message thing.Start() thr = threading.Thread(target=thing.OnConnected) thr.start() thing.Send("start ssss") time.sleep(5) thing.End()
'spa': 'No se pudo conectar con el servidor', 'eng': 'Cannot connect to server' } """This is where it begins""" if not is_server_up(): print(no_server_error_message[lang]) quit() auth = Authentication() if not auth.is_auth: quit() thing = Thing() print('ip: ' + str(thing.ip)) print('macs: ' + str(thing.macs)) groups = auth.getAdminGroups() pprint(groups) allThings = [] for group in groups: res = requests.get(base_url+'/group', params={'id': group['id']}) group = res.json() #pprint(group) for t in group['things']: allThings.append(t)
from Fleet import Fleet from Thing import Thing fleet = Fleet() # Create a fleet of things to have this output: # 1. [ ] Get milk # 2. [ ] Remove the obstacles # 3. [x] Stand up # 4. [x] Eat lunch fleet.add(Thing("Get milk")) fleet.add(Thing("Remove the obstacles")) thing1 = Thing("Stand up") thing1.complete() thing2 = Thing("Eat lunch") thing2.complete() fleet.add(thing1) fleet.add(thing2) print(fleet)
wildPokemon = Pokemon("Oddish", "leaf", "water") for i in range(len(pokemon)): if (pokemon[i].isEffectiveAgainst(wildPokemon)): print(f"Ash should Choose {pokemon[i].get()}") ###### Fleet of Things from Fleet import Fleet from Thing import Thing # Create a fleet of things to have this output: # 1. [ ] Get milk c = Thing("Get milk") milk = c.__str__() fleet = Fleet() fleet.add(milk) # 2. [ ] Remove the obstacles c = Thing("Remove the obstacles") remove = c.__str__() fleet.add(remove) # 3. [x] Stand up c = Thing("Stand up") true_complete = c.complete() stand = c.__str__() fleet.add(stand)