示例#1
0
def prompt_month_pretty(w: Worker.Worker) -> None:
    """
    Print an overview of this month
    """
    print('''Do you want to see your current month?''')
    d: bool = yes_or_no()
    if d:
        #Hours worked
        print('These are your hours worked:')
        print_dict_pretty(w.get_hours_month())
        #Income, Expected and Balance
        exp: float = w.get_monthly_expected()
        plus: float = add_values_dict(w.earnings)
        minus: float = add_values_dict(w.expenses)
        bal: float = exp + plus - minus
        print()
        print('''
        You Expect to earn:         +{expected:>10}€
        Plus your other earnings:   +{plus:>10}€
        Minus your expenses:        -{minus:>10}
        That makes it a balance of : {balance:>10}€'''.format(expected=exp,
                                                              plus=plus,
                                                              minus=minus,
                                                              balance=bal))
    print()
示例#2
0
 def __init__(self):
     Worker.__init__(self, "WorkerDB")
     
     self.db = None
     
     #Specific ZMQ stuff for WorkerDB, it uses SUB/PUB
     self.sub = self.context.socket(zmq.SUB)
示例#3
0
    def test_do(self):
        in_queue = ClosableQueue()
        out_queue = ClosableQueue()
        out2_queue = ClosableQueue()

        queues = [
            in_queue,
            out_queue,
            out2_queue,
        ]

        threads = [
            Worker(foo, in_queue, out_queue),
            Worker(bar, out_queue, out2_queue),
        ]

        for t in threads:
            t.start()
        count = 10
        start = time()

        trigger(queues[0], count)

        finish(queues)

        end = time()
        shouldBe = count * 0.3 + 0.1
        usage = end - start
        self.assertAlmostEqual(shouldBe, usage, delta=0.5)
        print("should %g secs, Took %g secs" % (shouldBe, usage))
示例#4
0
 def getEntity(self, paramDict):
     res_worker = Worker()
     query = 'SELECT WorkerId, PIB, Age, Gender, Adress, Phone, Passport, PositionId ' \
             'FROM Workers ' \
             'WHERE '
     equal_substr = '{attr_name} = ?'
     counter = len(paramDict)
     args = []
     for param in paramDict:
         query += equal_substr.format(attr_name=param)
         args.append(paramDict[param])
         if counter == 1:
             query += ';'
         else:
             query += ' AND '
         counter -= 1
     connection = sqlite3.connect(self._dbname)
     result = connection.execute(query, args).fetchone()
     connection.close()
     res_worker.workerId = result[0]
     res_worker.pib = result[1]
     res_worker.age = result[2]
     res_worker.gender = result[3]
     res_worker.address = result[4]
     res_worker.phone = result[5]
     res_worker.passport = result[6]
     res_worker.positionId = result[7]
     return res_worker
示例#5
0
 def __init__(self, workerNum=5):
     super(Manager, self).__init__()
     self.workerNum = workerNum
     for i in range(self.workerNum):
         worker = Worker('worker-thread[%d]' %(i), self.workerQueue, func)
         self.workerQueue.put(worker)
         worker.start()
示例#6
0
def prompt_act_month(w: Worker.Worker) -> None:
    """
    Set the actual month the worker is starting on
    """
    m: str = input('''What month is it?[jan, feb, apr, etc...]''')
    w.set_act_month(m)
    print()
示例#7
0
    def login(self, account, password, status, proxy, use_http=False):
        '''start the login process'''
        self.account = e3.Account(account, password, status)
        worker = Worker('emesene2', self, proxy, use_http)
        worker.start()

        self.add_action(e3.Action.ACTION_LOGIN, (account, password, status))
 def __init__(self):
     Worker.__init__(self, "Worker Rolling Average Subtraction")
     
     #Class specific variables
     self.averagedBuffer = None
     self.datFiles = []
     self.datIndex = 1
def add_questions_to_sentences(resultlines, categories, tasks):
    """Adds the Questions to the Sentences in the Tasks (phew), reading the worker's
    data from resultlines (a list of lines from the result file) and using the
    dictionary categories to put the Questions in the correct places.
    pre: resultlines is a list of lines from the result file, categories is a
    hash table based on metadata strings.
    post: Returns the task dictionary."""
    workers = []
    for rline in resultlines:                                                   #For each worker's data...
      l = rline.split("\t")                                                         #Make it a list of data
      workerID = l[19]                                                              #Retrieve workerID
      l = map(deleteQuotes,l)                                                       #Delete all the unnecessary quotes
      worker = Worker(workerID, l[29])
      workers.append(worker)
      currentTask = tasks[ l[29] ]                                                  #Find the Task that the worker is working on (taskID @l[29])
      #print currentTask.get_ID()
      currentTask = __add_questions(l, currentTask, categories, worker)           #Add the questions where they should go
      #currentTask.add_worker(worker)
    #print len(currentTask.get_workers())
    for worker in workers:
      taskID = worker.get_taskID()
      task = tasks[taskID]
      if task.get_ID()==taskID:
      	task.add_worker(worker)
    #print len(
    return tasks
