예제 #1
0
    def shake_tree_sap(self, mode=None):
        elem = TaskTree.get_sq_len()
        for i in range(1, elem + 1):  # get a task to assign
            sq = TaskTree.get_sq_elem()  # get a task to assign
            print 'shake_tree: NewQlen=' + str(elem) + 'Task got is ' + str(sq)
            wid = wm.W.assign(
                'sap', sq[1])  # Get a free worker to do the task picked above
            if (wid):
                ws = wm.W.get_socket(wid)
                # ws.write_message('Shruthi-try')
                msg = ws.fill_msg_wsh(sq[1], mode='sap')
                print 'Sending a msg to show task ' + str(
                    sq[1]) + 'to worker ' + wid
                #print 'Socket of wid is ' + str(ws.workerId)

                #important step for sending ready msgs:
                #hide the mode of the message in preference to know
                #what content to preview to worker.
                msg['preference'] = msg['mode']
                msg['mode'] = "ready"

                send_task(msg)
                #todo:msg = ws.fill_msg_wsh(sq[1])
            else:
                print 'Warning - no workers'
                TaskTree.add_to_sq(sq[0],
                                   sq[1])  # Put the task back in the queue
                break
예제 #2
0
    def on_close(self):
        print "Closing socket for" + self.workerId

        #abandon current task:
        TID = wm.W.get_TID(self.workerId)
        if (TID is not False):
            print "aborting task: ", TID

            if (TaskTree[TID].status == 'sap'):
                TaskTree.add_to_sq(0, TID)
            else:
                TaskTree.add_to_q(0, TID)
            wm.W.complete(self.workerId, False)
            #NOTE!!! may want to add dynamically changing priority

        t_amt.delete_amt_hit(self.hitId)

        wm.W.logout(self.workerId)
예제 #3
0
 def fill_msg_wsh(self, tid, mode='ready'):
     msg = tms.new_msg()
     msg = copy.deepcopy(TaskTree.getmsgcp(tid))
     msg['WID'] = self.workerId
     msg['preference'] = self.preference
     #msg['time_start']   = self.time_stamp
     msg['profile'] = self.profile
     msg['mode'] = mode
     print "Sending to ws of worker " + msg['WID']
     return msg
예제 #4
0
 def select_callback(self, msg):
     wm.W.set_type(self.workerId, msg['preference'])
     self.preference = msg['preference']
     self.send_msg(tms.new_msg(mode="idle", WID=self.workerId,
                               TID=""))  #fill in params more completely
     print "select callback shake starts"
     len = TaskTree.get_q_len()  # Tasks available ?
     self.shake_tree()  # Look to match more work and tasks
     self.shake_tree_sap()
     print "select callback shake returns"
예제 #5
0
    def shake_tree(self, mode=None):
        elem = TaskTree.get_q_len()
        for i in range(1, elem + 1):  # get a task to assign
            tq = TaskTree.get_q_elem()  # get a task to assign
            if (TaskTree[tq[1]].status != "idle"):
                continue

            print 'shake_tree: NewQlen=' + str(elem) + 'Task got is ' + str(tq)

            if (TaskTree[tq[1]].type == 'leaf'):
                wid = wm.W.assign('leaf', tq[1])
                is_leafer = True
            else:
                wid = wm.W.assign('branch', tq[1])
                is_leafer = False

            if (wid):
                ws = wm.W.get_socket(wid)
                # ws.write_message('Shruthi-try')
                if (is_leafer):
                    msg = ws.fill_msg_wsh(tq[1], 'leaf')
                else:
                    msg = ws.fill_msg_wsh(tq[1], 'branch')

                print 'Sending a msg to show task ' + str(
                    tq[1]) + 'to worker ' + wid
                #print 'Socket of wid is ' + str(ws.workerId)

                #important step for sending ready msgs:
                #hide the mode of the message in preference to know
                #what content to preview to worker.
                msg['preference'] = msg['mode']
                msg['mode'] = "ready"

                send_task(msg)
                #todo:msg = ws.fill_msg_wsh(tq[1])
            else:
                print 'Warning - no workers'
                TaskTree.add_to_q(tq[0],
                                  tq[1])  # Put the task back in the queue
예제 #6
0
    def get(self):
        tid = uuid.uuid4().hex
        TaskTree.add_node(tid)
        workerId = self.get_argument("workerId", None)
        assignmentId = self.get_argument("assignmentId", None)
        hitId = self.get_argument("hitId", None)
        turkSubmitTo = self.get_argument("turkSubmitTo", None)

        if (workerId is None or hitId is None or assignmentId is None
                or turkSubmitTo is None):
            self.write("some bad stuff happened on the way to the hit page.")
            self.render("404.html")
            return

        self.render("hit.html",
                    workerId=workerId,
                    assignmentId=assignmentId,
                    hitId=hitId,
                    turkSubmitTo=turkSubmitTo + "/mturk/externalSubmit",
                    url_prefix=ts.URL_PREFIX,
                    port=ts.PORT,
                    local_testing=ts.LOCAL_TESTING)
