Example #1
0
 def set_queue_ready(self, cola):
     if not cola_prioridad():
         #			print "COLA PRIORIDAD"
         self.queue1 = queue()
         self.queue2 = queue()
         self.queue3 = queue()
         self.queue4 = queue()
         self.queue5 = queue()
         set_cola_prioridad(True)
     self.cola = cola
     if not self.cola.esVacio():
         #			print "sergio Loyola"
         set_prog_inicio(True)
         validar = True
         aux = self.cola.get_next()
         while (validar):
             if aux != None:
                 #					print ("Imprimo prioridad:", aux.get_priority())
                 if aux.get_priority() == 1:
                     self.queue1.put_ready(aux)
                 if aux.get_priority() == 2:
                     self.queue2.put_ready(aux)
                 if aux.get_priority() == 3:
                     self.queue3.put_ready(aux)
                 if aux.get_priority() == 4:
                     self.queue4.put_ready(aux)
                 if aux.get_priority() == 5:
                     self.queue5.put_ready(aux)
                 aux = self.cola.get_next()
             else:
                 validar = False
Example #2
0
 def set_queue_ready(self, cola):
     if not cola_prioridad():
         self.queue1 = queue()
         self.queue2 = queue()
         self.queue3 = queue()
         self.queue4 = queue()
         self.queue5 = queue()
         set_cola_prioridad(True)
     self.cola = cola
     if not self.cola.esVacio():
         set_prog_inicio(True)
         validar = True
         aux = self.cola.get_next()
         while (validar):
             if aux != None:
                 if aux.get_priority() == 1:
                     self.queue1.put_ready(aux)
                 if aux.get_priority() == 2:
                     self.queue2.put_ready(aux)
                 if aux.get_priority() == 3:
                     self.queue3.put_ready(aux)
                 if aux.get_priority() == 4:
                     self.queue4.put_ready(aux)
                 if aux.get_priority() == 5:
                     self.queue5.put_ready(aux)
                 aux = self.cola.get_next()
             else:
                 validar = False
Example #3
0
 def __init__(self, queue):
     threading.Thread.__init__(self)
     self.queuesend = queue()
     self.queuerecive = queue()
     self.stoper = False
     self.ser = serial.Serial()  # creates serial object
     self.grbl_version = "Grbl Not Detected"
     self.portList = []
     self.Buffer = []
 def leval(self,node):
     if node is None:
         raise IndexError('树为空')
     else:
         import queue
         queue= queue()
         temp = 
Example #5
0
def f(a):
    """
    Convert ints in array 'a' to a tree stucture.
    Return tree structure as string to the caller.
    """
    t = T()
    c = t
    c.d = 20
    for i in a:
        ins = False
        while not ins:
            j = c.d
            if j >= i:
                if c.l == None:
                    c.l = T()
                c = c.l
            else:
                if c.r == None:
                    c.r = T()
                c = c.r
            if c.d == None:
                c.d = i
                ins = True
    q = queue()
    q.put(t)
    s = ""
    while not q.empty():
        c = q.get()
        if c.l != None:
            q.put(c.l)
            s += "0"
        if c.r != None:
            q.put(c.r)
            s += "1"
    return s
Example #6
0
 def __init__(self, bot, participants, text_channel, voice_channel, music_player, rounds=10, time_sec=20.0):
     ''' (Amq, discord.Client, List of Strings, int, double,) -> Amq
     '''
     super().__init__(bot)
     self.rounds = rounds
     self.music_player = music_player
     self.text_channel = text_channel
     self.voice_channel = voice_channel
     self.time_per_song = time_sec
     p_list = []
     anime_list = []
     # initializing the player list
     for person in participants:
         p_list.append(self.Player(person.id))
         # Union two sets (no repeats)
         second_list = AniListWrapper.get_anilist(person.anilist_user)
         in_first = set(anime_list)
         in_second = set(second_list)
         in_second_but_not_in_first = in_second - in_first
         result = anime_list + list(in_second_but_not_in_first)
     self.participiants = p_list
     self.aniList = anime_list
     # RANDO ANIME CHOOSING CODE HERE
     self.animeQueue = queue(self.rounds)
     for x in range(self.rounds):
         song_name = self.aniList.pop(randrange(len(self.aniList)))
         self.animeQueue.put(self.Song(song_name, "temp", "temp"))