示例#10
0
def main():
    in_queue = ClosableQueue()
    out_queue = ClosableQueue()
    out2_queue = ClosableQueue()

    queues = [
        in_queue,
        out_queue,
        out2_queue,
    ]

    threads = [
        Worker(foo, in_queue, out_queue),
        Worker(bar, out_queue, out2_queue),
    ]

    for t in threads:
        t.start()
    count = 10
    start = time()

    trigger(queues[0], count)

    finish(queues)

    end = time()
    print("should %g secs, Took %g secs" % (count * 0.3 + 0.1, end - start))
示例#11
0
 def __start(self, min_durtion, max_durtion, caller, pre_callback,
             post_callback):
     for i in xrange(0, self.agents_count):
         w = Worker(self.queue, i, min_durtion, max_durtion, caller,
                    pre_callback, post_callback)
         self.workers.append(w)
         w.start()
示例#12
0
 def __init_workers(self):
     for i in range(defaultThreadNum):
         worker = Worker(name="worker_" + str(i + 1),
                         jobs=self.__tasks,
                         task_condition=self.__task_condition)
         self.__pool.append(worker)
         worker.start()
         self.__thread_count = defaultThreadNum
 def clear(self):
     """
     Calls super clear() and then the workers specific requirements
     """
     Worker.clear(self)
     self.averagedBuffer = None
     self.bufferIndex = 1
     self.buffers = []
 def clear(self):
     """
     Calls super clear(), removes averaged buffer, sets index back to 1 and clears out all datFiles
     """
     Worker.clear(self)
     self.averagedBuffer = None
     self.datFiles = []
     self.datIndex = 1
示例#15
0
class Session(e3.Session):
    '''a specialization of e3.Session'''
    NAME = 'Jabber session'
    DESCRIPTION = 'Session to connect to the Jabber network'
    AUTHOR = 'Mariano Guerra'
    WEBSITE = 'www.emesene.org'

    SERVICES = {
        "gtalk": {
            "host": "talk.google.com",
            "port": "5223"
        },
        "facebook": {
            "host": "chat.facebook.com",
            "port": "5222"
        }
    }

    def __init__(self, id_=None, account=None):
        '''constructor'''
        e3.Session.__init__(self, id_, account)

    def login(self,
              account,
              password,
              status,
              proxy,
              host,
              port,
              use_http=False):
        '''start the login process'''
        self.account = e3.Account(account, password, status, host)
        self.__worker = Worker('emesene2', self, proxy, use_http)
        self.__worker.start()

        self.add_action(e3.Action.ACTION_LOGIN,
                        (account, password, status, host, port))

    def send_message(self, cid, text, style=None, cedict=None, celist=None):
        '''send a common message'''
        if cedict is None:
            cedict = {}

        if celist is None:
            celist = []

        account = self.account.account
        message = e3.Message(e3.Message.TYPE_MESSAGE, text, account, style)
        self.add_action(e3.Action.ACTION_SEND_MESSAGE, (cid, message))

    def request_attention(self, cid):
        '''request the attention of the contact'''
        account = self.account.account
        message = e3.Message(e3.Message.TYPE_MESSAGE,
                             '%s requests your attention' % (account, ),
                             account)
        self.add_action(e3.Action.ACTION_SEND_MESSAGE, (cid, message))
示例#16
0
class ManagerClient:
    def __init__(self, gate, size_buffer):
        self.waitLinesCode = False
        self.waitData = False
        self.codeTransmitted = None
        self.className = None
        self.data = None
        self.worker = None
        self.server = Client.Client(self, gate, size_buffer)

    def start(self):
        with open("./module/process.py", 'a+', encoding='utf-8') as fd:
            fd.write("")
        self.server.start()

    def end_task(self, worker, data):
        print(data)
        self.server.send("RESULT")
        self.server.send(str(data))
        self.server.send("ENDRESULT")

    def on_message(self, message):
        if len(message) > 4 and message[0:4] == "CODE":
            message = message.split('-')
            self.codeTransmitted = ""
            self.className = message[1]
            self.waitLinesCode = True

        elif message == "ENDCODE":
            self.waitLinesCode = False
            print(self.codeTransmitted)
            with open("./module/process.py", 'w+', encoding='utf-8') as fd:
                fd.write(self.codeTransmitted)

            self.codeTransmitted = None

        elif message == "DATA":
            self.waitData = True
            self.data = ""

        elif message == "ENDDATA":
            self.waitData = False
            self.data = eval(self.data)
            print(self.data)

        elif message == "RUN":
            clazz = getattr(importlib.import_module("module.process"),
                            self.className)
            process = clazz()
            self.worker = Worker(self.data, process, self)
            self.worker.start()

        elif self.waitData:
            self.data += message

        elif self.waitLinesCode:
            self.codeTransmitted += message + "\n"
示例#17
0
class Executor:
    def __init__(self, conf_file):
        self.worker = Worker(conf_file)

    def setUp(self):
        pass

    def run(self, task):
        self.worker.run(task)
