Exemple #1
0
    def apply_model(self, plot: Plot, years: int, value: float):

        Tools.print_log_line('Aplicando cut down sistemática', logging.INFO)

        new_plot = Plot()
        new_plot.clone(plot)

        order_criteria = OrderCriteria()
        order_criteria.add_criteria('dbh')

        search_criteria = SearchCriteria()
        search_criteria.add_criteria('status', None, EQUAL)

        trees = Tree.get_sord_and_order_tree_list(plot.trees,
                                                  search_criteria=search_criteria,
                                                  order_criteria=order_criteria)

        for tree in trees:

            new_tree = Tree()
            new_tree.clone(tree)

            new_tree.add_value('expan', tree.expan * ((100 - value) / 100))
            new_tree.add_value('status', None)
            new_plot.add_tree(new_tree)

            cut_tree = Tree()
            cut_tree.clone(tree)
            cut_tree.add_value('status', 'C')
            cut_tree.add_value('expan', tree.expan - new_tree.expan)

            if cut_tree.expan > 0:
                new_plot.add_tree(cut_tree)

        return new_plot
Exemple #2
0
    def apply_model(self, plot: Plot, years: int, value: float):

        Tools.print_log_line('Aplicando corta por el menor', logging.INFO)

        accumulator = 0
        cut_all_the_rest = False

        new_plot = Plot()
        new_plot.clone(plot)

        order_criteria = OrderCriteria(ASC)
        order_criteria.add_criteria('dbh')

        search_criteria = SearchCriteria()
        search_criteria.add_criteria('status', None, EQUAL)

        trees = Tree.get_sord_and_order_tree_list(plot.trees,
                                                  search_criteria=search_criteria,
                                                  order_criteria=order_criteria)

        cut_discriminator = self.type.cut_discriminator(trees, value)

        for tree in trees:

            accumulator += self.type.accumulator(tree)

            if not cut_all_the_rest:

                new_tree = Tree()
                new_tree.clone(tree)

                if accumulator >= cut_discriminator:

                    cut_all_the_rest = True
                    new_expan = self.type.compute_expan(tree, accumulator, cut_discriminator)

                    if new_expan <= 0:
                        new_tree.add_value('expan', new_expan)
                        new_tree.add_value('status', 'C')
                    else:
                        cut_tree = Tree()
                        cut_tree.clone(tree)
                        cut_tree.add_value('status', 'C')
                        cut_tree.add_value('expan', new_expan)

                        if cut_tree.expan > 0:
                            new_plot.add_tree(cut_tree)

                        new_tree.sub_value('expan', new_expan)
                        new_tree.add_value('status', None)

                new_plot.add_tree(new_tree)

            else:
                new_tree = Tree()
                new_tree.clone(tree)
                new_tree.add_value('status', 'C')
                new_plot.add_tree(new_tree)

        return new_plot
Exemple #3
0
def test_get_criteria_1():

    real_input: str = 'VALUE'

    tmp_order_criteria = OrderCriteria()
    tmp_order_criteria.add_criteria(real_input)
    real_output: str = tmp_order_criteria.get_criteria(0)
    expected_output: str = 'VALUE'

    assert real_output == expected_output
Exemple #4
0
def test_criterion_1():

    real_input: str = 'VALUE'

    tmp_order_criteria = OrderCriteria()
    tmp_order_criteria.add_criteria(real_input)
    real_output: list = tmp_order_criteria.criterion
    expected_output: list = [real_input]

    assert real_output == expected_output
Exemple #5
0
def test_get_first_1():

    real_input_1: str = 'VALUE1'

    tmp_order_criteria = OrderCriteria()
    tmp_order_criteria.add_criteria(real_input_1)
    real_output: str = tmp_order_criteria.get_first()
    expected_output: str = 'VALUE1'

    assert real_output == expected_output
Exemple #6
0
def test_criterion_2():

    real_input_1: str = 'VALUE1'
    real_input_2: str = 'VALUE2'

    tmp_order_criteria = OrderCriteria()
    tmp_order_criteria.add_criteria(real_input_1)
    tmp_order_criteria.add_criteria(real_input_2)
    real_output: list = tmp_order_criteria.criterion
    expected_output: list = [real_input_1, real_input_2]

    assert real_output == expected_output
Exemple #7
0
def test_get_len():

    real_input_1: str = 'VALUE0'
    real_input_2: str = 'VALUE1'

    tmp_order_criteria = OrderCriteria()
    tmp_order_criteria.add_criteria(real_input_1)
    tmp_order_criteria.add_criteria(real_input_2)
    real_output: int = tmp_order_criteria.len()
    expected_output: int = 2

    assert real_output == expected_output
Exemple #8
0
def test_type_without_value():

    tmp_order_criteria = OrderCriteria()
    real_output: int = tmp_order_criteria.type
    expected_output: int = DESC

    assert real_output == expected_output
Exemple #9
0
def test_type_with_value():

    real_input: int = ASC

    tmp_order_criteria = OrderCriteria(real_input)
    real_output: int = tmp_order_criteria.type
    expected_output: int = ASC

    assert real_output == expected_output
Exemple #10
0
def test_get_criteria_2():

    real_input_1: str = 'VALUE1'
    real_input_2: str = 'VALUE2'
    real_input_3: str = 'VALUE3'

    tmp_order_criteria = OrderCriteria()
    tmp_order_criteria.add_criteria(real_input_1)
    tmp_order_criteria.add_criteria(real_input_2)
    tmp_order_criteria.add_criteria(real_input_3)
    real_output: str = tmp_order_criteria.get_criteria(2)
    expected_output: str = 'VALUE3'

    assert real_output == expected_output
Exemple #11
0
def test_init():

    tmp_order_criteria = OrderCriteria()
    assert isinstance(tmp_order_criteria, OrderCriteria) is True