Example #7
0
 def Get_LevelOrder(self):
     q = queue()
     q.enqueue(self.store)
     rlist = []
     while True:
         x = q.dequeue()
         if (x[0] == False):
             break
         elif (type(x[1]) == int) or (type(x[1] == str)):
             rlist += [x[1]]
         inside = x[1]
         if x[1] == []:
             continue
         else:
             if type(inside) == list:
                 rlist = rlist + [inside[0]]
                 for idx in inside[1:]:
                     q.enqueue(idx)
             elif type(inside) == str:
                 continue
             elif inside == []:
                 continue
             else:
                 rlist += [(inside.store)[0]]
                 q.enqueue((inside.store)[1])
                 q.enqueue((inside.store)[2])
     return rlist
Example #8
0
    def Get_LevelOrder(self):
        q = queue([])
        returnList = []

        if self.store == []:
            return False

        q.push(self.store)

        while q.getLength() > 0:
            currNode = q.getValues()[0]
            if type(currNode[0]) != int:
                currNode = currNode[0].store

            if len(currNode) > 1:
                if currNode[1] != []:
                    if type(currNode[1][0]) == int:
                        q.push(currNode[1])
                    else:
                        q.push(currNode[1][0].store)
                if currNode[2] != []:
                    if type(currNode[2][0]) == int:
                        q.push(currNode[2])
                    else:
                        q.push(currNode[2][0].store)

            val = q.shift()
            returnList += [val[0]]

        return returnList
    def BFS(self, start_vertex):
        start_vertex = self.get_vertex(start_vertex)

        if start_vertex is None:
            raise Exception("The vertex is not present in the graph.")

        visited = [False] * len(self._vertices)
        traversed = []

        q = queue()
        q.enqueue(start_vertex)

        while not q.isEmpty(
        ):  #this loop goes on until every node is traversed
            v = q.dequeue()
            key = v.get_key()

            if not visited[key]:
                visited[key] = True
                traversed.append(key)

            for neighbor in v.get_connections():
                if not visited[neighbor[0].get_key()]:
                    q.enqueue(neighbor[0])

        return traversed
Example #10
0
	def __init__(self, forward_to_address):
		self.mDropper        = PacketDropper()
		self.mDelayer        = PacketDelayer()
		self.mModifier       = PacketModifier()
		self.mOutgoing       = socket(socket.AF_INET, socket.SOCK_DGRAM)
		self.mForwardAddress = (DEFAULT_FORWARD_IP, DEFAULT_FORWARD_UDP_PORT)
		self.mQueueEvent     = threading.Event()
		self.mQueueEvent.clear()
		self.mQueue = queue()
Example #11
0
 def Get_LevelOrder(self):
     x = queue()
     x.enqueue(self.store)
     accum = []
     while (x.cnt != 0):
         r = x.dequeue()
         accum += [r[1][0]]
         for i in r[1][1]:
             x.enqueue(i.store)
     return accum
Example #12
0
 def Get_LevelOrder (self):
     x = queue()
     x.enqueue(self)
     accum = []
     while x.empty() == False:
         r = x.dequeue()
         accum = accum + [r.store[0]]
         for i in r.store[1:len(r.store)][0]:
             x.enqueue(i)
     return accum
Example #13
0
def get_rds():
    rds = boto3.client('rds', region_name=REGION_NAME, aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, aws_session_token=AWS_SESSION_TOKEN)
    rdsinstances = rds.describe_db_instances()
    rds_count = 0
    rds = queue.deque()
    rds.queue = queue(rdsinstances['DBInstances'])
    for rdsins in rdsinstances['DBInstances']:
        rds_count += 1
        rdsname = rdsins['DBInstanceIdentifier']
        get_rds_metrics(rdsname)
    print 'RDS Count: ' + str(rds_count)