示例#18
0
 def __init__(self, parent=None):
     super(self.__class__, self).__init__(parent)
     self.window = MainWindow()
     self.worker = Worker()
     self.worker_thread = QThread()
     self.connect_signals()
     self.worker.moveToThread(self.worker_thread)
     self.worker_thread.start()
     self.window.btnCollectOff.setEnabled(False)
     self.window.show()
示例#19
0
	def addWorker(self, peer):
		key = peer.key
		if key not in self.workers and len(self.workers) < MAX_WORKERS: # We dont have worker for that peer and workers num less than max
			worker = Worker(self, peer)
			self.workers[key] = worker
			worker.key = key
			worker.start()
			return worker
		else: # We have woker for this peer or its over the limit
			return False
示例#20
0
	def addWorker(self, peer):
		key = peer.key
		if key not in self.workers and len(self.workers) < MAX_WORKERS: # We dont have worker for that peer and workers num less than max
			worker = Worker(self, peer)
			self.workers[key] = worker
			worker.key = key
			worker.start()
			return worker
		else: # We have woker for this peer or its over the limit
			return False
 def __init__(self, **kwargs):
     Worker.__init__(self, "Worker Buffer Average")
     
     #Specific Class Variables
     self.averagedBuffer = None
     self.bufferIndex = 1
     self.buffers = []
     self.averagedIntensities = None
     
     self.previousName = None
示例#22
0
    def login(self, account, password, status, proxy, host, port , use_http=False, use_ipv6=False):
        '''start the login process'''

        self.account = e3.Account(account, password, status, host)

        self.__worker = Worker(self, proxy, use_http, use_ipv6)
        self.__worker.start()

        self.add_action(e3.Action.ACTION_LOGIN, (account, password, status,
            host, port))
示例#23
0
def modify_expenses(w: Worker.Worker) -> None:
    """
    Prompt the user and modify recursively his expenses
    """
    read: list = input("Enter the values to replace/add here:").lower().split()
    rdict = list_to_dict(read)
    w.add_expenses(rdict)
    print("Do you want to modify something else?")
    d = yes_or_no()
    if d:
        modify_expenses(w)
示例#24
0
文件: Session.py 项目: Roger/emesene
    def login(self, account, password, status, proxy, host, port, use_http=False):
        """start the login process"""
        worker = Worker("emesene2", self, proxy, use_http)
        worker.start()

        # msn password must have 16 chars max.
        password = password[:16]
        # ------------------------------------
        self.account = e3.Account(account, password, status, host)

        self.add_action(e3.Action.ACTION_LOGIN, (account, password, status, host, port))
 def __init__(self):
     Worker.__init__(self, "WorkerStaticImage")
     
     self.subtractedDatIntensities = []
     self.subtractedDatq = []
     self.subtractedErrors = []
     
     #For adding to be cleared when new user/sample
     self.addToClearList(self.subtractedDatIntensities)
     self.addToClearList(self.subtractedDatq)
     self.addToClearList(self.subtractedErrors)
示例#26
0
 def addWorker(self, firstName, lastName, workLoad):
     if not (isinstance(firstName, str) and isinstance(lastName, str)
             and isinstance(workLoad, int)):
         return False
     worker = Worker(firstName, lastName, workLoad, self.__workerCount)
     if self.__workers.insert(worker.searchkey, worker):
         for i in range(0, worker.getWorkload()):
             self.addWorkload()
         self.__userCount += 1
         return True
     return False
示例#27
0
 def __init__(self, host, port):
     Thread.__init__(self)
     self.def_in = 0
     self.def_out = 0
     self.worker = Worker()
     self.worker.start()
     self.downtop_tasks = {}
     self.host = host
     self.port = port
     self.server = get_socket_server(self.port)
     self.consumer = init_kafka_consumer()
     self.producer = init_kafka_producer()
示例#28
0
    def login(self, account, password, status, proxy, host, port, use_http=False):
        '''start the login process'''
        worker = Worker('emesene2', self, proxy, use_http)
        worker.start()

        #msn password must have 16 chars max.
        password=password[:16]
        #------------------------------------
        self.account = e3.Account(account, password, status, host)

        self.add_action(e3.Action.ACTION_LOGIN, (account, password, status,
            host, port))
示例#29
0
    def running(self):
        print("Wait for new connections on http://" + self.IP + ":" +
              str(self.PORT_HTTP))

        while True:  # ever on
            self.reqCount += 1
            conn, addr = self.s.accept()
            thread = Worker(conn, addr, conn.recv(self.BUFFER_SIZE),
                            self.servers, self.reqCount, self.upTime, self.IP,
                            self.PORT_HTTP)  # create thread
            thread.start()  # execute thread
            continue
示例#30
0
	def runloop(self):
		while self.current <= self.end:
			remainLimit = self.limit - threading.activeCount()
			if remainLimit > 0:
				for x in xrange(1, remainLimit):
					uri = uriTemplate % (self.current,)
					self.current += 1
					worker = Worker(uri=uri)
					worker.daemon = True
					worker.start()
					# worker.join()
			
			time.sleep(2)
