コード例 #1
0
ファイル: apps.py プロジェクト: PyBossa/pybossa-apps
    def GET(self, app_name):
        app = _get_app(app_name)
        taskruns = pbclient.get_taskruns(app.id, limit=3000)
        taskruns_by_id = {}
        self.sdsd = ''

        for taskrun in taskruns:
            if taskrun.task_id not in taskruns_by_id:
                taskruns_by_id[taskrun.task_id] = 0
            taskruns_by_id[taskrun.task_id] += 1
        tasks = pbclient.get_tasks(app.id, limit=1000)
        task_status = {}
        taskruns_needed = 0
        taskruns_finished = 0
        for task in tasks:
            num_taskruns = 0
            if task.id in taskruns_by_id:
                num_taskruns = taskruns_by_id[task.id]
            task_status[task.id] = (num_taskruns, task.info['n_answers'])
            taskruns_needed += task.info['n_answers']
            taskruns_finished += min(task.info['n_answers'], num_taskruns)
        result = {
            'num_tasks': len(tasks),
            'task_status': task_status,
            'taskruns_needed': taskruns_needed,
            'taskruns_finished': taskruns_finished
        }
        return json.dumps(result)
コード例 #2
0
def create_tasks(engine):
    log.info("Updating tasks on pyBossa...")
    app = setup()
    with flask_app.open_resource('resources/pbnetworks_template.html') as f:
        app.info['task_presenter'] = f.read()
        pbclient.update_app(app)
    tasks = pbclient.get_tasks(app.id, limit=30000)
    existing = dict([(t.data.get('info').get('signature'), t) for t in tasks])
    for rep in sl.all(engine, sl.get_table(engine, 'representative')):
        networking = rep.get('networking')
        if networking is None or len(networking.strip()) < 3:
            continue
        signature = rep.get('identification_code') + networking
        signature = sha1(signature.encode('ascii', 'ignore')).hexdigest()
        rep['signature'] = signature
        print [rep.get('name')]
        log.debug("Task: %s", rep['name'])
        rep['last_update_date'] = rep['last_update_date'].isoformat()
        rep['registration_date'] = rep['registration_date'].isoformat()
        #print [(k, type(v)) for k,v in rep.items()]
        if signature in existing:
            task = existing.get(signature)
            task.data['info'] = rep
            pbclient.update_task(task)
        else:
            pbclient.create_task(app.id, rep)
コード例 #3
0
 def setUp(self):
     self.app = Apptt_select(short_name="sh_tt1", title="title1")
     self.app.add_task(task_info={"info1":1, "info2":2})
     self.app.add_task(task_info={"info3":3, "info4":4})
     
     tasks = pbclient.get_tasks(app_id=self.app.app_id)
     
     self.pb_task1 = pb_task(tasks[0].id, app_short_name=self.app.short_name)
     self.pb_task2 = pb_task(tasks[1].id, app_short_name=self.app.short_name)
コード例 #4
0
 def tasks(app):
     offset = 0
     limit = 100
     while True:
         tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
         if len(tasks) == 0:
             break
         for task in tasks:
             yield task
         offset += len(tasks)
コード例 #5
0
 def tasks(app):
     offset = 0
     limit = 100
     while True:
         tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
         if len(tasks) == 0:
             break
         for task in tasks:
             yield task
         offset += len(tasks)
コード例 #6
0
 def tasks():
     offset = 0
     limit = 100
     while True:
         tasks = self.handle_result(pbclient.get_tasks(self.app.id, offset=offset, limit=limit))
         if len(tasks) == 0:
             break
         for task in tasks:
             yield task
         offset += len(tasks)
コード例 #7
0
ファイル: createTasks.py プロジェクト: megansb/lostatnight
 def tasks(app):
     offset = 0
     limit = 100
     while True:
         try:
             tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
             check_api_error(tasks)
             if len(tasks) == 0:
                 break
             for task in tasks:
                 yield task
             offset += len(tasks)
         except:
             format_error("pbclient.get_tasks", response)
コード例 #8
0
 def tasks(app):
     offset = 0
     limit = 100
     while True:
         try:
             tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
             check_api_error(tasks)
             if len(tasks) == 0:
                 break
             for task in tasks:
                 yield task
             offset += len(tasks)
         except:
             format_error("pbclient.get_tasks", response)
コード例 #9
0
    def _get_existing_tasks(self):
        project_id = self.project_id
        tasks = []
        limit = 100

        while True:
            last_id = tasks[-1].id if tasks else None
            response = pbclient.get_tasks(project_id, limit=limit, last_id=last_id)

            if not response:
                break

            if not self._wait_if_reached_rate_limit(response):
                tasks.extend(response)

        logger.debug('{} tasks on the server'.format(len(tasks)))
        return tasks
コード例 #10
0
    def create_msg_task(app, msg, question):
        # Data for the tasks
        # msgs_text and msgs_html are lists, hence 'msgs' not 'msg'.
        # msg_subject and msg_date are simple strings.
        task_info = dict(question=question,
                         n_answers=options.n_answers,
                         msgs_text=msg['msgs_text'],
                         msgs_html=msg['msgs_html'],
                         msg_subject=msg['msg_subject'],
                         msg_date=msg['msg_date'])

        print task_info['msg_subject']
        print len(pbclient.get_tasks(app.id))

        # from erpy.ipshell import ipshell
        # ipshell('here')
        # sys.exit()
        # return

        pbclient.create_task(app.id, task_info)
