Esempio n. 1
0
def web_task(request):

    result = {'user': None}
    #if True:
    try:

        user, token = check_auth(request)
        result['user'] = user

        task_id = request.GET['task_id']
        #project_id = request.GET['project_id']

        task = get_task(task_id)
        result['task'] = task

        result['comments'] = get_task_comments(task['id'])

        result['tasks'] = get_tasks(task['project_id'], completed=False)

        result['project'] = get_project(user.id, task['project_id'])


    except:
        pass

    return result
Esempio n. 2
0
def api_task(task_id=None):
    try:
        task = utils.get_task(task_id)
        try:
            data = json.loads(task)
        except Exception, e:
            data = {'status': 'error', 'result': 'invalid task'}
    except Exception, e:
        data = {'status': 'error', 'result': str(e)}
Esempio n. 3
0
async def guide(context):
    """ Link to guide on the forum """
    lookup, at_users, message = await init_command(context)
    task, _ = get_task(message, list(lookup["tasks"].keys()))
    if not task:
        return
    msg = "There's a guide for {} here: {}".format(
        task.title(), lookup["url"] + lookup["tasks"][task])
    msg = format_message(msg, at_users)
    await context.send(msg)
Esempio n. 4
0
def view_task(task_id=None):
    data = {}
    if task_id:
        task = get_task(task_id)
        data['status'] = task.get('status')
        res = task.get('result')
        if res:
            res = pickle.loads(res)
        data['result'] = res
    return generate_api_response(data)
Esempio n. 5
0
def view_task(task_id=None):
    data = {}
    if task_id:
        task = get_task(task_id)
        data['status'] = task.get('status')
        res = task.get('result')
        if res:
            res = pickle.loads(res)
        data['result'] = res
    return generate_api_response(data)
Esempio n. 6
0
async def forums(context):
    """ Link to the forums """
    lookup, at_users, message = await init_command(context)
    task, _ = get_task(message, lookup["tasks"])
    ext = "index.php" if task is None else "viewforum.php?f={}".format(
        lookup["tasks"][task])
    section = "" if task is None else "the {} section of ".format(task.title())
    msg = "You should check out {}our Forum at: {}".format(
        section, lookup["url"] + ext)
    msg = format_message(msg, at_users)
    await context.send(msg)
Esempio n. 7
0
async def support(context):
    """ Support section of forum command """
    lookup, at_users, message = await init_command(context)
    task, _ = get_task(message, list(lookup["tasks"].keys()))
    url = "{}{}".format(lookup["url"],
                        "3" if task is None else lookup["tasks"][task])
    section = "in" if task is None else "in the {} section of".format(
        task.title())
    msg = format_message(
        "This question has been asked and answered {} our Support Forum at: "
        "{}".format(section, url), at_users)
    await context.send(msg)
Esempio n. 8
0
async def faqs(context):
    """ Link to FAQs """
    lookup, at_users, message = await init_command(context)

    is_task = True
    tasks = faq_cache.contents
    if "search" in message:
        is_task = False
        search_term = " ".join(message[message.index("search") + 1:])
        logger.info("search_term: %s", search_term)
        if not search_term:
            is_task = True
            task = None
        else:
            task = faq_cache.search(search_term)
            logger.info("results: %s", task)
            if len(task) > lookup["results"]:
                logger.info("Too many results. Limiting: %s / %s",
                            lookup["results"], len(task))
                task = None
            if not task:
                is_task = True
                task = None
    else:
        task, _ = get_task(message, list(tasks.keys()))
    logger.info("final task: %s", task)
    if is_task:
        url = lookup["url"] if task is None else lookup["url"] + tasks[task]
        section = "on" if task is None else "in the {} section of".format(
            task.title())
        msg = "Your question is answered {} our FAQ page at: {}".format(
            section, url)
        msg = format_message(msg, at_users)
    else:
        urls = "\n\t".join([
            "`{}`: {}".format(val, lookup["url"] + key)
            for key, val in task.items()
        ])
        msg = (
            "Your question is answered on our FAQ page. Try one of these answers related to "
            "the term `{}`: \n\t{}".format(search_term, urls))
        msg = format_message(msg, at_users)
    await context.send(msg)
Esempio n. 9
0
async def donate(context):
    """ Display donation messages """
    lookup, at_users, message = await init_command(context)

    content = dict()
    for key, val in lookup["tasks"].items():
        kwargs = dict(embed=dict(title=val["title"], type="rich"),
                      author=dict(name=val["name"], icon_url=val["icon"]))
        if "url" in val:
            kwargs["embed"]["url"] = val["url"]
            kwargs["author"]["url"] = val["url"]
        embed = Embed(**kwargs["embed"])
        embed.set_thumbnail(url=val["thumbnail"])
        embed.set_author(**kwargs["author"])

        if val.get("fields", None) is not None:
            for field in val["fields"]:
                embed.add_field(inline=False, **field)
        content[key] = embed
    logger.info("donator content: %s", content)

    donatee, _ = get_task(message, list(content.keys()))

    msg = format_message(lookup["msg"], at_users)
    await context.send(msg)
    await context.send(embed=content.pop("patreon"))

    if donatee != "patreon":
        embeds = [content[donatee]] if donatee else [
            content[key] for key in list(content.keys())
        ]
        msg = (
            "Alternatively you can give a one off donation to any of our Devs below:"
        )
        await context.send(msg)
        for embed in embeds:
            await context.send(embed=embed)
Esempio n. 10
0
File: main.py Progetto: mafanhe/pbt
        population_id = get_max_of_db_column(connect_str_or_path, USE_SQLITE,
                                             table_name, "population_id")
    # Train each available task for an interval
    task_wait_count = 0
    exploitation_wait_count = 0
    start_time = int(time.time())
    # global exploitation_wait_count
    # global task_wait_count
    while True:

        try:
            # init process pool
            pool = multiprocessing.Pool(processes=POPULATION_SIZE, initializer=init)  #
            try:
                # Find a task that's incomplete and inactive, and set it to active
                tasks = get_task(connect_str_or_path, USE_SQLITE, population_id,
                                 interval_limit, POPULATION_SIZE)
                # task_id, intervals_trained, seed_for_shuffling = task
            except RemainingTasksTaken:
                if task_wait_count == 0:
                    print_with_time("Waiting for a task to be available.")
                time.sleep(10)
                task_wait_count += 1
                continue
            except PopulationFinished:
                task_ids, scores = get_task_ids_and_scores(connect_str_or_path,
                                                           USE_SQLITE,
                                                           population_id)
                print("Population finished. Best score: %.2f" % scores[0])
                checkpoint_path = (CHECKPOINT_STR % (population_id, task_ids[0]))
                pre, suf = checkpoint_path.split('.')
                weights_path = pre + "_weights." + suf
Esempio n. 11
0
def get_task_view(request):
    id = request.GET.get("id")
    ret = utils.get_task(id)
    return public.success_result_http(ret)