示例#31
0
 def copyMove(self, oldP, newP):
     copy = RecBoard(False)
     for i in range(BOARD_SHAPE[0]):
         for j in range(BOARD_SHAPE[1]):
             if self.board[(i, j)] is not None:
                 if self.board[(i, j)].owner is 0:
                     copy.board[(i, j)] = Worker((i, j), 0)
                     copy.player0.append(copy.board[(i, j)])
                 else:
                     copy.board[(i, j)] = Worker((i, j), 1)
                     copy.player1.append(copy.board[(i, j)])
     copy.move(oldP, newP)
     return copy
示例#32
0
class Session(e3.Session):
    '''a specialization of e3.Session'''
    NAME = 'Jabber session'
    DESCRIPTION = 'Session to connect to the Jabber network'
    AUTHOR = 'Mariano Guerra'
    WEBSITE = 'www.emesene.org'

    SERVICES = {
        "gtalk": {
            "host": "talk.google.com",
            "port": "5223"
        },
        "facebook": {
            "host": "chat.facebook.com",
            "port": "5222"
        }
    }

    def __init__(self, id_=None, account=None):
        '''constructor'''
        e3.Session.__init__(self, id_, account)

    def login(self, account, password, status, proxy, host, port, use_http=False):
        '''start the login process'''
        self.account = e3.Account(account, password, status, host)
        self.__worker = Worker('emesene2', self, proxy, use_http)
        self.__worker.start()

        self.add_action(e3.Action.ACTION_LOGIN, (account, password, status,
            host, port))

    def send_message(self, cid, text, style=None, cedict=None, celist=None):
        '''send a common message'''
        if cedict is None:
            cedict = {}

        if celist is None:
            celist = []

        account = self.account.account
        message = e3.Message(e3.Message.TYPE_MESSAGE, text, account,
            style)
        self.add_action(e3.Action.ACTION_SEND_MESSAGE, (cid, message))

    def request_attention(self, cid):
        '''request the attention of the contact'''
        account = self.account.account
        message = e3.Message(e3.Message.TYPE_MESSAGE,
            '%s requests your attention' % (account, ), account)
        self.add_action(e3.Action.ACTION_SEND_MESSAGE, (cid, message))
 def __init__(self):
     Worker.__init__(self, "Worker Buffer Average")
     
     #Specific Class Variables
     self.averagedBuffer = None
     self.bufferIndex = 1
     self.buffers = []
     self.averagedIntensities = None
     
     self.previousName = None
     
     
     #specific ZMQ 
     self.context = zmq.Context()
     self.reply = self.context.socket(zmq.REP)
示例#34
0
 def addWorker(self, peer, multiplexing=False, force=False):
     key = peer.key
     if len(self.workers) > self.getMaxWorkers() and not force:
         return False
     if multiplexing:  # Add even if we already have worker for this peer
         key = "%s/%s" % (key, len(self.workers))
     if key not in self.workers:
         # We dont have worker for that peer and workers num less than max
         worker = Worker(self, peer)
         self.workers[key] = worker
         worker.key = key
         worker.start()
         return worker
     else:  # We have woker for this peer or its over the limit
         return False
示例#35
0
 def addWorker(self, peer, multiplexing=False, force=False):
     key = peer.key
     if len(self.workers) > self.getMaxWorkers() and not force:
         return False
     if multiplexing:  # Add even if we already have worker for this peer
         key = "%s/%s" % (key, len(self.workers))
     if key not in self.workers:
         # We dont have worker for that peer and workers num less than max
         worker = Worker(self, peer)
         self.workers[key] = worker
         worker.key = key
         worker.start()
         return worker
     else:  # We have woker for this peer or its over the limit
         return False
示例#36
0
    def generate_play_thread(self):
        # Declare and connect worker to thread process.
        self.worker = Worker()
        self.thread = QtCore.QThread(parent=self)
        self.worker.moveToThread(self.thread)

        # Assign methods for thread process and signaling to the GUI.
        self.thread.started.connect(
            self.worker.increment_track
        )  # Run increment_track worker method on start.
        self.worker.intReady.connect(
            self.iterate_play
        )  # When work intReady signal propogated call GUI iterate_play method.

        self.thread.start()
示例#37
0
    def __init__(self, new=True):

        self.board = np.empty((8, 8), dtype=object)
        self.player0 = list()
        self.player1 = list()
        if new:
            for j in range(8):
                # player0
                for i in [0, 1]:
                    self.board[(i, j)] = Worker((i, j), 0)
                    self.player0.append(self.board[(i, j)])
                # player1
                for i in [6, 7]:
                    self.board[(i, j)] = Worker((i, j), 1)
                    self.player1.append(self.board[(i, j)])
 def __init__(self, config, **kwargs):
     Worker.__init__(self, "Worker Rolling Average Subtraction")
     
     # variables for pipeline data analysis
     self.config = config
     self.nextPipelineUser = None
     self.nextPipelineExp = None
     self.nextPipelineInput = None
     self.ExperimentFolderOn = config.get("ExperimentFolderOn")
     self.PipelineOn = config.get("PipelineOn")
     
     #Class specific variables
     self.averagedBuffer = None
     self.datFiles = []
     self.datIndex = 1
示例#39
0
    def __init__(self, new=True):

        self.board = np.empty(BOARD_SHAPE, dtype=object)
        self.player0 = list()
        self.player1 = list()
        if new:
            for j in range(BOARD_SHAPE[1]):
                # player0
                for i in [0]:
                    self.board[(i, j)] = Worker((i, j), 0)
                    self.player0.append(self.board[(i, j)])
                # player1
                for i in [4]:
                    self.board[(i, j)] = Worker((i, j), 1)
                    self.player1.append(self.board[(i, j)])
    def __init__(self):
        self.account_endpoint = Configurations.ENDPOINT
        self.account_key = Configurations.ACCOUNT_KEY

        self.regions = Configurations.REGIONS.split(';')

        self.database_name = Configurations.DATABASE_NAME
        self.manual_collection_name = Configurations.MANUAL_COLLECTION_NAME
        self.lww_collection_name = Configurations.LWW_COLLECTION_NAME
        self.udp_collection_name = Configurations.UDP_COLLECTION_NAME
        self.basic_collection_name = Configurations.BASIC_COLLECTION_NAME

        self.workers = []
        self.conflict_worker = ConflictWorker(self.database_name,
                                              self.basic_collection_name,
                                              self.manual_collection_name,
                                              self.lww_collection_name,
                                              self.udp_collection_name)
        self.pool = ThreadPool(processes=len(self.regions))

        for region in self.regions:
            connection_policy = documents.ConnectionPolicy()
            connection_policy.UseMultipleWriteLocations = True
            connection_policy.PreferredLocations = [region]

            client = cosmos_client.CosmosClient(
                self.account_endpoint, {'masterKey': self.account_key},
                connection_policy, documents.ConsistencyLevel.Session)

            self.workers.append(
                Worker(client, self.database_name, self.basic_collection_name))

            self.conflict_worker.add_client(client)
示例#41
0
    def __register_unit(self, unit):
        # if unit.unit_type == bc.UnitType.Healer:
        #     self.robots.append(Healer(self.game_controller, \
        #     self, self.pathfinding_controller, unit, self.mapController))
        # elif unit.unit_type == bc.UnitType.Knight:
        #     self.robots.append(Knight(self.game_controller, \
        #     self, self.pathfinding_controller, unit, self.mapController))
        # elif unit.unit_type == bc.UnitType.Mage:
        #     self.robots.append(Mage(self.game_controller, \
        #     self, self.pathfinding_controller, unit, self.mapController))
        if unit.unit_type == bc.UnitType.Ranger:
            self.robots.append(
                Ranger(self.game_controller, self, self.pathfinding_controller,
                       self.mission_controller, unit, self.mapController))
        elif unit.unit_type == bc.UnitType.Worker:
            self.robots.append(
                Worker(self.game_controller, self, self.pathfinding_controller,
                       self.mission_controller, unit, self.mapController))

        elif unit.unit_type == bc.UnitType.Factory:
            self.structures.append(
                Factory(self.game_controller, self, unit,
                        self.mission_controller))
        elif unit.unit_type == bc.UnitType.Rocket:
            self.structures.append(
                Rocket(self.game_controller, self, unit,
                       self.mission_controller))
        else:
            print("ERROR - Attempting to register an unknown unit type [{}]".
                  format(unit.unit_type))
 def __init__(self):
     Worker.__init__(self, "WorkerRollingAverageSubtraction")
     
     self.subtractedDatIntensities = []
     self.subtractedDatq = []
     self.subtractedErrors = []
     
     self.allIntensities = []
     self.allQ = []
     self.allErrors = []
     
     
     #For adding to be cleared when new user/sample
     self.addToClearList(self.subtractedDatIntensities)
     self.addToClearList(self.subtractedDatq)
     self.addToClearList(self.subtractedErrors)
示例#43
0
class Recommender:

    __coded_docs = None
    __docs = None
    # prepare the datasets
    worker = Worker()

    def get_data_frame(self, matrix):
        df = pd.DataFrame(matrix)
        return df

    def get_document_matrix(self, document_df):
        coded_docs = document_df[["class_year", "school_code", "subject_code"]]
        return coded_docs

    def get_tag_matrix(self, document_df):
        tags = document_df["tags"]
        # vectorise
        tfid_vectorizer = TfidfVectorizer()
        matrix = tfid_vectorizer.fit_transform(tags)

        return matrix

    def calculate_tag_similarity(self, tag, tagMatrix):
        tags_similarity = cosine_similarity(tag, tagMatrix)
        return tags_similarity

    def calculate_document_similarity(self, doc, document_matrix):
        document_similarity = cosine_similarity(doc, document_matrix)

        return document_similarity

    def calculate_recommendations(self):
        product_matrix = self.worker.build_product_matrix()
示例#44
0
    def train(self):
        if args.algorithm == 'random':
            random_agent = RandomAgent(self.game_name, args.max_eps)
            random_agent.run()
            return

        res_queue = Queue()
        print(f'Number of workers: {multiprocessing.cpu_count()}')
        workers = [Worker(self.state_size,
                          self.action_size,
                          self.global_model,
                          self.opt, res_queue,
                          i, game_name=self.game_name,
                          save_dir=self.save_dir) for i in range(multiprocessing.cpu_count())]

        for i, worker in enumerate(workers):
            print("Starting worker {}".format(i))
            worker.start()

        moving_average_rewards = []  # record episode reward to plot
        while True:
            reward = res_queue.get()
            if reward is not None:
                moving_average_rewards.append(reward)
            else:
                break
        [w.join() for w in workers]

        plt.plot(moving_average_rewards)
        plt.ylabel('Moving average ep reward')
        plt.xlabel('Step')
        plt.savefig(os.path.join(self.save_dir,
                                 '{} Moving Average.png'.format(self.game_name)))
        plt.show()
示例#45
0
	def __init__(self):
		
		self.m_oWorker = Worker()
		self.m_oHttpd = Httpd(self.m_oWorker)
		self.m_oGlobs = Globs()
		
		return
示例#46
0
    def wait_for_client(self):
        worker = Worker(self.wait_client_thread)
        worker.signals.result.connect(self.print_output)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)

        self.threadpool.start(worker)
    def wait_for_message(self):
        worker = Worker(self.receive_message)
        worker.signals.result.connect(self.print_output)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.progress.connect(self.progress_fn)

        self.threadpool.start(worker)
示例#48
0
 def __add_worker(self):
     self.__pool_condition.acquire()
     try:
         if len(self.__pool) >= self.__max_thread_num:
             Logger.info("exceed the max_thread_num, add failed")
             self.__pool_condition.wait()
         else:
             worker = Worker(name="worker_" + str(len(self.__pool) + 1),
                             jobs=self.__tasks,
                             task_condition=self.__task_condition)
             self.__pool.append(worker)
             Logger.info("add a worker_" + str(len(self.__pool) + 1))
             worker.start()
             self.__pool_condition.notify()
     finally:
         self.__pool_condition.release()
示例#49
0
 def __init__(self, page_loager, result_filter):
     self._rank_worker = Worker()
     self._page_loader = page_loager
     self._result_filter = result_filter
     self._main_proc_timer = None
     self.__active = False
     self._lock_run = Lock()
     self._shutting_down = False
示例#50
0
文件: server.py 项目: rd2b/tools
def send( alert ):
    logging.info("My alert is : " + str(alert))
    alertobject = Alert( date = alert['Date'],
               sender = alert['Sender'],
               reference = alert['Reference'],
               host = alert['Host'],
               message = alert['Message'],
               priority = alert['Priority'])
    response = SendResponse()
    try:
        myworker = Worker()
        myworker.registeralert(alertobject)
        response._Message = "OK"
    except Exception as error:
        logging.warn("Got error while registering alert")
        logging.info(error)
        response._Message = "KO"
    return response
示例#51
0
文件: server.py 项目: rd2b/tools
def getalerts(Message = None):
    logging.debug("Asking for alerts.")
    response = GetAlertsResponse()
    alerts = Worker.getalerts()
    response._Message = ""
    for alert in alerts:
        response._Message += str(alert) + "\n"
    logging.debug("Sending alerts : " + response._Message)
    return response
    def __init__(self):
        Worker.__init__(self, "WorkerBufferAverage")
        self.allIntensities = []
        self.allErrors = []
        self.allQ = []

        self.avIntensities = []
        self.avErrors = []
        self.avQ = []

        # self.addToClearList(self.allIntensities, self.allErrors, self.allQ)
        self.reply = self.context.socket(zmq.REP)

        # self.sendDataThread = Thread(target=self.sendData())

        self.index = 0

        self.changeInBuffer = True
示例#53
0
文件: Session.py 项目: tiancj/emesene
    def login(self, account, password, status, proxy, host, port , use_http=False, use_ipv6=None):
        '''start the login process'''

        self.account = e3.Account(account, password, status, host)

        self.__worker = Worker('emesene2', self, proxy, use_http)
        self.__worker.start()
        print "add e3.Action.ACTION_LOGIN"
        self.add_action(e3.Action.ACTION_LOGIN, (account, password, status,
            host, port))
示例#54
0
class ExecutorDaemon(BaseHTTPRequestHandler):

    def setUp(self):
        self.worker = Worker(conf_file)
        self.config = self.worker.config
        self.tasks = self.config.sections()
        self.last_tasks = {}

    def do_GET(self):
        self.setUp()
        if '/' == self.path:
            self.send_response(200)
            self.end_headers()
            message = self.index()
            self.wfile.write(message)
            self.wfile.write('\n')
            return

        task = self.path[1:]
        if not task in self.tasks:
            self.send_response(404)
            self.end_headers()
            return
        else:
            message = self.worker.run(task)
            if message is None:
                self.send_response(404)
            else:
                self.send_response(200)
            self.end_headers()
            self.wfile.write(message)
            self.wfile.write('\n')
        return

    def index(self):
        content = ""
        content = '<ul class="list-group">'
        content = '</ul>'
        label = 'label-default'
        for task in self.tasks:
            title = self.config.get(task, "sinker.title")
            if 'mana' in task.lower():
                label = 'label-primary'
            elif 'native' in task.lower():
                label = 'label-success'
            elif 'ssp' in task.lower():
                label = 'label-default'
            content += '<li class="list-group-item">'
            content += ('<tab><a href="/' + task + '">' + title + '</a></tab>')
            content += ('<span class="label ' + label + ' label-pill pull-xs-right">' + task + '</span>')
            content += '</li>'
        return '<html><head><link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"><style type="text/css">tab{padding-left: 1em;padding-right: 6em;}</style></head><body>' +  content + '</body></html>'
示例#55
0
文件: Session.py 项目: AmiZya/emesene
    def login(self, account, password, status, proxy, host, port,
              use_http=False, use_ipv6=False):
        '''start the login process'''
        self.__worker = Worker(self, proxy, use_http, use_ipv6)
        self.__worker.start()

        # msn password must have 16 chars max.
        password = password[:16]

        self.account = e3.Account(account, password, status, host)

        self.add_action(e3.Action.ACTION_LOGIN, (account, password, status,
            host, port))
示例#56
0
 def testRAT_nolimitation(self):
     my_profile = ResourceLimitation(0, 0, 0)
     my_worker = Worker(my_profile, self.tasks)
     # -----
     while True:
         if my_worker.pre_process():
             string2debug = my_worker.check_status()
             print "\t", string2debug
             my_worker.process()
             my_worker.post_process()
         else:
             string2debug = my_worker.check_status()
             print "\t", string2debug
             break
     self.assertEqual(string2debug,
                      ('9', '27', '',
                       "[('A', 6), ('C', 6), ('B', 8), ('D', 8), ('E', 9)]"))
示例#57
0
 def testRAT_max_concurrent_1(self):
     my_profile = ResourceLimitation(1, 0, 0)
     my_worker = Worker(my_profile, self.tasks)
     string2debug = my_worker.check_status()
     self.assertEqual(string2debug, ('0', '0', '', '[]'))
     # -----
     while True:
         if my_worker.pre_process():
             my_worker.process()
             my_worker.post_process()
         else:
             break
     string2debug = my_worker.check_status()
     print string2debug
     self.assertEqual(string2debug,
                      ('37', '9', '',
                       "[('A', 6), ('B', 14), ('C', 20), "
                       "('D', 28), ('E', 37)]"))
示例#58
0
 def testRAT_max_concurrent_4(self):
     my_profile = ResourceLimitation(4, 0, 0)
     my_worker = Worker(my_profile, self.tasks)
     # -----
     while True:
         if my_worker.pre_process():
             my_worker.process()
             my_worker.post_process()
         else:
             break
     string2debug = my_worker.check_status()
     print string2debug
     self.assertEqual(string2debug,
                      ('15', '22', '',
                       "[('A', 6), ('C', 6), ('B', 8), "
                       "('D', 8), ('E', 15)]"))
示例#59
0
class Ranker(object):
    def __init__(self, page_loager, result_filter):
        self._rank_worker = Worker()
        self._page_loader = page_loager
        self._result_filter = result_filter
        self._main_proc_timer = None
        self.__active = False
        self._lock_run = Lock()
        self._shutting_down = False

    def _get_active(self):
        """active property getter"""
        self._lock_run.acquire()
        ret_value = self.__active
        self._lock_run.release()
        return ret_value

    def _set_active(self, state):
        """active property setter"""
        if type(state) != types.BooleanType:
            raise TypeError("state should be boolean")
        self._lock_run.acquire()
        old_active = self.__active
        self.__active = state
        if not old_active:
            self._main_proc_timer = Timer(1, self._main_proc)
            self._main_proc_timer.start()
        self._lock_run.release()

    def ready_to_shutdown(self):
        return self._page_loader.ready_to_shutdown() and self._rank_worker.ready_to_shutdown()

    def purge_tasks(self, filter_not_match):
        self._rank_worker.purge_tasks(filter_not_match)

    def _main_proc(self):
        """
        Main procedure:
        get page from PageLoader, rank it and give it to ResultFilter
        """
        sleep_time = 1
        page_result = self._page_loader.get_loaded_page()
        # page_result is namedtuple('url, code, info, data, user_data')
        if page_result:
            if page_result.data:
                rw_task = WorkerTask(page_result, ranker_routine, page_result[0])
                self._rank_worker.add_task(rw_task)
            sleep_time = 0
        else:
            pass  # self._result_filter.thresholds[1] -= 1
        rw_completed_task = self._rank_worker.get_completed_task()
        if rw_completed_task:
            self._result_filter.submit_ranker_result(rw_completed_task.result)
            sleep_time = 0
            # print 'Completed!'
        self._lock_run.acquire()
        if self.__active:
            self._main_proc_timer = Timer(sleep_time, self._main_proc)
            self._main_proc_timer.start()
        self._lock_run.release()

    active = property(_get_active, _set_active)
