Esempio n. 1
0
def update_current_sums(curr_sums: dict, pub: Pub, auth: Author) -> dict:
    """
    Updates temporary values needed to run greedy algorithm. Instead of recount
    values in every loop iteration, we simply update them.

    Args:
        curr_sums: dictionary with values to update
            contrib_sum: sum of contributions from all accepted publicatons (float)
            monograph_sum: sum of contributions from all accepted monographs (float)
            phd_and_outsiders: sum of contributions from all accepted phds' and
                outsiders' publicatons (float)
        pub: newly accepted publication
        auth: publication's author

    Returns:
        dictionary with updated values

    """
    monograph_sum = curr_sums["monograph_sum"]
    phd_and_outsiders = curr_sums["phd_and_outsiders"]

    if pub.is_monograph():
        monograph_sum += pub.get_contribution()
    if auth.is_phd_student() or not auth.is_in_n():
        phd_and_outsiders += pub.get_contribution()

    result = {
        "contrib_sum": curr_sums["contrib_sum"] + pub.get_contribution(),
        "monograph_sum": monograph_sum,
        "phd_and_outsiders": phd_and_outsiders,
    }
    return result
Esempio n. 2
0
def prepare_authors(data: dict) -> List[Author]:
    """
    Prepares list of authors without their publications list

    Args:
        data: dictionary with keyes:
            AUTHOR_ID: list of authors' ids
            IS_EMPLOYEE: list that defines which authors are employees
            IS_PHD_STUDENT: list that defines which authors are phd students
            CONTRIBUTION: list of authors' contributions
            IS_IN_N: list that defines which authors are in N
            All keys are defined in settings.py

    Returns:
        List of authors

    """
    result = []
    for idx in range(len(data[AUTHOR_ID])):
        author_id = data[AUTHOR_ID][idx]
        is_emp = data[IS_EMPLOYEE][idx]
        is_phd = data[IS_PHD_STUDENT][idx]
        cont = data[CONTRIBUTION][idx]
        in_n = data[IS_IN_N][idx]
        result.append(Author(author_id, is_emp, is_phd, cont, in_n))
    return result
def create_example_author(
    a_id: str = AUTH_ID,
    is_emp: bool = IS_EMP,
    is_phd: bool = IS_PHD,
    contrib: float = CONTRIB,
    in_n: bool = IN_N,
):
    return Author(a_id, is_emp, is_phd, contrib, in_n)
Esempio n. 4
0
def prepare_test_authors(data: dict):
    authors = []
    for idx in range(len(data[AUTHOR_ID])):
        a_id = data[AUTHOR_ID][idx]
        is_emp = data[IS_EMPLOYEE][idx]
        is_phd = data[IS_PHD_STUDENT][idx]
        contrib = data[CONTRIBUTION][idx]
        in_n = data[IS_IN_N][idx]
        authors.append(Author(a_id, is_emp, is_phd, contrib, in_n))
    return authors
def prepare_data_for_check_mono_limit_test():
    """
    Prepares data that fails _Author__check_moographs_limit() test

    """
    is_phd = False
    is_emp = False
    is_mon = True
    tmp_sum = MONOGRAPH_COEFFICIENT * CONTRIB + 1.0
    points = MONOGRAPH_LIMIT_MAX_POINTS / 2

    author = Author(AUTH_ID, is_emp, is_phd, CONTRIB, CZYN)

    return author, is_mon, tmp_sum, points
Esempio n. 6
0
def check_full_author_limits(auth: Author, publications: List[Publication]):
    if auth.is_employee():
        publications_sum = 0
        for pub in publications:
            publications_sum += pub.get_contribution()
        assert publications_sum <= auth.get_contribution(
        ) * PUBLICATIONS_COEFFICIENT

    if auth.is_employee() and not auth.is_phd_student():
        monograph_sum = 0
        for pub in publications:
            monograph_sum += pub.get_contribution() if pub.is_monograph(
            ) else 0.0
        assert monograph_sum <= auth.get_contribution() * MONOGRAPH_COEFFICIENT

    if auth.is_phd_student():
        publications_sum = 0
        for pub in publications:
            publications_sum += pub.get_contribution()
        assert publications_sum <= PUBLICATIONS_COEFFICIENT_FOR_PHD
    return True
def prepare_complex_test_data():
    publications = create_complex_publications_list()
    author = Author("author", True, False, 0.5, 1)
    author.load_publications(publications)
    author.create_publications_ranking()
    return author, publications
def test_update_contribution_with_value_smaller_than_MIN_CONTRIBUTION():
    value = MIN_CONTRIBUTION - 0.1
    assert Author._Author__update_contribution(value) == MIN_CONTRIBUTION
def test_update_contribution_with_value_greater_than_MAX_CONTRIBUTION():
    value = MAX_CONTRIBUTION + 0.1
    assert Author._Author__update_contribution(value) == MAX_CONTRIBUTION
Esempio n. 10
0
def test_update_contribution():
    value = (MAX_CONTRIBUTION + MIN_CONTRIBUTION) / 2
    assert Author._Author__update_contribution(value) == value