예제 #7
0
    def ready_callback(self, msg):
        if (TaskTree[msg['TID']].status == 'sap'):
            mode = 'sap'
        else:
            mode = msg['preference']

        print "pref:", msg['ready_flag']
        if (msg['ready_flag'] == "accept"):
            # #increase idle time
            # mins = (msg['time_end']-msg['time_start']).total_seconds() / float(60)
            # print "adding idle mins:", mins
            # wm.W.addIdleTime(self.workerId,mins)

            if (mode == 'sap'):
                TaskTree[msg['TID']].add_sapwid(self.workerId)
            else:
                TaskTree[msg['TID']].add_wid(self.workerId)

            print "ACCEPTED, mode:", mode
            msg['mode'] = mode
            send_task(msg)

        else:
            print "declined"
            msg['mode'] = 'idle'
            send_task(msg)
            if (mode == 'sap'):
                TaskTree.add_to_sq(0, msg['TID'])
                self.shake_tree_sap()
            else:
                TaskTree.add_to_q(0, msg['TID'])
                self.shake_tree()

            wm.W.complete(self.workerId, None)

        print "ready callback"  #???
예제 #8
0
	def post(self):
		msg=self.get_argument(name="TaskInfo",default=None)
		Budget=self.get_argument(name="Budget")
		if Budget.isdigit():
			Budget=float(Budget)
		else:
			self.write('Enter Valid Inputs')
		
		# Check to see if new task was created
		if self.get_argument(name="NewTask",default=None):
			if(TaskTree.set_requestTask(msg,Budget)!=False):
				self.write('Request Submitted. Press back and logout')
			else:
				self.write('Request Being Processed. Come Back Later For Results.')
		
		# Check if Logout Button Was Pressed
		if self.get_argument("logout",None):
			self.redirect(ts.URL_PREFIX+"/logout")
		if self.get_argument("login",None):
			self.redirect(ts.URL_PREFIX+"/login")
예제 #9
0
    def process_approval(self, msg):
        child = TaskTree[
            msg['super_task_id']]  #might be incorrectly using supertaskid
        if (msg['super_approve'] == False
            ):  #rejected, set worker and task idle
            child.status = 'idle'
            wm.W.complete(child.wid, False)
            msg['mode'] = 'idle'
            msg['WID'] = child.wid
            send_task(msg)
            TaskTree.add_to_q(0, child.id)
        else:  #approved
            child.status = 'approved'
            if (child.type == 'leaf'):  #release leaf to idle & complete
                child.sapify_leaf()
                wm.W.complete(child.wid, True)
                msg['mode'] = 'idle'
                msg['WID'] = child.wid
                send_task(msg)
                #tell parent to try to sap
                TaskTree.update_sap(child)
            else:  #tell brancher to go super
                TaskTree.generate_branches(
                    msg, child.id)  #generate branches of worker
                msg['super_mode'] = 'idle'
                msg['mode'] = 'super'
                msg['WID'] = child.wid
                send_task(msg)

        #if(TaskTree.is_root(child.id) is False):
        parent = TaskTree[msg['TID']]

        if (TaskTree.finished_supervision(parent.id)):
            parent.state = 'sap'  #is this too early? we want someone to come along adn sap this now
            wm.W.complete(parent.wid, True)
            msg['mode'] = 'idle'
        else:
            msg['super_mode'] = 'idle'
            msg['mode'] = 'super'

        msg['WID'] = parent.wid
        send_task(msg)
예제 #10
0
    def task_callback(self, msg):
        if (TaskTree.is_root(msg['TID']) is True):
            if (TaskTree[msg['TID']].status == 'sap'):
                TaskTree.process_sap(msg)
                wm.W.complete(msg['WID'], True)
                msg['mode'] = 'idle'
                send_task(msg)
            else:
                TaskTree[msg['TID']].status = 'sap'
                TaskTree[msg['TID']].add_wid(self.workerId)
                msg['super_approve'] = True
                msg['super_task_id'] = msg['TID']
                TaskTree.save_results(msg)
                self.process_approval(msg)

        elif (msg['mode'] != 'sap'):
            try:
                TaskTree.ask_approval(msg)  # send msg to parent to approve
            except:
                #our super probably left... just approve it.
                TaskTree[msg['TID']].status = 'sap'
                msg['super_approve'] = True
                msg['super_task_id'] = msg['TID']
                TaskTree.save_results(msg)
                self.process_approval(msg)

            TaskTree.save_results(msg)  # save results of the task
        else:
            TaskTree.process_sap(msg)
            wm.W.complete(msg['WID'], True)
            msg['mode'] = 'idle'
            send_task(msg)

            #MISSING IDLE TIME FUNCTIONALITY!!!
        #keep this around... maybe
        #if(task_approved):
        #increase active time
        # mins = (msg['time_end']-msg['time_start']).total_seconds() / float(60)
        # print "adding active mins:", mins
        # wm.W.addActiveTime(self.workerId,mins)

        self.shake_tree()
        self.shake_tree_sap()

        print "task callback"