Exemple #1
0
    def __init__(self, node):
        self.node = node
        self.id = node.id
        self.trace = BaseTracer()

        # sellers are trading on multiple jobs
        self.accept_processes = {}
        self.confirm_processes = {}

        # use ring buffers for space saving since 
        # resource agents are long lived
        self.nrejected = 0
        self.cancelled = RingBuffer(400)
        self.timedout = RingBuffer(400)
Exemple #2
0
from util import RingBuffer

numberwang = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
aj = 13
buf = RingBuffer(aj)
dig = {}
for x in numberwang:
    i = int(x)
    buf.append(i)
    arr = buf.get()
    boo = False
    for y in arr:
        if not y:
            boo = True
    if not boo:
        i2 = 0
        for z in arr:
            if i2 == 0:
                i2 = z
            else:
                i2 *= z

        key = ""
        for s in arr:
            key += str(s)
        dig[key] = i2

highest = ('', 0)
for x in dig.items():
    if x[1] >= highest[1]:
        highest = x
Exemple #3
0
class ResourceAgent(object):

    def __init__(self, node):
        self.node = node
        self.id = node.id
        self.trace = BaseTracer()

        # sellers are trading on multiple jobs
        self.accept_processes = {}
        self.confirm_processes = {}

        # use ring buffers for space saving since 
        # resource agents are long lived
        self.nrejected = 0
        self.cancelled = RingBuffer(400)
        self.timedout = RingBuffer(400)

    @property
    def resource(self):
        return self.node.resource

    # utility functions
    def confirm_and_start_job(self, job, other, value):
        # sending confirmation message
        confirm = Confirm(self, other, value)
        confirm.send_msg(self.node, other.node)
        
        # start procsses to listen for cancellations
        confirm_process = ConfirmProcess(self, value)
        activate(confirm_process, confirm_process.confirm())
        self.confirm_processes[job.id] = confirm_process

        # start the job
        self.resource.start(job, confirm_process)

    
    def send_reject(self, other, value):
        reject = Reject(self, other, value)
        reject.send_msg(self.node, other.node)


    # public AcceptProcess message interface
    def confirm(self, confirm):
        if confirm.id in self.accept_processes:
            process = self.accept_processes[confirm.id]
            process.signal("confirm", confirm)
        else:
            self.trace("WARNING: no accept process for confirm %s" 
                    % reject.str(self))
    
    def reject(self, reject):
        if reject.id in self.accept_processes:
            process = self.accept_processes[reject.id]
            process.signal("reject", reject)
        else:
            self.trace("WARNING: no accept process for reject %s" 
                    % reject.str(self))

 
    # public ConfirmProcess message interface
    def cancel(self, cancel):
        trace = self.trace.add("j%-5s" % cancel.id)
        self.cancelled.add(cancel.id)
        if cancel.id in self.confirm_processes:
            process = self.confirm_processes[cancel.id]
            process.signal("cancel", cancel)
        else:
            trace and trace("no confirm process for cancel, "
                    "probably out of sync")
    
    def complete(self, complete):
        trace = self.trace.add("j%-5s" % cancel.id)
        if complete.id in self.confirm_processes:
            process = self.confirm_processes[complete.id]
            process.signal("complete", complete)
        else:
            trace("WARNING: no confirm process for complete")


    #internal ConfirmProcess interface
    # this should be the same for all resource agents
    def cancel_received(self, cancel):
        trace = self.trace.add('j%-5s' % cancel.job)

        if cancel.job in self.resource.jobs:
            trace and trace("got cancel, cancelling job %s" 
                    % cancel.job.id)
            self.resource.cancel(cancel.job);
            del self.confirm_processes[cancel.job.id]
        else:
            trace("WARNING: got cancel for job not running (%s)"
                    % cancel.job.id)

    def complete_received(self, complete):
        trace = self.trace.add('j%-5s' % complete.job.id)
        trace and trace("job %s completed, cleaning up" 
                % complete.job.id)
        del self.confirm_processes[complete.job.id]
Exemple #4
0
 def __init__(self, node, rationale,  **kw):
     super(SBSeller, self).__init__(node, rationale, **kw)
     self.offers = RingBuffer(500)
Exemple #5
0
class SBSeller(Seller):

    def __init__(self, node, rationale,  **kw):
        super(SBSeller, self).__init__(node, rationale, **kw)
        self.offers = RingBuffer(500)

    # internal ListenProcess interface
    def quote_received(self, quote):
        trace = self.trace.add('j%-5s' % quote.job.id)
        trace and trace("advert from %s at %s" % (quote.buyer, quote.buyer.node))
        
        if quote not in self.offers:
            if self.resource.can_allocate(quote.job):

                # generate a quote and send it
                self.price = self.rationale.quote()
                quote = Ask(quote.buyer, self, quote.job, self.price)
                private = PrivateQuote(quote)
                private.send_msg(self.node, quote.buyer.node)
                self.set_quote_timeout(quote, trace)

                self.offers.add(quote)
                trace and trace("sending offer %s" % quote)

            else:
                # TODO: add this record to the job object
                record.record_failure_reason(quote.job.id, "Too Busy")
                trace and trace("resource has no room for job")
                self.nrejected += 1
        else:
            trace("WARNING: received advert for job already trading for")


    def accept_received(self, quote):
        trace = self.trace.add('j%-5s' % quote.job.id)

        if quote in self.offers:
            # we know this one
            trace and trace("got accept from %s" % quote.buyer)
            
            self.cancel_quote_timeout(quote.id, trace)
            self.rationale.observe(quote, True)

            # can we still do it?
            if self.resource.can_allocate(quote.job): 
                self.confirm_and_start_job(
                        quote.job, quote.buyer, quote)
                
            else: # we cannot honour our original quote
                trace and trace("got accept, now too busy, rejecting")
                record.record_failure_reason(quote.job.id, "Too Busy Later")
                self.send_reject(quote.buyer, quote)
                self.nrejected += 1

        else: 
            trace and trace("got an accept for a job we've timed out on")


    # diable confirm/reject as in sealedbid these are buyer only
    confirm = Seller.disable("confirm")
    reject = Seller.disable("reject")

    def quote_timedout(self):
        """this is for a regular pulse timeout"""
        pass
Exemple #6
0
turning_th = 2

for m in get_monitors():
    total_H += m.height
    total_W += m.width
print(total_H)
print(total_W)
cap = cv2.VideoCapture(2)
_, frame = cap.read()
h = frame.shape[0]
w = frame.shape[1]
incx = total_W / float(w)
incy = total_H / float(h)
startx = starty = 0
font = cv2.FONT_HERSHEY_PLAIN
xhistory = RingBuffer(ringlen)
yhistory = RingBuffer(ringlen)
last_dist_x = last_dist_y = 0
firstx = True
firsty = True
count = 0
data = np.array([[125, 249], [135, 259], [145, 269], [155, 279], [135, 259],
                 [115, 239], [95, 219], [75, 199]])
while True:
    _, frame = cap.read()
    # s0x, s0y = pyautogui.position()
    # images = sorted(glob.glob('data/*.png'))
    # for fname in images:
    #     frame = cv2.imread(fname)
    # for m in data: