Example #1
0
def send_data():
    api_key = request.json.get('api_key')
    server_url = request.json.get('server_url')
    data = request.json.get('data')
    project_name = request.json.get('project_name')

    tpl_presenter = render_template('presenter.html',
                                    steps=data['steps'],
                                    project_name=project_name)

    pbclient.set('endpoint', server_url)
    pbclient.set('api_key', api_key)

    # TODO: check error
    app = pbclient.find_app(short_name=project_name)[0]
    app.info['task_presenter'] = tpl_presenter

    for task in pbclient.find_tasks(app.id):
        pbclient.delete_task(task.id)

    for task in data['tasks']:
        pbclient.create_task(app.id, task)

    pbclient.update_app(app)

    return '', 200
Example #2
0
def getLastTaskrun():
    task_id = json.loads( request.data )    
    app_id = pbclient.find_app( short_name = "librasdictionary" )[0].id
    taskruns_for_task_id = pbclient.find_taskruns( app_id, task_id = task_id )
    if len( taskruns_for_task_id ) != 0:
        return jsonify( lastTaskrun = taskruns_for_task_id[-1].info )
    return jsonify( lastTaskrun = None )
Example #3
0
 def find_app_by_short_name():
     try:
         response = pbclient.find_app(short_name=app_config['short_name'])
         check_api_error(response)
         return response[0]
     except:
         format_error("pbclient.find_app", response)
Example #4
0
 def find_app_by_short_name():
     try:
         response = pbclient.find_app(short_name=app_config['short_name'])
         check_api_error(response)
         return response[0]
     except:
         format_error("pbclient.find_app", response)
Example #5
0
 def POST(self):
     global last_status
     data = web.input()
     last_status = '<p>Connecting to PyBossa <i class="loading"></i></p>'
     # check endpoint and api_key
     pbclient.set('endpoint', data.endpoint)
     pbclient.set('api_key', data.api_key)
     app = pbclient.find_app(short_name=data.appname)
     if len(app) == 0:
         last_status += '<p class="error" data-field="appname">PyBossa app not found.</p>'
     else:
         app = app[0]
         res = pbclient.update_app(app)
         if res == 403:
             last_status += '<p class="error" data-field="api_key">You\'re not allowed to edit that app. Double check your API key.</p>'
         else:
             last_status += '<p>Loading data from Google spreadsheet <i class="loading"></i></p>'
             url = 'http://spreadsheets.google.com/feeds/cells/%s/%s/public/basic?alt=json' % (data.spreadsheet, data.worksheet)
             r = requests.get(url)
             if r.status_code / 100 == 4:
                 last_status += '<p class="error" data-field="spreadsheet">The spreadsheet could not be found. Make sure that the key is right and that you properly shared the document (click on <i>File > Publish to the web</i>).</p>'
             else:
                 last_status += '<p>Parsing spreadsheet data <i class="loading"></i></p>'
                 tasks = parse_spreadsheet(r.json)
                 tmp = last_status
                 total = len(tasks)
                 completed = 0
                 for info in tasks:
                     info['n_answers'] = int(data.n_answers)
                     res = pbclient.create_task(app.id, info)
                     completed += 1
                     last_status = tmp + '<p>Uploading tasks to PyBossa (%d of %d)<i class="loading"></i></p>' % (completed, total)
                 last_status += '<p>finished.</p>'
     print ''
Example #6
0
def _get_app(app_name):
    global _pybossa_application_cache
    if app_name in _pybossa_application_cache:
        return _pybossa_application_cache[app_name]
    app = pbclient.find_app(short_name=app_name)[0]
    _pybossa_application_cache[app_name] = app
    return app
def push_presenter():
    html = open('presenter.html').read()

    app = pbclient.find_app(short_name=config.APP)[0]

    app.info['task_presenter'] = html
    app.info['sched'] = 'default'
    pbclient.update_app(app)
 def find_app_by_short_name():
     try:
         print "app_config['short_name']"
         print app_config['short_name']
         response = pbclient.find_app(short_name=app_config['short_name'])
         #check_api_error(response)
         print response
         return response[0]
     except:
         format_error("pbclient.find_app", response)
Example #9
0
def validateTask():
    task_info = json.loads( request.data )

    app_id = pbclient.find_app( short_name = "librasdictionary" )[0].id

    # sets the task as completed
    requests.put( "%s/api/task/%s?api_key=%s" % 
                 ( "http://localhost:8080/pybossa", task_info["task_id"], "53b8465d-91b0-4286-b2d8-834fbd89e194" ), 
                 data = json.dumps( dict( state = "completed" ) ) )

    return jsonify( resultado = None )
def validateTask():
    task_info = json.loads( request.data )

    app_id = pbclient.find_app( short_name = "librasdictionary" )[0].id

    # sets the task as completed
    requests.put( "%s/api/task/%s?api_key=%s" % 
                 (PYBOSSA_ENDPOINT, task_info["task_id"], PYBOSSA_API_KEY), 
                 data = json.dumps( dict( state = "completed" ) ) )

    return jsonify( resultado = None )
def userReport():
    info = json.loads( request.data )
    current_user_id = info["current_user_id"]
    app_id = pbclient.find_app( short_name = "librasdictionary" )[0].id
    current_user_ip = getUserIp();
    all_task_runs = getAllTaskRuns( app_id ) 
    # TODO comparar a quantidade de tarefas disponiveis com a quantidade de tarefas completas

    user_task_runs = dict()
    user_task_runs_amount = 0
    user_signs = dict()
    signs_validated = list()
    signs_improved = list()
    users_amount = 0
    comunity_average = 0
    user_average = 0
    overall_progress = getOverallProgress( app_id )
    last_time = "Nunca"
    if( len( all_task_runs ) > 0 ):
        user_task_runs = getUserTaskRuns( app_id, current_user_id, current_user_ip )
        user_signs = getUserSigns( user_task_runs )
        user_task_runs_amount = len( user_task_runs ) - len( user_signs['skips'] )        
        users_amount = getUsersAmount( all_task_runs )
        all_task_runs_amount = len( all_task_runs )
        
        if ( users_amount ) == 1:
            comunity_average = all_task_runs_amount
        else:
            comunity_average = ( all_task_runs_amount - user_task_runs_amount ) / ( float( users_amount - 1 ) )

        user_average = round( user_task_runs_amount / float( comunity_average ), 2 )
        
        if ( user_average < 0.5 ) and ( user_task_runs_amount != 0 ):
            user_average = 1
        elif user_average >= 0.5 and user_average < 1:
            user_average = 1 + user_average
        elif user_average >= 1 and user_average < 1.5:
            user_average = 2 + (user_average - 1)
        elif user_average >= 1.5:
            user_average = 3

        comunity_average = round( comunity_average, 2 )

        if ( user_task_runs_amount > 0 ):
            last_time = user_task_runs[-1].finish_time.split("T")[0]
 
        signs_validated = getSignsValidated( all_task_runs )

        signs_improved = getSignsImproved( all_task_runs )

    return jsonify( user_signs = user_signs, signs_validated = signs_validated, signs_improved = signs_improved, last_time = last_time, overall_progress = overall_progress, user_average = user_average, user_task_runs_amount = user_task_runs_amount, comunity_average = comunity_average )
Example #12
0
def setup():
    # settings
    pbclient.set('api_key', "c008cbd5-7885-4c49-a0fe-6cdee926651f")
    pbclient.set('endpoint', 'http://localhost/pybossa')

    # Create the app
    #pbclient.create_app('Semantics Map','Semantics','What is the perceived relation between words? ');
    dir = os.path.dirname(__file__)

    #update app
    pyBossaApp = pbclient.find_app(short_name='Semantics')[0]
    pyBossaApp.long_description = contents(dir +
                                           '/../View/long_description.html')
    pyBossaApp.info['task_presenter'] = contents(dir +
                                                 '/../View/template.html')
    pyBossaApp.info[
        'thumbnail'] = "http://societic.ibercivis.es/semantics/static/images/icon.jpg"
    #pyBossaApp.info['tutorial'] = contents('tutorial.html')
    pyBossaApp.category_id = 1
    pbclient.update_app(pyBossaApp)

    #create tasks
    try:
        cnx = get_connection()
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            return "Something is wrong your username or password"
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
            return "Database does not exists"
        else:
            return err
    else:
        #Get Data
        cursor = cnx.cursor()
        cursor.execute("SELECT * FROM startwords")
        words = cursor.fetchall()
        cursor.close()
        cnx.close()

        #if (len(words)>0):
        #    for item in words:
        #            task_info = dict(start=item[0],
        #                end=item[1],
        #                startWord=getWord(item[0]),
        #                endWord=getWord(item[1]) )
        #            pbclient.create_task(pyBossaApp.id, task_info)

    return "ok"
Example #13
0
def setup():    
    # settings
    pbclient.set('api_key', "c008cbd5-7885-4c49-a0fe-6cdee926651f")
    pbclient.set('endpoint', 'http://localhost/pybossa')

    # Create the app
    #pbclient.create_app('Semantics Map','Semantics','What is the perceived relation between words? ');
    dir = os.path.dirname(__file__)
        
    #update app
    pyBossaApp = pbclient.find_app(short_name='Semantics')[0]
    pyBossaApp.long_description = contents(dir + '/../View/long_description.html')
    pyBossaApp.info['task_presenter'] = contents(dir + '/../View/template.html')
    pyBossaApp.info['thumbnail'] = "http://societic.ibercivis.es/semantics/static/images/icon.jpg"
    #pyBossaApp.info['tutorial'] = contents('tutorial.html')
    pyBossaApp.category_id = 1
    pbclient.update_app(pyBossaApp)

    #create tasks
    try:
        cnx = get_connection()
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            return "Something is wrong your username or password"
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
                return "Database does not exists"
        else:
            return err;
    else:
        #Get Data
        cursor = cnx.cursor()
        cursor.execute("SELECT * FROM startwords")
        words = cursor.fetchall()        
        cursor.close()
        cnx.close()

        #if (len(words)>0):            
        #    for item in words:
        #            task_info = dict(start=item[0],
        #                end=item[1],
        #                startWord=getWord(item[0]),
        #                endWord=getWord(item[1]) )
        #            pbclient.create_task(pyBossaApp.id, task_info)
        
    return "ok"
Example #14
0
def setup():    
    # settings
    pbclient.set('api_key', "74690b3e-e980-4299-b006-9c6a5c50b355")
    pbclient.set('endpoint', 'http://pybossa.socientize.eu/pybossa')

    # Create the app
    #pbclient.create_app('Semantics Map','Semantics','What is the perceived relation between words? ');
    #update app
    pyBossaApp = pbclient.find_app(short_name='Sun4All')[0];
    #pyBossaApp.long_description = '- add long description -';
    #pyBossaApp.info['task_presenter'] = contents('template.html')
    #pyBossaApp.info['thumbnail'] = "http://societic.ibercivis.es/semantics/static/images/icon.jpg"
    #pyBossaApp.info['tutorial'] = contents('tutorial.html')
    #pbclient.update_app(pyBossaApp)

    #create tasks
    try:
        cnx = get_connection();
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            return "Something is wrong your username or password";
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
                return "Database does not exists";
        else:
            return err;
    else:
        #Get Data
        cursor = cnx.cursor();
        cursor.execute("SELECT * FROM images");
        words = cursor.fetchall();        
        cursor.close();
        cnx.close();

        if (len(words)>0):            
            for item in words:
                    task_info = dict(n_answers=5,
                        start=item[0],
                        end=item[1],
                        startWord=getWord(item[0]),
                        endWord=getWord(item[1]) )
                    pbclient.create_task(pyBossaApp.id, task_info)
        
    return "ok";
Example #15
0
def setup():
    # settings
    pbclient.set('api_key', "74690b3e-e980-4299-b006-9c6a5c50b355")
    pbclient.set('endpoint', 'http://pybossa.socientize.eu/pybossa')

    # Create the app
    #pbclient.create_app('Semantics Map','Semantics','What is the perceived relation between words? ');
    #update app
    pyBossaApp = pbclient.find_app(short_name='Sun4All')[0]
    #pyBossaApp.long_description = '- add long description -';
    #pyBossaApp.info['task_presenter'] = contents('template.html')
    #pyBossaApp.info['thumbnail'] = "http://societic.ibercivis.es/semantics/static/images/icon.jpg"
    #pyBossaApp.info['tutorial'] = contents('tutorial.html')
    #pbclient.update_app(pyBossaApp)

    #create tasks
    try:
        cnx = get_connection()
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            return "Something is wrong your username or password"
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
            return "Database does not exists"
        else:
            return err
    else:
        #Get Data
        cursor = cnx.cursor()
        cursor.execute("SELECT * FROM images")
        words = cursor.fetchall()
        cursor.close()
        cnx.close()

        if (len(words) > 0):
            for item in words:
                task_info = dict(n_answers=5,
                                 start=item[0],
                                 end=item[1],
                                 startWord=getWord(item[0]),
                                 endWord=getWord(item[1]))
                pbclient.create_task(pyBossaApp.id, task_info)

    return "ok"
def push_presenter():
    html = open('presenter.html').read()

    # prepend categories to presenter
    cat_html = """
    <script type="text/javascript">
    window.LobbyFactsCategories = %s;
    </script>

    """ % open('categories.json').read()

    html = cat_html + html

    app = pbclient.find_app(short_name=config.APP)[0]

    app.info['task_presenter'] = html
    app.long_description = open('long-description.html').read().replace('%APP%', config.APP)
    app.info['sched'] = 'default'
    app.info['thumbnail'] = 'http://i46.tinypic.com/14js2tx.png'

    pbclient.update_app(app)
    pbclient.set('endpoint', options.api_url)

    if not options.api_key:
        parser.error("You must supply an API-KEY to create an applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)

    if (options.verbose):
       print('Running against PyBosssa instance at: %s' % options.api_url)
       print('Using API-KEY: %s' % options.api_key)

    if (options.results):
        offset=0
        limit=100

        app = pbclient.find_app(short_name='philippinestyphoon')[0]
        if options.completed: 
            completed_tasks = pbclient.find_tasks(app.id, state="completed", offset=offset,limit=limit)
        else:
            completed_tasks = pbclient.find_tasks(app.id,offset=offset,limit=limit)

        # Now get the task runs
        import csv
        f = csv.writer(open("results.csv", "wb"))
        f.writerow(['taskid',
                    'tweetid',
                    'text',
                    'date',
                    'username',
                    'userid',
                    'picture',
Example #18
0
                      applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)

    if (options.verbose):
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if not options.n_answers:
        options.n_answers = 30

    if options.create_app:
        pbclient.create_app('Flickr Person Finder',
                'flickrperson',
                'Do you see a human in this photo?')
        app = pbclient.find_app(short_name='flickrperson')[0]
        app.long_description = open('long_description.html').read()
        app.info['task_presenter'] = open('template.html').read()
        app.info['thumbnail'] = "http://img37.imageshack.us/img37/156/flickrpersonthumbnail.png"

        pbclient.update_app(app)
        # First of all we get the URL photos
        photos = get_flickr_photos()
        # Finally, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        for i in xrange(100):
            for photo in photos:
                # Data for the tasks
                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'],
Example #19
0
       print('Using API-KEY: %s' % options.api_key)


    if options.list_apps:
        my_file = open(options.list_apps)
        list_names = my_file.readlines()
        my_file.close()
    elif options.app:
        list_names = [options.app]
    list_apps = []
    index_apps = []

    # Get all the task runs
    offset = 0
    for app_short_name in list_names:
        app = pbclient.find_app(short_name=app_short_name.rstrip())
        list_apps.append(app)


    for app in list_apps:
        print "Generating stats for %s" % unicode(app[0].name).encode('utf-8')
        if (len(app) > 0):
            app = app[0]
            users = []
            anon_users = []
            auth_users =[]
            task_runs = pbclient.get_taskruns(app.id)
            dates = {}
            dates_anon = {}
            dates_auth = {}
            dates_n_tasks = {}
Example #20
0
        parser.error("You must supply an API-KEY to create an \
                      applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)

    if (options.verbose):
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if not options.n_answers:
        options.n_answers = 30

    if options.create_app:
        pbclient.create_app('Flickr Person Finder', 'flickrperson',
                            'Do you see a human in this photo?')
        app = pbclient.find_app(short_name='flickrperson')[0]
        app.long_description = open('long_description.html').read()
        app.info['task_presenter'] = open('template.html').read()
        app.info[
            'thumbnail'] = "http://img37.imageshack.us/img37/156/flickrpersonthumbnail.png"

        pbclient.update_app(app)
        # First of all we get the URL photos
        photos = get_flickr_photos()
        # Finally, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        for i in xrange(100):
            for photo in photos:
                # Data for the tasks
                task_info = dict(question="Do you see a human in this photo?",
                                 n_answers=int(options.n_answers),
Example #21
0
 def find_app_by_short_name(self):
     self.app = pbclient.find_app(
         short_name=self.app_config['short_name'])[0]
def create_tasks(app_config, submit_tasks):
    config = RawConfigParser()
    config.read(args.task_config)
    response = pbclient.find_app(short_name=app_config['short_name'])
    app = response[0]
    app_id = app.id
    #polygon around area to be tasked, as list of (lat, long) lists
    area_polygon = polygon_file_to_path(config.get("area", "polygon_file"))
    extent = area_polygon.get_extents().get_points()
    #The northern, southern, western, and eastern bounds of the area to work on.
    nb = extent[1][0]
    wb = extent[0][1]
    sb = extent[0][0]
    eb = extent[1][1]
    shared_style = simplekml.Style()
    shared_style.iconstyle.color = "ff0000ff"
    shared_style.labelstyle.scale = 0.5
    shared_style.iconstyle.scale = 0.5
    kml = simplekml.Kml()
    pnt = kml.newpoint(name="NW")
    pnt.coords = [(wb, nb)]
    pnt.style = shared_style
    pnt = kml.newpoint(name="NE")
    pnt.coords = [(eb, nb)]
    pnt.style = shared_style
    pnt = kml.newpoint(name="SW")
    pnt.coords = [(wb, sb)]
    pnt.style = shared_style
    pnt = kml.newpoint(name="SE")
    pnt.coords = [(eb, sb)]
    pnt.style = shared_style
    #Size of the tasks, into how many rows and columns should the area be divided.
    task_cols = int(config.get("tasksize", "task_cols"))
    task_rows = int(config.get("tasksize", "task_rows"))
    boundary = float(config.get("tasksize", "boundary"))
    ns_step = (sb - nb) / task_rows
    ns_boundary = ns_step * boundary
    we_step = (eb - wb) / task_cols
    we_boundary = we_step * boundary
    task_counter = 0
    if submit_tasks:
        res = requests.get(args.server + '/api/app')
        remaining_requests = int(res.headers['x-ratelimit-remaining'])
        print("Remaining requests: " + str(remaining_requests))
    else:
        remaining_requests = 99999
    for col in range(task_cols):
        wbr = wb + col * we_step
        ebr = wb + (col + 1) * we_step
        for row in range(task_rows):
            while remaining_requests < 10:
                time.sleep(60)
                res = requests.get(args.server + '/api/app')
                remaining_requests = int(res.headers['x-ratelimit-remaining'])
                print(remaining_requests)
            nbc = nb + row * ns_step
            sbc = nb + (row + 1) * ns_step
            if area_polygon.intersects_bbox(Bbox([[nbc, wbr], [sbc, ebr]])):
                if submit_tasks:
                    task_info = dict(question=app_config['question'], n_answers=config.get("meta", "n_answers"),
                                     westbound=wbr, eastbound=ebr, northbound=nbc, southbound=sbc,
                                     westmapbound=wbr - we_boundary, eastmapbound=ebr + we_boundary,
                                     northmapbound=nbc - ns_boundary, southmapbound=sbc + ns_boundary,
                                     location=str(row) + "_" + str(col), batch=config.get("meta", "batch_name"))
                    response = pbclient.create_task(app_id, task_info)
                    check_api_error(response)
                    remaining_requests -= 1
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(wbr, nbc)]
                pnt.style = shared_style
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(ebr, nbc)]
                pnt.style = shared_style
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(wbr, sbc)]
                pnt.style = shared_style
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(ebr, sbc)]
                pnt.style = shared_style
                task_counter += 1
                print("Task: " + str(task_counter))
    kml.save(config.get("meta", "batch_name") + "_tasks.kml")