コード例 #11
0
    def create_msg_task(app, msg, question):
        # Data for the tasks
        # msgs_text and msgs_html are lists, hence 'msgs' not 'msg'.
        # msg_subject and msg_date are simple strings.
        task_info = dict(question=question,
                         n_answers=options.n_answers,
                         msgs_text=msg['msgs_text'],
                         msgs_html=msg['msgs_html'],
                         msg_subject=msg['msg_subject'],
                         msg_date=msg['msg_date'])

        print task_info['msg_subject']
        print len(pbclient.get_tasks(app.id))

        # from erpy.ipshell import ipshell
        # ipshell('here')
        # sys.exit()
        # return

        pbclient.create_task(app.id, task_info)
コード例 #12
0
    if options.update_template:
        print "Updating app template"
        app = pbclient.find_app(short_name=app_config['short_name'])[0]
        app.long_description = open('long_description.html').read()
        app.info['task_presenter'] = open('template.html').read()
        app.info['tutorial'] = open('tutorial.html').read()
        pbclient.update_app(app)

    if options.update_tasks:
        print "Updating task n_answers"
        app = pbclient.find_app(short_name=app_config['short_name'])[0]
        n_tasks = 0
        offset = 0
        limit = 100
        tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
        while tasks:
            for task in tasks:
                print "Updating task: %s" % task.id
                if ('n_answers' in task.info.keys()):
                    del (task.info['n_answers'])
                task.n_answers = int(options.update_tasks)
                pbclient.update_task(task)
                n_tasks += 1
            offset = (offset + limit)
            tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
        print "%s Tasks have been updated!" % n_tasks


    if not options.create_app and not options.update_template\
            and not options.add_more_tasks and not options.update_tasks:
コード例 #13
0
            photos = get_flickr_photos()
            question = "Do you see a human in this photo?"
            [create_photo_task(app, p, question) for p in photos]

    if options.update_template:
        print "Updating app template"
        # discard return value
        setup_app()

    if options.update_tasks:
        print "Updating task n_answers"
        app = find_app_by_short_name()
        n_tasks = 0
        offset = 0
        limit = 100
        tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
        while tasks:
            for task in tasks:
                print "Updating task: %s" % task.id
                if "n_answers" in task.info.keys():
                    del (task.info["n_answers"])
                task.n_answers = int(options.update_tasks)
                pbclient.update_task(task)
                n_tasks += 1
            offset = offset + limit
            tasks = pbclient.get_tasks(app.id, offset=offset, limit=limit)
        print "%s Tasks have been updated!" % n_tasks

    if (
        not options.create_app
        and not options.update_template
コード例 #14
0
                                 url_b=photo['url_b'])
                pbclient.create_task(app.id, task_info)

    else:
        if options.add_more_tasks:
            for photo in photos:
                task_info = dict(question="Do you see a human in this photo?",
                                 n_answers=int(options.n_answers),
                                 link=photo['link'],
                                 url_m=photo['url_m'],
                                 url_b=photo['url_b'])
                pbclient.create_task(app.id, task_info)

    if options.update_template:
        print "Updating app template"
        app = pbclient.find_app(short_name='flickrperson')[0]
        app.long_description = open('long_description.html').read()
        app.info['task_presenter'] = open('template.html').read()
        pbclient.update_app(app)

    if options.update_tasks:
        print "Updating task question"
        app = pbclient.find_app(short_name='flickrperson')[0]
        for task in pbclient.get_tasks(app.id):
            task.info['question'] = u'Ves un humano?'
            pbclient.update_task(task)

    if not options.create_app and not options.update_template\
            and not options.add_more_tasks and not options.update_tasks:
        parser.error("Please check --help or -h for the available options")
コード例 #15
0
                            url_m=photo['url_m'],
                            url_b=photo['url_b'])
                pbclient.create_task(app.id, task_info)

    else:
        if options.add_more_tasks:
            for photo in photos:
                task_info = dict(question="Do you see a human in this photo?",
                            n_answers=int(options.n_answers), link=photo['link'],
                            url_m=photo['url_m'],
                            url_b=photo['url_b'])
                pbclient.create_task(app.id, task_info)

    if options.update_template:
        print "Updating app template"
        app = pbclient.find_app(short_name='flickrperson')[0]
        app.long_description = open('long_description.html').read()
        app.info['task_presenter'] = open('template.html').read()
        pbclient.update_app(app)

    if options.update_tasks:
        print "Updating task question"
        app = pbclient.find_app(short_name='flickrperson')[0]
        for task in pbclient.get_tasks(app.id):
            task.info['question'] = u'Ves un humano?'
            pbclient.update_task(task)

    if not options.create_app and not options.update_template\
            and not options.add_more_tasks and not options.update_tasks:
        parser.error("Please check --help or -h for the available options")