Beispiel #1
0
 def convert(self, raw_data):
     raw_data_s = utilities.s(raw_data)
     if raw_data == utilities.u('n/a'):
         return 0
     elif raw_data == utilities.u('< 1 year'):
         return 1
     elif raw_data == utilities.u('10+ years'):
         return 11
     return int(raw_data[0]) + 1
Beispiel #2
0
    def setup_zmq(self):

        # Initialize a zeromq context
        self.context = utilities.zmq.Context()

        # Set up a channel to receive work from the ventilator
        self.work_receiver = self.context.socket(utilities.zmq.PULL)
        self.work_receiver.connect("tcp://127.0.0.1:5557")

        # Set up a channel to send result of work to the results reporter
        self.results_sender = self.context.socket(utilities.zmq.PUSH)
        self.results_sender.connect("tcp://127.0.0.1:5558")

        # Set up a channel to receive control messages over
        self.control_receiver = self.context.socket(utilities.zmq.SUB)
        self.control_receiver.connect("tcp://127.0.0.1:5559")
        self.control_receiver.setsockopt_string(utilities.zmq.SUBSCRIBE, utilities.u(""))

        # Set up a poller to multiplex the work receiver and control receiver channels
        self.poller = utilities.zmq.Poller()
        self.poller.register(self.work_receiver, utilities.zmq.POLLIN)
        self.poller.register(self.control_receiver, utilities.zmq.POLLIN)

        # Send a message that we are done with the setup and ready to receive work
        answer_message = dict(worker=self.worker_idx, message='READY')
        self.results_sender.send_json(answer_message)
Beispiel #3
0
    def calculate(self, min_work_messages=100):
        citizen_idx = 0

        # Bundle up the filters
        work_messages = []

        for citizen in self.population:

            filter_values = [
                citizen['filters'][i].current for i in self.range_filters
            ]

            work_messages.append((citizen_idx, filter_values))

            if len(work_messages) >= int(min_work_messages):
                self.ventilator_send.send_json(work_messages)
                work_messages = []

            # citizen['results'] = self.lcbt.test(citizen['filters'])
            # sys.stdout.write('.')

            citizen_idx += 1

        # Send the tail
        if work_messages:
            self.ventilator_send.send_json(work_messages)

        # Send control message to signal sending back the results
        self.control_sender.send_unicode(utilities.u("SEND_RESULTS"))
        results_receiver = self.results_receiver
        for _ in range(self.args.workers):
            results_message = results_receiver.recv_json()
            self.debug_msg(
                "Worker[%i] returned %d results" %
                (results_message['worker'], len(results_message['results'])))
            for citizen_idx, result in results_message['results']:
                # sys.stderr.write("results[%d]=%s\n" % (citizen_idx, result))
                self.population[citizen_idx]['result'] = result
        self.info_msg('calculate() complete')
Beispiel #4
0
    def calculate(self, min_work_messages=100):
        citizen_idx = 0

        # Bundle up the filters
        work_messages = []

        for citizen in self.population:

            filter_values = [citizen['filters'][i].current for i in self.range_filters]

            work_messages.append((citizen_idx, filter_values))

            if len(work_messages) >= int(min_work_messages):
                self.ventilator_send.send_json(work_messages)
                work_messages = []

            # citizen['results'] = self.lcbt.test(citizen['filters'])
            # sys.stdout.write('.')

            citizen_idx += 1

        # Send the tail
        if work_messages:
            self.ventilator_send.send_json(work_messages)

        # Send control message to signal sending back the results
        self.control_sender.send_unicode(utilities.u("SEND_RESULTS"))
        results_receiver = self.results_receiver
        for _ in range(self.args.workers):
            results_message = results_receiver.recv_json()
            self.debug_msg("Worker[%i] returned %d results" %
                           (results_message['worker'], len(results_message['results'])))
            for citizen_idx, result in results_message['results']:
                # sys.stderr.write("results[%d]=%s\n" % (citizen_idx, result))
                self.population[citizen_idx]['result'] = result
        self.info_msg('calculate() complete')
Beispiel #5
0
    def run(self):
        GATest.run(self)

        # Signal to all workers that we are finished
        self.control_sender.send_unicode(utilities.u("FINISHED"))