示例#60
0
class Session(e3.Session):
    '''a specialization of e3.base.Session'''
    NAME = 'Papyon session'
    DESCRIPTION = 'MSN session (papyon)'
    AUTHOR = ", ".join(AUTHOR_LIST)
    WEBSITE = 'www.emesene.org'

    SERVICES = {"msn": {"host": "messenger.hotmail.com", "port": "1863"}}

    def __init__(self, id_=None, account=None):
        '''constructor'''
        e3.Session.__init__(self, id_, account)

    def login(self,
              account,
              password,
              status,
              proxy,
              host,
              port,
              use_http=False):
        '''start the login process'''
        self.__worker = Worker('emesene2', self, proxy, use_http)
        self.__worker.start()

        # msn password must have 16 chars max.
        password = password[:16]

        self.account = e3.Account(account, password, status, host)

        self.add_action(e3.Action.ACTION_LOGIN,
                        (account, password, status, host, port))

    def send_message(self, cid, text, style=None, cedict=None, celist=None):
        '''send a common message'''
        if cedict is None:
            cedict = {}

        if celist is None:
            celist = []

        account = self.account.account
        message = e3.Message(e3.Message.TYPE_MESSAGE, text, account, style)
        self.add_action(e3.Action.ACTION_SEND_MESSAGE,
                        (cid, message, cedict, celist))

    def send_typing_notification(self, cid):
        '''send typing notification to contact'''
        account = self.account.account
        message = e3.Message(e3.Message.TYPE_TYPING, None, account)
        self.add_action(e3.Action.ACTION_SEND_MESSAGE, (cid, message))

    def request_attention(self, cid):
        '''request the attention of the contact'''
        account = self.account.account
        message = e3.Message(e3.Message.TYPE_NUDGE, None, account)
        self.add_action(e3.Action.ACTION_SEND_MESSAGE, (cid, message))

    def conversation_invite(self, cid, account):
        '''invite a contact to a conversation'''
        self.add_action(e3.Action.ACTION_CONV_INVITE, (cid, account))

    def filetransfer_invite(self, cid, account, filename, completepath,
                            preview_data):
        '''send a file to the first user of the conversation'''
        self.add_action(e3.Action.ACTION_FT_INVITE,
                        (cid, account, filename, completepath, preview_data))

    def call_invite(self, cid, account, a_v_both, surface_other, surface_self):
        '''try to start a call with the first user of the conversation'''
        self.add_action(e3.Action.ACTION_CALL_INVITE,
                        (cid, account, a_v_both, surface_other, surface_self))

    def get_worker(self):
        return self.__worker

    def get_profile(self):
        return self.__worker.profile

    # methods for the privacy tab
    def get_blocked_contacts(self):
        '''return a list containing the contacts in the address book with the
        BLOCK flag set'''
        contacts = self.__worker.address_book.contacts
        return [c.account for c in contacts if (Membership.BLOCK & c.memberships) and \
                ((Membership.FORWARD & c.memberships) or (Membership.REVERSE & c.memberships))]

    def get_allowed_contacts(self):
        '''return a list containing the contacts in the address book with the
        ALLOW flag set'''
        contacts = self.__worker.address_book.contacts
        return [c.account for c in contacts if (Membership.ALLOW & c.memberships) and \
                ((Membership.REVERSE & c.memberships) or (Membership.FORWARD & c.memberships))]

    def is_only_reverse(self, account):
        '''return True if the contact has set the REVERSE flag and not the
        FORWARD flag; otherwise False.
        This means, contacts that are not in your contact list but they do have
        you'''
        contacts = self.__worker.address_book.contacts.search_by(
            'account', account)

        if len(contacts) == 0:
            return False

        return (Membership.REVERSE & contacts[0].memberships) and \
                not (Membership.FORWARD & contacts[0].memberships)

    def is_only_forward(self, account):
        '''return True if the contact has set the FORWARD flag and not the
        REVERSE flag; otherwise False.
        This means, contacts that are in your contact list but they don't have
        you'''
        contacts = self.__worker.address_book.contacts.search_by(
            'account', account)

        if len(contacts) == 0:
            return False

        return (Membership.FORWARD & contacts[0].memberships) and \
                not (Membership.REVERSE & contacts[0].memberships)

    def is_forward(self, account):
        '''return True if the contact has set the FORWARD flag; otherwise False'''
        contacts = self.__worker.address_book.contacts.search_by(
            'account', account)

        if len(contacts) == 0:
            return False

        return (Membership.FORWARD & contacts[0].memberships)