def __init__(self, numAgents, numMinutes, betweenTime, serviceTime):
        self._arriveprob = 1.0 / betweenTime
        self._serviceTime = serviceTime
        self._numMinutes = numMinutes
        self.served = 0

        self._passengers = CircularQueue()
        self._Agents = [None] * numAgents
        for i in range(numAgents):
            self._Agents = TicketAgent(i + 1)

        self._totalWaitTime = 0
        self._numPassengers = 0
Ejemplo n.º 2
0
def testImpute(snpData, Ls):
    '''
    Function that slides the window(s) and calculates accuracy of imputation
    on all called values.
    '''

    global corrects
    global count

    L = max(Ls)
    vectors = snpData.vectors
    snps = snpData.snps
    numSNPs = len(snps)

    print 'Running imputation window test with %d window sizes...' % len(Ls),

    count = 0
    corrects = zeros(len(Ls))

    vectorLength = len(vectors.values()[0])

    vectorQueue = CircularQueue(Ls, vectorLength)
    acc = zeros((len(Ls), vectorLength), uint16)
    # Initialize queue
    for i in xrange(L):
        snpVector = vectors[snps[i]]
        vectorQueue.queue[i] = snpVector
        for j in xrange(len(Ls)):
            if i < Ls[j]:
                add(acc[j], snpVector, acc[j])

    # Begin impute
    for i in xrange(numSNPs):
        if i + L < numSNPs:
            vectorQueue.enqueue(vectors[snps[i + L]])
        else:
            vectorQueue.enqueue(zeros(vectorLength, uint16))

        mid = vectorQueue.getMid()
        snp = snps[i]

        for j in xrange(len(Ls)):
            top, bottom = vectorQueue.getEnds(j)
            add(acc[j], top, acc[j])
            subtract(acc[j], bottom, acc[j])
            imputeSNPT(snpData, i, acc[j] - mid, snp, j)

    print 'Done'

    return count, corrects
Ejemplo n.º 3
0
def testImpute(snpData, Ls):
    """
	Function that slides the window(s) and calculates accuracy of imputation
	on all called values.
	"""

    global corrects
    global count

    L = max(Ls)
    vectors = snpData.vectors
    snps = snpData.snps
    numSNPs = len(snps)

    print "Running imputation window test with %d window sizes..." % len(Ls),

    count = 0
    corrects = zeros(len(Ls))

    vectorLength = len(vectors.values()[0])

    vectorQueue = CircularQueue(Ls, vectorLength)
    acc = zeros((len(Ls), vectorLength), uint16)
    # Initialize queue
    for i in xrange(L):
        snpVector = vectors[snps[i]]
        vectorQueue.queue[i] = snpVector
        for j in xrange(len(Ls)):
            if i < Ls[j]:
                add(acc[j], snpVector, acc[j])

                # Begin impute
    for i in xrange(numSNPs):
        if i + L < numSNPs:
            vectorQueue.enqueue(vectors[snps[i + L]])
        else:
            vectorQueue.enqueue(zeros(vectorLength, uint16))

        mid = vectorQueue.getMid()
        snp = snps[i]

        for j in xrange(len(Ls)):
            top, bottom = vectorQueue.getEnds(j)
            add(acc[j], top, acc[j])
            subtract(acc[j], bottom, acc[j])
            imputeSNPT(snpData, i, acc[j] - mid, snp, j)

    print "Done"

    return count, corrects
Ejemplo n.º 4
0
def impute(snpData, L):
    '''
    Function that slides the window and calls other functions to do the actual imputation.
    '''

    global count

    snpData.changes = dict()
    count = 0
    snps = snpData.snps
    vectors = snpData.vectors
    numSNPs = len(snps)

    print "Imputing with window size " + str(L) + "...",

    vectorLength = len(vectors.values()[0])
    vectorQueue = CircularQueue([L], vectorLength)
    acc = zeros(vectorLength, uint16)

    # Initialize queue
    for i in xrange(L):
        snpVector = vectors[snps[i]]
        vectorQueue.queue[i] = snpVector
        add(acc, snpVector, acc)

    # Begin impute
    for i in xrange(numSNPs):

        if i + L < numSNPs:
            snpVector = vectors[snps[i + L]]
            vectorQueue.enqueue(snpVector)
        else:
            vectorQueue.enqueue(zeros(vectorLength, uint16))

        top, bottom = vectorQueue.getEnds(0)
        add(acc, top, acc)
        subtract(acc, bottom, acc)
        snp = snps[i]
        if '?' in snp:
            imputeSNP(snpData, i, acc, snp)

    print "Done"
    return count
Ejemplo n.º 5
0
def impute(snpData, L):
    """
	Function that slides the window and calls other functions to do the actual imputation.
	"""

    global count

    snpData.changes = dict()
    count = 0
    snps = snpData.snps
    vectors = snpData.vectors
    numSNPs = len(snps)

    sys.stderr.write("Imputing with window size " + str(L) + "...")

    vectorLength = len(vectors.values()[0])
    vectorQueue = CircularQueue([L], vectorLength)
    acc = zeros(vectorLength, uint16)

    # Initialize queue
    for i in xrange(L):
        snpVector = vectors[snps[i]]
        vectorQueue.queue[i] = snpVector
        add(acc, snpVector, acc)

        # Begin impute
    for i in xrange(numSNPs):

        if i + L < numSNPs:
            snpVector = vectors[snps[i + L]]
            vectorQueue.enqueue(snpVector)
        else:
            vectorQueue.enqueue(zeros(vectorLength, uint16))

        top, bottom = vectorQueue.getEnds(0)
        add(acc, top, acc)
        subtract(acc, bottom, acc)
        snp = snps[i]
        if "?" in snp:
            imputeSNP(snpData, i, acc, snp)

    sys.stderr.write("Done.\n")
    return count
Ejemplo n.º 6
0
	except IOError,e:
		print e
		exit_programmer()

	url,file,extension,threads,proxies_file,delay = check_args(args)
	
	setdefaulttimeout(delay)
	
	#this queue is to load the items file :[]
	queue_read = Queue()
	#this queue is to write the url found to a file : content.txt
	queue_write = Queue()
	#this queue is for store proxy ip
	loop_queue = None
	if proxies_file is not None:
		loop_queue = CircularQueue.CircularQueue()
	items = file.readlines()
	
	
	queue_put(queue_read,items)
	if proxies_file is not None:
		proxies_items = proxies_file.readlines()
		loop_queue_put(loop_queue,proxies_items)
	
	amount = queue_read.qsize()
	Thread(target=mission_hint,args=(END,amount,queue_read,loop_queue) ).start()
	Thread(target=write_file,args=(END,queue_write), ).start()
	
	
	
	create_threads(threads,queue_read,url,extension,queue_write,loop_queue)
Ejemplo n.º 7
0
from socket import *
import time
import CircularQueue

HOST = ''
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)

udpSerSock = socket(AF_INET, SOCK_DGRAM)
udpSerSock.bind(ADDR)

connection, addr = udpSerSock.recvfrom(BUFSIZ)
print(connection)
sequence = 1
qStr = CircularQueue.SqQueue(30)
qTime = CircularQueue.SqQueue(30)
minTime = time.time()

while True:
    t = time.time()

    if t - minTime > 60:
        break

    if qStr.QueueFull():
        print(qTime.SumTimeQueue())
        print(qStr.SumStrQueue())
        rate = qStr.SumStrQueue() / qTime.SumTimeQueue()
        print(rate / (1024 * 1024), end='\n')
        if rate / (1024 * 1024) > 0.0001:
class TicketCounterSimulation:
    def __init__(self, numAgents, numMinutes, betweenTime, serviceTime):
        self._arriveprob = 1.0 / betweenTime
        self._serviceTime = serviceTime
        self._numMinutes = numMinutes
        self.served = 0

        self._passengers = CircularQueue()
        self._Agents = [None] * numAgents
        for i in range(numAgents):
            self._Agents = TicketAgent(i + 1)

        self._totalWaitTime = 0
        self._numPassengers = 0

    def run(self):
        for curTime in range(self._numMinutes):
            self._handleArrival(curTime)
            self._handleBeginService(curTime)
            self._handleEndService(curTime)
        self.printResult()

    def printResult(self):
        numServed = self._numPassengers - len(self._passengers)
        avgwait = float(self._totalWaitTime) / numServed
        print("")
        print("Number of passengers served()")
        print("Number of passengers remaining in line")
        print("The average wait time was")

    # Handle Customer Arrival
    def _handleArrival(self, curTime):
        prob = randint(0.0, 1.0)
        if 0.0 <= prob and prob <= self._arriveprob:
            person = Passenger(self._numPassengers + 1, curTime)
            self._passengers.enqueue(person)
            self._numPassengers += 1
            print("Time Passenger")

    # Begin Customer Service
    def _handleBeginService(self, curTime):
        i = 0
        while i < len(self._Agents):
            if self._Agents[i].isFree() and not self._passengers.isEmpty(
            ) and curTime != self._numMinutes:
                passenger = self._passengers.dequeue()
                self.served += 1
                stoptime = curTime + self._serviceTime
                self._Agents[i].starService(passenger, stoptime)
                self._totalWaitTime += (curTime - passenger.timeArrivaed())
                print("Time Agent started serving")

    # End Customer Service
    def _handleEndService(self, curTime):
        i = 0
        while i < len(self._Agents):
            if self._Agents[i].isFinished(curTime):
                passenger = self._Agents[i].stopService()
                print(":Time Agent stoped serving")

            i += 1