def referentiel() -> Referentiel:
    action_1_1 = make_action_referentiel(id_nomenclature="1.1",
                                         actions=[],
                                         points=30)
    action_1_2 = make_action_referentiel(id_nomenclature="1.2",
                                         actions=[],
                                         points=70)
    action_1 = make_action_referentiel(id_nomenclature="1",
                                       actions=[action_1_1, action_1_2])
    root_action = make_action_referentiel(actions=[action_1])
    referentiel = Referentiel(root_action)
    return referentiel
def test_referentiel_when_a_():
    action_1_2_1 = make_action_referentiel(id="ref__1_2_1",
                                           id_nomenclature="1.2.1",
                                           actions=[],
                                           points=50)
    action_1_2_2 = make_action_referentiel(id="ref__1_2_2",
                                           id_nomenclature="1.2.2",
                                           actions=[],
                                           points=50)

    action_1_2 = make_action_referentiel(id="ref__1_2",
                                         id_nomenclature="1.2",
                                         actions=[action_1_2_1, action_1_2_2])

    action_1_1 = make_action_referentiel(id="ref__1_1",
                                         id_nomenclature="1.1",
                                         points=30)

    action_1 = make_action_referentiel(id="ref__1",
                                       id_nomenclature="1",
                                       actions=[action_1_1, action_1_2],
                                       points=500)

    root_action = make_action_referentiel(id="ref",
                                          id_nomenclature="",
                                          actions=[action_1])
    referentiel = Referentiel(root_action, mesure_depth=1)
    assert referentiel.points[("1", "1")] == 150.0
    assert referentiel.points[("1", "2")] == 350.0
    assert referentiel.points[("1", "2", "1")] == 175.0
    assert referentiel.percentages[("1", "2", "1")] == 0.5
def test_notation_only_root_default_status():
    referentiel = Referentiel(root_action=make_action_referentiel())
    notation = Notation(referentiel)

    scores = notation.compute_and_get_scores()

    assert_score_with_nomenclature_id_equals(
        scores,
        "",
        points=0.0,
        percentage=0.0,
        potentiel=defaut_referentiel_root_points_value,
        referentiel_points=defaut_referentiel_root_points_value,
        referentiel_percentage=1,
    )
示例#4
0
def test_notation_only_root_default_status():
    # todo, do we want to keep this ?
    referentiel = Referentiel(root_action=make_action_referentiel(points=42),
                              mesure_depth=0)
    notation = Notation(referentiel)

    scores = notation.compute_and_get_scores()

    assert_score_with_nomenclature_id_equals(
        scores,
        "",
        points=0.0,
        percentage=0.0,
        potentiel=42,
        referentiel_points=42,
        referentiel_percentage=1,
    )
示例#5
0
def referentiel() -> Referentiel:
    action_1_1 = make_action_referentiel(id_nomenclature="1.1",
                                         actions=[],
                                         points=30)
    action_1_2 = make_action_referentiel(id_nomenclature="1.2",
                                         actions=[],
                                         points=70)
    action_1 = make_action_referentiel(id_nomenclature="1",
                                       actions=[action_1_1, action_1_2],
                                       points=100)
    action_2_0 = make_action_referentiel(id_nomenclature="2.0",
                                         actions=[],
                                         points=0)
    action_2_1 = make_action_referentiel(id_nomenclature="2.1",
                                         actions=[],
                                         points=100)
    action_2 = make_action_referentiel(id_nomenclature="2",
                                       actions=[action_2_0, action_2_1],
                                       points=100)
    action_3 = make_action_referentiel(id_nomenclature="3", points=300)
    root_action = make_action_referentiel(
        actions=[action_1, action_2, action_3])
    referentiel = Referentiel(root_action, mesure_depth=1)
    return referentiel
def test_referentiel_fails_when_wrong_root_action():
    with pytest.raises(ReferentielValueError):
        referentiel = Referentiel(
            root_action=make_action_referentiel(id_nomenclature="not_empty"),
            mesure_depth=3,
        )
def test_referentiel_when_root_action_has_one_mesure():
    action_1_1_1_0 = make_action_referentiel(
        id="ref__1_1_1_0",
        id_nomenclature="1.1.1.0",
        actions=[],
        points=0,  # Réglementaire
    )

    action_1_1_1_1 = make_action_referentiel(
        id="ref__1_1_1_1",
        id_nomenclature="1.1.1.1",
        actions=[],
        points=20  # %
    )
    action_1_1_1_2 = make_action_referentiel(
        id="ref__1_1_1_2",
        id_nomenclature="1.1.1.2",
        actions=[],  # No points specified !
    )

    action_1_1_1 = make_action_referentiel(
        id="ref__1_1_1",
        id_nomenclature="1.1.1",
        actions=[action_1_1_1_0, action_1_1_1_1, action_1_1_1_2],
        points=30,  # %
    )
    action_1_1_2 = make_action_referentiel(
        id="ref__1_1_2",
        id_nomenclature="1.1.2",
        actions=[],
        points=70  # %
    )

    action_1_2_1 = make_action_referentiel(id="ref__1_2_1",
                                           id_nomenclature="1.2.1",
                                           actions=[])

    action_1_2 = make_action_referentiel(id="ref__1_2",
                                         id_nomenclature="1.2",
                                         actions=[action_1_2_1],
                                         points=200)
    action_1_1 = make_action_referentiel(
        id="ref__1_1",
        id_nomenclature="1.1",
        actions=[action_1_1_1, action_1_1_2],
        points=300,
    )

    action_1 = make_action_referentiel(id="ref__1",
                                       id_nomenclature="1",
                                       actions=[action_1_1, action_1_2])

    root_action = make_action_referentiel(id="ref",
                                          id_nomenclature="",
                                          actions=[action_1])
    referentiel = Referentiel(root_action, mesure_depth=2)

    assert referentiel.forward == [
        (),
        ("1", ),
        ("1", "1"),
        ("1", "2"),
        ("1", "1", "1"),
        ("1", "1", "2"),
        ("1", "2", "1"),
        ("1", "1", "1", "0"),
        ("1", "1", "1", "1"),
        ("1", "1", "1", "2"),
    ]

    expected_points = {
        (): 500.0,
        ("1", ): 500.0,
        ("1", "1"): 300.0,
        ("1", "2"): 200.0,
        ("1", "1", "1"): 90.0,  # 30% of 300.0
        ("1", "1", "2"): 210.0,  # 70% of 300.0
        ("1", "2", "1"): 200.0,  # 100% of 200.0
        ("1", "1", "1", "0"): 0,  # 0% of 90.0
        ("1", "1", "1", "1"): 18.0,  # 20% of 90.0
        ("1", "1", "1", "2"): 72.0,  # 80% of 90.0
    }

    expected_percentages = {
        (): 1,
        ("1", ): 1,
        ("1", "1"): 3 / 5,
        ("1", "2"): 2 / 5,
        ("1", "1", "1"): 0.3,
        ("1", "1", "2"): 0.7,
        ("1", "2", "1"): 1.0,
        ("1", "1", "1", "0"): 0.0,
        ("1", "1", "1", "1"): 0.2,
        ("1", "1", "1", "2"): 0.8,
    }

    expected_childless_descendant = {
        (): 5,
        ("1", ): 5,
        ("1", "1"): 4,
        ("1", "2"): 1,
        ("1", "1", "1"): 3,
        ("1", "1", "2"): 0,
        ("1", "2", "1"): 0,
        ("1", "1", "1", "0"): 0,
        ("1", "1", "1", "1"): 0,
        ("1", "1", "1", "2"): 0,
    }

    for action_index in referentiel.forward:
        assert (
            referentiel.points[action_index] == expected_points[action_index]
        ), f"Error in points at index {action_index}"

        assert (referentiel.percentages[action_index] ==
                expected_percentages[action_index]
                ), f"Error in percentage at index {action_index}"

        assert (referentiel.childless_descendant[action_index] ==
                expected_childless_descendant[action_index]
                ), f"Error in childless descendant at index {action_index}"
def test_referentiel_when_some_root_action_has_no_actions():
    root_action = make_action_referentiel(actions=[])
    referentiel = Referentiel(root_action, mesure_depth=3)
    assert referentiel.backward == [()]
    assert referentiel.forward == [()]
示例#9
0
def test_notation_non_concernee_changes_parents_potentiels():
    """
    A l'intérieur d'une mesure/orientation :
    - Si une action a un statut "Non concernée", alors cette action n'est pas prise en compte pour calculer le score.
    *Exemple : Orientation 1.2. = 30 points
    Si niveau 1.2.1 dont le poids est 20% est "Non concerné" alors l'orientation 1.2 reste évaluée sur 30 points
    et le poids est reventilé sur les autres niveaux en augmentant de façon proportionnelle
        - 1.2.2 = 20% + 1/3 x 20%
        - 1.2.3 = 20% + 1/3 x 20%
        - 1.2.4 = 40% + 1/3 x 40%

    - Si toutes les actions sœurs ont un statut "Non concernée" (en dehors des mesures/orientations),
    alors le niveau parent est "Non concerné" et l'action n'est pas prise en compte pour calculer le score.
    *Exemple : Niveau 1.2.1.
    Si 1.2.1.1/2/3/4/5 sont "Non concernée" alors 1.2.1 = Non concernée*

    - Cas particulier : Si tous les enfants d'une mesure/orientation sont "Non concernée"
    alors la mesure/orientation a bien un statut "Non concernée"
    MAIS son nombre de points passe à "0" sans être reventilé sur les autres mesures/orientations.

    *Exemple : Orientation 1.2 = 30 points
    Si 1.2.1/2/3/4 = "Non concernée"
    alors 1.2 = "Non concernée" et "0/0 points" et la collectivité n'est plus évaluée sur 500 points mais sur 470 points.*
    """
    action_1_2_1 = make_action_referentiel(id_nomenclature="1.2.1",
                                           actions=[],
                                           points=25)
    action_1_2_2 = make_action_referentiel(id_nomenclature="1.2.2",
                                           actions=[],
                                           points=25)
    action_1_2_3 = make_action_referentiel(id_nomenclature="1.2.3",
                                           actions=[],
                                           points=25)
    action_1_2_4 = make_action_referentiel(id_nomenclature="1.2.4",
                                           actions=[],
                                           points=25)
    action_1_2 = make_action_referentiel(
        id_nomenclature="1.2",
        actions=[action_1_2_1, action_1_2_2, action_1_2_3, action_1_2_4],
        points=30,
    )
    action_1 = make_action_referentiel(id_nomenclature="1",
                                       actions=[action_1_2])
    action_2_2 = make_action_referentiel(
        id_nomenclature="2.2",
        actions=[],
        points=470,
    )

    action_2 = make_action_referentiel(id_nomenclature="2",
                                       actions=[action_2_2])

    root_action = make_action_referentiel(actions=[action_1, action_2])

    referentiel = Referentiel(root_action, mesure_depth=2)

    notation = Notation(referentiel)

    notation.set_status(index=("1", "2", "1"), status=Status.non_concernee)
    notation.set_status(index=("1", "2", "2"), status=Status.non_concernee)
    notation.set_status(index=("1", "2", "3"), status=Status.non_concernee)
    notation.set_status(index=("1", "2", "4"), status=Status.non_concernee)

    scores = notation.compute_and_get_scores()

    assert_score_with_nomenclature_id_equals(
        scores,
        "",
        points=0.0,
        percentage=0.0,
        potentiel=470,
        referentiel_points=500,
        referentiel_percentage=1,
    )

    assert_score_with_nomenclature_id_equals(
        scores,
        "1",
        points=0,
        percentage=0.0,
        potentiel=0,
        referentiel_points=30,
        referentiel_percentage=30 / 500,
    )

    assert_score_with_nomenclature_id_equals(
        scores,
        "1.2",
        points=0,
        percentage=0.0,
        potentiel=0,
        referentiel_points=30,
        referentiel_percentage=1,
    )

    assert_score_with_nomenclature_id_equals(
        scores,
        "1.2.1",
        points=0,
        percentage=0.0,
        potentiel=0,
        referentiel_points=30 / 4,
        referentiel_percentage=1 / 4,
    )

    assert_score_with_nomenclature_id_equals(
        scores,
        "2",
        points=0,
        percentage=0.0,
        potentiel=470,
        referentiel_points=470,
        referentiel_percentage=0.94,
    )