def vote_number_of_subjects(pmid, subjects, username):
    """ Place a vote for the number of subjects for this article. """

    fullArticle = next(get_article_object(pmid))

    target = eval(fullArticle.metadata)

    if "space_subjects" not in target:
        target["space_subjects"] = {}

    if "number_of_subjects" not in target["space_subjects"]:
        target["space_subjects"]["number_of_subjects"] = []

    for i in range(len(target["space_subjects"]["number_of_subjects"])):
        if target["space_subjects"]["number_of_subjects"][i][
                "username"] == username:
            del target["space_subjects"]["number_of_subjects"][i]

    target["space_subjects"]["number_of_subjects"].append({
        "username": username,
        "value": subjects
    })

    query = Articles.update(metadata=target).where(Articles.pmid == pmid)
    query.execute()
示例#2
0
def vote_stereotaxic_space(pmid, space, username):
    """ Toggle a user's vote for the stereotaxic space of an article. """

    fullArticle = next(get_article_object(pmid))

    target = eval(fullArticle.metadata)

    if "space_subjects" not in target:
        target["space_subjects"] = {}

    if "radio_votes" not in target["space_subjects"]:
        target["space_subjects"]["radio_votes"] = []

    for i in range(len(target["space_subjects"]["radio_votes"])):
        if target["space_subjects"]["radio_votes"][i]["username"] == username:
            del target["space_subjects"]["radio_votes"][i]

    target["space_subjects"]["radio_votes"].append({
        "username": username,
        "type": space
    })

    query = Articles.update(
        metadata=target).where(
        Articles.pmid == pmid)
    query.execute()
def edit_table_title_caption(pmid, exp, title, caption):
    """ Edit the title and caption of a table. """

    target = next(get_article_object(pmid))
    experiments = eval(target.experiments)
    elem = experiments[int(exp)]
    elem["title"] = title
    elem["caption"] = caption
    Articles.update(experiments=experiments).where(
        Articles.pmid == pmid).execute()
def delete_row(pmid, exp, row):
    """ Delete a row of coordinates from an experiment. """

    target = next(get_article_object(pmid))
    experiments = eval(target.experiments)
    elem = experiments[exp]
    locations = elem["locations"]
    locations.pop(row)
    Articles.update(experiments=experiments).where(
        Articles.pmid == pmid).execute()
def toggle_vote(pmid, topic, username, direction):
    """ Toggle a user's vote on an article tag. """

    fullArticle = next(get_article_object(pmid))

    metadata = eval(fullArticle.metadata)

    update_vote_in_struct(metadata['meshHeadings'], topic, username, direction,
                          "name")

    query = Articles.update(metadata=metadata).where(Articles.pmid == pmid)
    query.execute()
def update_coordinate_row(pmid, exp, coords, row_number):
    """ Add a coordinate row to the end of a table.

    Take a list of three or four coordinates. Take a row number. """

    target = next(get_article_object(pmid))
    experiments = eval(target.experiments)
    elem = experiments[int(exp)]
    row_list = ",".join([str(c) for c in coords])
    elem["locations"][row_number] = row_list
    Articles.update(experiments=experiments).where(
        Articles.pmid == pmid).execute()
示例#7
0
def add_table_through_text_box(pmid, values):
    """ Add an experiment table using a CSV-formatted string. """

    target = next(get_article_object(pmid))
    experiments = eval(target.experiments)
    values = values.replace(" ", "").split("\n")
    secondTable = {"title": "", "caption": "", "locations": values,
                   "id": (max([exp["id"] for exp in experiments]) + 1)}
    experiments.insert(len(experiments), secondTable)
    Articles.update(
        experiments=experiments).where(
        Articles.pmid == pmid).execute()
def flag_table(pmid, exp):
    """ Flag a table as inaccurate. """

    target = next(get_article_object(pmid))
    experiments = eval(target.experiments)
    elem = experiments[int(exp)]
    if "flagged" in elem:
        # toggle the flag if it exists
        elem["flagged"] = 1 - elem["flagged"]
    else:
        elem["flagged"] = 1
    Articles.update(experiments=experiments).where(
        Articles.pmid == pmid).execute()
def add_coordinate_row(pmid, exp, coords, row_number=-1):
    """ Add a coordinate row to the end of a table.

    Take a list of three or four coordinates.
    Take a row number. -1 will add to the end of the list. """

    target = next(get_article_object(pmid))
    experiments = eval(target.experiments)
    elem = experiments[int(exp)]
    row_list = ",".join([str(c) for c in coords])
    if row_number == -1:
        elem["locations"].append(row_list)
    else:
        elem["locations"].insert(row_number, row_list)
    Articles.update(experiments=experiments).where(
        Articles.pmid == pmid).execute()
示例#10
0
def split_table(pmid, exp, row):
    """ Split a coordinate table into two. """

    target = next(get_article_object(pmid))
    experiments = eval(target.experiments)
    elem = experiments[exp]
    locations = elem["locations"]
    locations1 = locations[0:row]
    locations2 = locations[row:]
    elem["locations"] = locations1
    highestID = int(max([exp["id"] for exp in experiments])) + 1
    secondTable = {
        "title": "",
        "caption": "",
        "locations": locations2,
        "id": highestID
    }
    experiments.insert(exp + 1, secondTable)
    Articles.update(experiments=experiments).where(
        Articles.pmid == pmid).execute()
示例#11
0
def add_unmapped_article_to_cached_collections(api_key, pmid, collection_name):
    query = list(
        User.select(
            User.collections).where(User.password == api_key).execute())[0]
    collections = json.loads(query.collections)
    relevant_article = list(get_article_object(pmid))[0]
    target_collection = [
        x for x in collections if x['name'] == collection_name
    ][0]
    target_collection['unmapped_articles'].append({
        'title':
        relevant_article.title,
        'pmid':
        relevant_article.pmid,
        'authors':
        relevant_article.authors,
        'reference':
        relevant_article.reference,
    })
    cache_user_collections(api_key, collections)