Example #14
0
def main():
    # 页码的队列,表示可以存储10个页面
    pageQueue = queue(10)

    # 放入了1~10的数字,先进先出
    for i in pageQueue(1, 11):
        pageQueue.put(i)

    #采集结果(每页的HTML源码)的数据队列,参数为空表示不限制
    dataqueue = queue()

    #开始线程创建
    # 存储三个采集线程的名字
    crawList = ["一号", "二号", "三号"]

    # 存储三个采集线程
    threadcrawl = []
    for threadName in crawList:
        thread = ThreadCrawl(threadName, pageQueue, dataqueue)
        thread.start()
        threadcrawl.append(thread)
Example #15
0
def makeQueue(runway1, runway2, runway3):
    planeQueue = queue()

    # Loop as long as there are planes left in any of the runways
    while (not isEmpty(runway1) or not isEmpty(runway2)
           or not isEmpty(runway3)):
        # Call nextPlance to find priority plane
        nextPlane = getNext(runway1, runway2, runway3)
        # Add priority plane to queue
        enqueue(planeQueue, nextPlane)

    return planeQueue
Example #16
0
 def Get_LevelOrder(self):
     x = queue()
     x.enqueue(self.store)
     accum = []
     while (x.cnt != 0):
         r = x.dequeue()
         accum += [r[1][0]]
         if type(r[1][1]) == binary_tree:
             x.enqueue(r[1][1].store)
         if type(r[1][2]) == binary_tree:
             x.enqueue(r[1][2].store)
     return accum
Example #17
0
def listOfDepths(bt):
    lists = []
    temp = None
    q = new queue()
    nextQ = new queue()
    currNode = bt

    q.put(currNode)
    while not q.empty():
        currNode = q.get()
        newNode = new LinkedList(currNode.value)
        newNode.next = temp
        temp = newNode
        if currNode.left:
            nextQ.put(currNode.left)
        if currNode.right:
            nextQ.put(currNode.right)

        if q.empty():
            lists.append(temp)
            temp = None
            q = nextQ
            nextQ = new queue()

    return lists
Example #18
0
 def Get_LevelOrder_Obj(self):
     accum = []
     x = queue()
     x.enqueue(self)
     while (1):
         r = x.dequeue()
         if r == False:  #nothing to dequeue - empty queue
             break
         elif r != []:
             accum += [r]
             for i in r.GetSuccessors():
                 x.enqueue(i)
     return accum
Example #19
0
    def Get_LevelOrder(self):
        accum = []
        #		self.q = queue()
        q = queue()
        self.GloHlpr(q)
        #		print("index 1 of q is " + str(q.x[1]))
        #		print("Iterate " + str(len(q.x))+ " times")
        for i in range(0, len(q.x), 1):
            r = q.dequeue()
            accum = accum + [r]

#		print(accum)
        return accum
Example #20
0
    def __init__(self, *args, **kwargs):
        ver = "V 0.0.1"
        tk.Tk.__init__(self, *args, **kwargs)
        tk.Tk.wm_title(self, "Noble Laser " + ver + " --- " + ser111.grbl_version)
        tk.Tk.wm_geometry(self, "800x480+100+100")
        tk.Tk.wm_resizable(self, False, False)
        # tk.Tk.iconbitmap(self,default="some.ico")

        self.queuesend = queue()
        self.queuerecive = queue()
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        self.connectionstatus = False
        self.frames = {}

        for F in (GeneralPage, FileSYSPage, SerialPage, NetworkPage):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky="nsew")
        self.show_frame(GeneralPage)
Example #21
0
def hot_potato_game(names, num_of_rot):
    # function for playing the hot_potato_game with num_of_rot number of rotations
    name_queue = queue()
    for name in names:
        name_queue.enqueue(name)

    while name_queue > 1:
        for i in range(num_of_rot):
            name_queue.enqueue(name_queue.deque())

        name_queue.deque()

    return name_queue.deque()
Example #22
0
 def Get_LevelOrder(self):
     x = queue()
     x.enqueue(self.store)
     accum = []
     while True:
         y = x.dequeue()
         if (y[0] == False):
             break
         else:
             v = y[1]
             accum = accum + [v[0]]
             for i in v[1]:
                 x.enqueue(i.store)
     return accum
Example #23
0
    def Get_LevelOrder(self):
        q = queue()
        q.enqueue(self.store)
        rlist = []

        while (1):
            x = q.dequeue()
            if (x[0] == False):
                break
            else:
                inside = x[1]
                rlist += [inside[0]]
                for element in inside[1]:
                    q.enqueue(element.store)
        return rlist
Example #24
0
def find_len2(root):
    if root is None:
        return
    q = queue()
    q.en_queue(root)
    node = None
    count = 0
    while not q.is_empty:
        node = q.de_queue()
        count += 1
        if node.left is not None:
            q.en_queue(node.left)
        if node.right is not None:
            q.en_queue(node.right)
    return count
Example #25
0
def level_reverse_order(root):
    if root is None:
        q = queue()
        s = stack()
        q.en_queue(root)
        node = None
        while not q.is_empty:
            node = q.de_queue
            if node.left is not None:
                q.en_queue(node.left)
            if node.right is not None:
                q.en_queue(node.right)
            s.push(node)
        while not s.is_empty:
            print(s.pop().get_data)
Example #26
0
def sum_without_recurssion(root):
    if root is None:
        return
    q = queue()
    q.en_queue(root)
    node = None
    sum = 0
    while not q.is_empty():
        node = q.de_queue()
        sum += node.get_data()
        if not node.left:
            q.en_queue(node.left)
        if not node.right:
            q.en_queue(node.right)
    return sum
Example #27
0
 def Get_LevelOrder(self):
     x=queue()
     x.enqueue(self.store)
     accum=[]
     while True:
         y=x.dequeue()
         # y is a 2-list where y[0]=True/False
         # and y[1] is the actual dequeued value when y[0]=True
         if (y[0]==False):
             break
         else:
             v=y[1]
             accum=accum+[v[0]]
             for i in v[1]:
                 x.enqueue(i.store)
     return accum
Example #28
0
 def Get_LevelOrder(self):
     x = queue()
     x.enqueue(self.store)
     accum = []
     while x.store != []:
         r = x.dequeue()
         if r != []:
             if type(r[0]) == int:
                 accum = accum + [r[0]]
                 for i in r[1:len(r)]:
                     x.enqueue(i)
             else:
                 accum = accum + [r[0].store[0]]
                 for i in r[0].store[1:len(r[0].store)]:
                     x.enqueue(i)
     return accum
Example #29
0
def find_node_with_one_child(root):
    if root is None:
        return
    q = queue()
    q.en_queue(root)
    node = None
    count = 0
    while q.is_empty:
        node.q.de_queue()
        if node.left is not None and node.right is None or node.left is None and node.right is not None:
            count += 1
        if node.left is not None:
            q.en_queue(node.left)
        if node.right is not None:
            q.en_queue(node.right)
    return count
Example #30
0
def find_number_of_leaves(root):
    if root is None:
        return
    q = queue()
    q.en_queue(root)
    node = None
    count = 0
    while not q.is_empty:
        node = q.de_queue()
        if node.left is None and node.right is None:
            count += 1
            if node.left is not None:
                q.en_queue(node.left)
            if node.right is not None:
                q.en_queue(node.right)
    return count
Example #31
0
 def __init__(self,gameboard):
     self.grid = [[None for x in range(gameboard.height)] for x in range(gameboard.width)]
     self.run()
     self.qset = queue()
     self.pqueue = PriorityQueue()
Example #32
0
 def __init__(self, queue=queue.Queue, caller=subprocess,
         wait=WaitForever):
     threading.Thread.__init__(self)
     self.queue = queue()
     self.caller = caller
     self.wait = wait()
Example #33
0
 def __init__(self,capacity,levels):
     self._store = [None] * levels
     self._capacity = capacity
     self.size = 0
     for i in range(levels):
         self._store[i] = queue()