# Importing all tasks one by one, and setting n_answers for each.
# This is not as elegant as the csv bulk import as it involves
# lots of requests, but setting n_answers isn't possible in
# bulk importing.
#

import requests
import sys
import config
import pbclient


pbclient.set('endpoint', config.ENDPOINT)
pbclient.set('api_key', config.API_KEY)

app = pbclient.find_app(short_name=config.APP)[0]

# steal task from original flickrperson app
print 'loading tasks from flickrperson app'
r = requests.get('http://crowdcrafting.org/api/task?app_id=147&limit=1000')
tasks = r.json

print len(tasks), 'tasks loaded.'

finished = 0

for t in tasks:
    sent = False
    while not sent:
        #try:
            pbclient.create_task(app.id, t['info'], n_answers=100)
Example #24
0
 def find_app_by_short_name(self):
     self.app = pbclient.find_app(short_name=self.app_config['short_name'])[0]
                      help="Create the application",
                      metavar="CREATE-APP")

    parser.add_option("-u", "--update", dest="update", action="store_true", 
                      help="Update the templates of the application",
                      metavar="UPDATE-APP")

    parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
    
    (options, args) = parser.parse_args()

    if not options.update:
        fw_client = pbclient
        fw_client.set('endpoint','http://forestwatchers.net/pybossa')
        fw_client.set('api_key', options.api_key)
        besttile = pbclient.find_app(short_name='besttile')[0]
        offset = 0
        limit = 100
        completed_tasks = pbclient.find_tasks(besttile.id, state="completed", offset=0,limit=200)


    if not options.api_url:
        options.api_url = 'http://localhost:5000'

    pbclient.set('endpoint', options.api_url)

    if not options.api_key:
        parser.error("You must supply an API-KEY to create an applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)
Example #26
0

parser = ArgumentParser()
parser.add_argument("-k",
                    "--api-key",
                    help="PyBossa User API-KEY to interact with PyBossa",
                    required=True)
parser.add_argument("-s",
                    "--server",
                    help="PyBossa URL http://domain.com/",
                    default="http://crowdcrafting.org")
args = parser.parse_args()
pbclient.set('api_key', args.api_key)
pbclient.set('endpoint', args.server)

response = pbclient.find_app(short_name='RuralGeolocator')
# Check errors:
if type(response) == dict and (response.get('status') == 'failed'):
    print "Error"
    print response
    exit(0)
# Get the app
app = response[0]
data = pbclient.get_taskruns(app_id=app.id, limit=1000, offset=0)
limit = 100
offset = 0
task_runs = []

while len(data) > 0:
    response = pbclient.get_taskruns(app_id=app.id, limit=limit, offset=offset)
    if type(response) != dict:
Example #27
0
    if not options.api_key:
        parser.error(
            "You must supply an API-KEY to create an applicationa and tasks in PyBossa"
        )
    else:
        pbclient.set('api_key', options.api_key)

    if (options.verbose):
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if (options.results):
        offset = 0
        limit = 100

        app = pbclient.find_app(short_name='philippinestyphoon')[0]
        if options.completed:
            completed_tasks = pbclient.find_tasks(app.id,
                                                  state="completed",
                                                  offset=offset,
                                                  limit=limit)
        else:
            completed_tasks = pbclient.find_tasks(app.id,
                                                  offset=offset,
                                                  limit=limit)

        # Now get the task runs
        import csv
        f = csv.writer(open("results.csv", "wb"))
        f.writerow([
            'taskid',
Example #28
0
    if not options.n_answers:
        options.n_answers = 15

    if not options.input_path:
        parser.error("You must supply the input data path")

    if not options.inputs_file:
        parser.error("You must supply the file where the input data files are listed")
                      
    if options.create_app:
        # Create the app with its corresponding info and files
        pbclient.create_app(app_config['name'],
                app_config['short_name'],
                app_config['description'])
        app = pbclient.find_app(short_name=app_config['short_name'])[0]
        app.long_description = open('long_description.html').read()
        app.info['task_presenter'] = open('cellSpottingPresenter.html').read()
        app.info['tutorial'] = open('tutorial.html').read()
        app.info['thumbnail'] = app_config['thumbnail']
        app.info['sched'] = 'breadth_first'

        pbclient.update_app(app)
        
        # Prepare the url of the server to be accessed in order to get the input data
                #data_url = 'http://pybossa.ibercivis.es:5000/static/input/'
        data_url = options.api_url+"/"+options.input_path
     
        # Filenames and the rest of task infos are written down within the following CSV file
        # A CSV reader is used to go through the document
        # Each row contains a task to be created with the following info: 
        exit(0)

    pbclient.set('endpoint', args.server)
    pbclient.set('api_key', args.api_key)

    if args.verbose:
        print('Running against PyBosssa instance at: %s' % args.server)
        print('Using API-KEY: %s' % args.api_key)

    if args.create_app:
        try:
            response = pbclient.create_app(app_config['name'],
                                           app_config['short_name'],
                                           app_config['description'])
            check_api_error(response)
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            app = response[0]
            app.long_description = open('long_description.html').read()
            app.info['task_presenter'] = open('template.html').read()
            app.info['thumbnail'] = app_config['thumbnail']
            app.info['tutorial'] = open('tutorial.html').read()
        except:
            format_error("pbclient.create_app or pbclient.find_app", response)

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
        except:
            format_error("pbclient.update_app", response)
Example #30
0
import pbclient

def contents(filename):
    return file(filename).read()

# settings
pbclient.set('api_key', "c008cbd5-7885-4c49-a0fe-6cdee926651f")
pbclient.set('endpoint', 'http://localhost/pybossa')

# Create the app
#response = pbclient.create_app('Sun for All', 'Sun4All','The aim of the project is the collection of over 30,000 images of the Sun (spectroheliograms) existing at the Astronomical Observatory of the University of Coimbra, the result of work of more than 80 years of daily observations of the Sun started in 1926.');

#update app
pyBossaApp = pbclient.find_app(short_name='Sun4All')[0];
#pyBossaApp.long_description = '- add long description -';
pyBossaApp.info['task_presenter'] = contents('../Site/static/templates/template.html')
pyBossaApp.info['tutorial'] = contents('../Site/static/templates/tutorial.html')
pyBossaApp.info['thumbnail'] = "https://pybossa.socientize.eu/sun4all/images/icon2.jpg"
pyBossaApp.category_id = 2

pbclient.update_app(pyBossaApp)
                      applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)

    if (options.verbose):
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if not options.n_answers:
        options.n_answers = 30

    if options.create_app:
        pbclient.create_app(app_config['name'],
                app_config['short_name'],
                app_config['description'])
        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['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = open('tutorial.html').read()

        pbclient.update_app(app)
        # First of all we get the URL photos
        photos = get_flickr_photos()
        # Finally, we have to create a set of tasks for the application
        # For this, we get first the photo URLs from Flickr
        for i in xrange(1):
            for photo in photos:
                # Data for the tasks
                task_info = dict(question=app_config['question'],
                            n_answers=int(options.n_answers), link=photo['link'],
Example #32
0
    if args.verbose:
        print('Running against PyBosssa instance at: %s' % args.server)
        print('Using API-KEY: %s' % args.api_key)

    if args.dry:
        create_tasks(app_config, False)
        exit(0)

    if args.create_app:
        try:
            response = pbclient.create_app(app_config['name'],
                                           app_config['short_name'],
                                           app_config['description'])
            check_api_error(response)
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            app = response[0]
            app.long_description = open('long_description.html').read()
            app.info['task_presenter'] = open('template.html').read()
            app.info['thumbnail'] = app_config['thumbnail']
            app.info['tutorial'] = open('tutorial.html').read()
        except:
            format_error("pbclient.create_app or pbclient.find_app", response)

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
        except:
            format_error("pbclient.update_app", response)
Example #33
0
 def find_app_by_short_name():
     return pbclient.find_app(short_name=app_config['short_name'])[0]
Example #34
0
 def find_app_by_short_name(self):
     self.app = self.handle_result(pbclient.find_app(short_name=self.app_config['short_name']))[0]
Example #35
0
def create_tasks(app_config, submit_tasks):
    config = RawConfigParser()
    config.read(args.task_config)
    response = pbclient.find_app(short_name=app_config['short_name'])
    app = response[0]
    app_id = app.id
    #polygon around area to be tasked, as list of (lat, long) lists
    area_polygon = polygon_file_to_path(config.get("area", "polygon_file"))
    extent = area_polygon.get_extents().get_points()
    #The northern, southern, western, and eastern bounds of the area to work on.
    nb = extent[1][0]
    wb = extent[0][1]
    sb = extent[0][0]
    eb = extent[1][1]
    shared_style = simplekml.Style()
    shared_style.iconstyle.color = "ff0000ff"
    shared_style.labelstyle.scale = 0.5
    shared_style.iconstyle.scale = 0.5
    kml = simplekml.Kml()
    pnt = kml.newpoint(name="NW")
    pnt.coords = [(wb, nb)]
    pnt.style = shared_style
    pnt = kml.newpoint(name="NE")
    pnt.coords = [(eb, nb)]
    pnt.style = shared_style
    pnt = kml.newpoint(name="SW")
    pnt.coords = [(wb, sb)]
    pnt.style = shared_style
    pnt = kml.newpoint(name="SE")
    pnt.coords = [(eb, sb)]
    pnt.style = shared_style
    #Size of the tasks, into how many rows and columns should the area be divided.
    task_cols = int(config.get("tasksize", "task_cols"))
    task_rows = int(config.get("tasksize", "task_rows"))
    boundary = float(config.get("tasksize", "boundary"))
    ns_step = (sb - nb) / task_rows
    ns_boundary = ns_step * boundary
    we_step = (eb - wb) / task_cols
    we_boundary = we_step * boundary
    task_counter = 0
    if submit_tasks:
        res = requests.get(args.server + '/api/app')
        remaining_requests = int(res.headers['x-ratelimit-remaining'])
        print("Remaining requests: " + str(remaining_requests))
    else:
        remaining_requests = 99999
    for col in range(task_cols):
        wbr = wb + col * we_step
        ebr = wb + (col + 1) * we_step
        for row in range(task_rows):
            while remaining_requests < 10:
                time.sleep(60)
                res = requests.get(args.server + '/api/app')
                remaining_requests = int(res.headers['x-ratelimit-remaining'])
                print(remaining_requests)
            nbc = nb + row * ns_step
            sbc = nb + (row + 1) * ns_step
            if area_polygon.intersects_bbox(Bbox([[nbc, wbr], [sbc, ebr]])):
                if submit_tasks:
                    task_info = dict(question=app_config['question'],
                                     n_answers=config.get("meta", "n_answers"),
                                     westbound=wbr,
                                     eastbound=ebr,
                                     northbound=nbc,
                                     southbound=sbc,
                                     westmapbound=wbr - we_boundary,
                                     eastmapbound=ebr + we_boundary,
                                     northmapbound=nbc - ns_boundary,
                                     southmapbound=sbc + ns_boundary,
                                     location=str(row) + "_" + str(col),
                                     batch=config.get("meta", "batch_name"))
                    response = pbclient.create_task(app_id, task_info)
                    check_api_error(response)
                    remaining_requests -= 1
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(wbr, nbc)]
                pnt.style = shared_style
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(ebr, nbc)]
                pnt.style = shared_style
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(wbr, sbc)]
                pnt.style = shared_style
                pnt = kml.newpoint(name=str(task_counter))
                pnt.coords = [(ebr, sbc)]
                pnt.style = shared_style
                task_counter += 1
                print("Task: " + str(task_counter))
    kml.save(config.get("meta", "batch_name") + "_tasks.kml")
Example #36
0
def setup():
    pbclient.set('endpoint', flask_app.config.get('ETL_PYBOSSA_HOST'))
    pbclient.set('api_key', flask_app.config.get('ETL_PYBOSSA_KEY'))
    apps = pbclient.find_app(short_name='lobbyfacts-nee')
    return apps.pop()
Example #37
0
 def find_app_by_short_name():
     return pbclient.find_app(short_name=app_config['short_name'])[0]
Example #38
0
        print ("Using the number of pages of the default PDF file from Mozilla")

    if (options.verbose):
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if not options.n_answers:
        options.n_answers = 100

    if options.create_app:
        try:
            response = pbclient.create_app(app_config['name'],
                                           app_config['short_name'],
                                           app_config['description'])
            check_api_error(response)
            response = pbclient.find_app(short_name=app_config['short_name'])
            check_api_error(response)
            app = response[0]
            app.long_description = open('long_description.html').read()
            app.info['task_presenter'] = open('template.html').read()
            app.info['thumbnail'] = app_config['thumbnail']
        except:
            format_error("pbclient.create_app", response)

        try:
            response = pbclient.update_app(app)
            check_api_error(response)
            for page in range(1, 15):
                # Data for the tasks
                task_info = dict(question=app_config['question'],
                                 page=page,
Example #39
0
                      applicationa and tasks in PyBossa")
    else:
        pbclient.set('api_key', options.api_key)

    if (options.verbose):
        print('Running against PyBosssa instance at: %s' % options.api_url)
        print('Using API-KEY: %s' % options.api_key)

    if not options.n_answers:
        options.n_answers = 2

    if options.create_app:
        import csv
        pbclient.create_app(app_config['name'], app_config['short_name'],
                            app_config['description'])
        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['thumbnail'] = app_config['thumbnail']
        app.info['tutorial'] = open('tutorial.html').read()

        pbclient.update_app(app)
        with open('PabloPh_latest_UN_051212_5_38PM.csv', 'rb') as csvfile:
            csvreader = csv.reader(csvfile, delimiter=',')
            # Each row has the following format
            # tweetid,
            # text
            # date
            # username
            # userid
            for row in csvreader:
            )

            doc.Folder.append(pm)
        colorIndex += 1
    out = open(filename, "wb")
    out.write(etree.tostring(doc, pretty_print=True))
    out.close()

parser = ArgumentParser()
parser.add_argument("-k", "--api-key", help="PyBossa User API-KEY to interact with PyBossa", required=True)
parser.add_argument("-s", "--server", help="PyBossa URL http://domain.com/", default="http://crowdcrafting.org")
args = parser.parse_args()
pbclient.set('api_key', args.api_key)
pbclient.set('endpoint', args.server)

response = pbclient.find_app(short_name='RuralGeolocator')
# Check errors:
if type(response) == dict and (response.get('status') == 'failed'):
    print "Error"
    print response
    exit(0)
# Get the app
app = response[0]
data = pbclient.get_taskruns(app_id=app.id, limit=1000, offset=0)
limit = 100
offset = 0
task_runs = []

while len(data) > 0:
    response = pbclient.get_taskruns(app_id=app.id, limit=limit, offset=offset)
    if type(response) != dict: