def handle_cards(update, filename): # Read cards queue = Queue() im, contours = card.get_im_contours(filename) contours = card.filter_cards_contours(contours) update.message.reply_text("I can see " + str(len(contours)) + " cards") update.message.reply_text("Not sure what they are, though") update.message.reply_text("Let me see...") trained = card.load_trained() cards = [] for contour in contours: worker = SetWorker(update, queue, im, trained, cards) worker.daemon = True worker.start() for contour in contours: queue.put(contour) queue.join() contours, cards = zip(*cards) update.message.reply_text("Here's what I got:") update.message.reply_text( functools.reduce(lambda x, y: x + "," + y, map(str, cards))) my_set = set.Set(im, contours, cards) prefix = os.path.basename(filename).split(".")[0] filenames = my_set.save_sets(SAVE_FOLDER, prefix) return filenames
def test_in(): s = set.Set() s.add(1) s.add("foo") assert (1 in s), "Should find 1 in s: {s}" assert (2 not in s), "Should not find 2 in s: {s}" assert ("foo" in s), "Should find foo in s: {s}" assert ("bar" not in s), "Should not find foo in s: {s}"
def test_add(): s = set.Set() assert (s.add(1)), "Add 1 for the first time should return True" assert (not s.add(1)), "Add 1 for the second time should return False" assert (s.add("foo") ), "Should be able to add strings to Set, should return True" assert ( not s.add("foo") ), "Should only be able to add a given string once to Set, expected False"
def schedule(year, quarter, profiles): #get profiles # profiles = getAllProfiles() #setup quarter sundays = getAllSundaysInQuarter(year, quarter) sets = list() for sun in sundays: #DATE FORMAT IS YEAR-MONTH-DAY dayBefore = sun - timedelta(days=1) #set datetime dateTime_Sunday = getDateTimeObject( str(sun.year) + "-" + str(sun.month) + "-" + str(sun.day)) dateTime_Sunday = dateTime_Sunday.replace(hour=11, minute=45) #rehearsal datetime dateTime_Rehearsal = getDateTimeObject( str(dayBefore.year) + "-" + str(dayBefore.month) + "-" + str(dayBefore.day)) dateTime_Rehearsal = dateTime_Rehearsal.replace(hour=10, minute=00) temp = s.Set(dateTime_Sunday) temp.updateRehearsalDate(dateTime_Rehearsal) sets.append(temp) worshipperIDs = profiles.keys() #cycle through when picking people #populate worshippers into sets for i in sets: #find a leader REQUIRED # update profile['lastSet'] #find a rhythm instrumentalist REQUIRED # update profile['lastSet'] #find drummer #find bassist #check set object functions to make sure critical components have been populated # def validateLeader(self): # def validateVocalist(self): # def validateRhythmInstrument(self): # def getMembers(self): # def getBandSize(self): continue return sets
def neighbours(self, p): n = set.Set() if p.x > 0: n.add(xy(p.x - 1, p.y)) if p.y > 0: n.add(xy(p.x, p.y - 1)) if p.x < len(self.grid[0]) - 1: n.add(xy(p.x + 1, p.y)) if p.y < len(self.grid) - 1: n.add(xy(p.x, p.y + 1)) #print(f"returning neighbours {n}") return n
def handle_cards(filename): # Read cards im, contours = card.get_im_contours(filename) contours = card.filter_cards_contours(contours) trained = card.load_trained() cards = [] for contour in contours: my_card = card.Card(im, contour) my_card.predict(trained) cards.append(my_card) print(my_card) # Compute sets my_set = set.Set(im, contours, cards) # Show sets # my_set.show_sets() # Write sets prefix = os.path.basename(args.filename).split(".")[0] filenames = my_set.save_sets("save", prefix) return filenames
def __init__(self, size = 2048, ways = 2, blockSize = 64) : # check that args are all powers of two if size <= 0 or not checkPowerOfTwo(size): size = 2048; if ways <= 0 or not checkPowerOfTwo(ways): ways = 2; if blockSize <= 0 or not checkPowerOfTwo(blockSize): blockSize = 64; self.ways = ways; self.sets = size//(ways * blockSize); self.blockSize = blockSize; self.setArray = [Set.Set(ways) for _ in range(self.sets)]; # vars for number of accesses and cache misses to output results self.accesses = 0; self.misses = 0; self.nonCompMisses = 0;
def handle_cards(filename): cards = [] queue = Queue() im, contours = card.get_im_contours(filename) contours = card.filter_cards_contours(contours) trained = card.load_trained() for contour in contours: worker = DownloadWorker(queue, im, trained, cards) worker.daemon = True worker.start() for contour in contours: queue.put(contour) queue.join() contours, cards = zip(*cards) # Compute sets my_set = set.Set(im, contours, cards) # Show sets my_set.show_sets() # Write sets prefix = os.path.basename(args.filename).split(".")[0] filenames = my_set.save_sets("save", prefix) return filenames
import bt import set import hash_table import random b1 = bt.BinaryTree(1, 2, 3) A = set.Set(b1) set.make_set(A) b2 = bt.BinaryTree(4, 5, 6) B = set.Set(b2) set.make_set(B) set.union(A, B) ht = hash_table.HashTable() for i in range(12): ht[random.randint(0, 65535)] = random.randint(1, 10) for kv in ht: print("{}:{}".format(kv[0], kv[1])) print(len(ht))
def test_len(): s = set.Set() s.add(1) s.add("two") assert ( len(s)) == 2, f"Set should contain 2 items at this stage, not {len(s)}"
def make_set(x): # x jest wartoscia x_set = st.Set(x) x_set.rank = 0 x_set.p = x_set sets[x] = x_set