Ejemplo n.º 1
0
    def form_image(self, prices, screen_draw):
        screen_draw.rectangle((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
                              fill="#ffffff")
        if self.mode == "candle":
            Plot.candle(prices,
                        size=(SCREEN_WIDTH - 45, SCREEN_HEIGHT - 27),
                        position=(41, 0),
                        draw=screen_draw)
        else:
            last_prices = [x[3] for x in prices]
            Plot.line(last_prices,
                      size=(SCREEN_WIDTH - 42, SCREEN_HEIGHT - 27),
                      position=(42, 0),
                      draw=screen_draw)

        flatten_prices = [item for sublist in prices for item in sublist]
        Plot.y_axis_labels(flatten_prices,
                           FONT_SMALL, (0, 0), (38, SCREEN_HEIGHT - 34),
                           draw=screen_draw,
                           labels_number=5)
        screen_draw.line([(10, SCREEN_HEIGHT - 25), (470, SCREEN_HEIGHT - 25)])
        screen_draw.line([(39, 4), (39, SCREEN_HEIGHT - 27)])
        screen_draw.line([(60, SCREEN_HEIGHT - 23), (60, SCREEN_HEIGHT - 1)])
        # screen_draw.text((-1, SCREEN_HEIGHT - 27), "XXX"[:3], font=FONT_LARGE, fill=None)
        Plot.caption(flatten_prices[len(flatten_prices) - 1],
                     SCREEN_HEIGHT - 27,
                     SCREEN_WIDTH - 45,
                     FONT_LARGE,
                     screen_draw,
                     price_offset=0)
        Plot.percentage(prices, SCREEN_WIDTH - 56, SCREEN_HEIGHT - 27,
                        FONT_LARGE, screen_draw)

        screen_draw.line([(366, SCREEN_HEIGHT - 23), (366, SCREEN_HEIGHT - 1)])
Ejemplo n.º 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
Ejemplo n.º 3
0
    def form_image(self, prices, screen_draw):
        screen_draw.rectangle((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
                              fill="#ffffff")
        screen_draw = self.screen_draw
        if self.mode == "candle":
            Plot.candle(prices,
                        size=(SCREEN_WIDTH - 45, 93),
                        position=(41, 0),
                        draw=screen_draw)
        else:
            last_prices = [x[3] for x in prices]
            Plot.line(last_prices,
                      size=(SCREEN_WIDTH - 42, 93),
                      position=(42, 0),
                      draw=screen_draw)

        flatten_prices = [item for sublist in prices for item in sublist]
        Plot.y_axis_labels(flatten_prices,
                           FONT_SMALL, (0, 0), (38, 89),
                           draw=screen_draw)
        screen_draw.line([(10, 98), (240, 98)])
        screen_draw.line([(39, 4), (39, 94)])
        screen_draw.line([(60, 102), (60, 119)])
        Plot.caption(flatten_prices[len(flatten_prices) - 1], 95, SCREEN_WIDTH,
                     FONT_LARGE, screen_draw)
Ejemplo n.º 4
0
    def form_image(self, prices):
        self.draw_black.rectangle((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
                                  fill="white")
        screen_draw = self.draw_black
        if self.mode == "candle":
            Plot.candle(prices,
                        size=(SCREEN_WIDTH - 38, 79),
                        position=(35, 0),
                        draw=screen_draw)
        else:
            last_prices = [x[3] for x in prices]
            Plot.line(last_prices,
                      size=(SCREEN_WIDTH - 36, 79),
                      position=(36, 0),
                      draw=screen_draw)

        flatten_prices = [item for sublist in prices for item in sublist]
        Plot.y_axis_labels(flatten_prices,
                           FONT_SMALL, (0, 0), (32, 76),
                           draw=screen_draw)
        screen_draw.line([(9, 83), (204, 83)])
        screen_draw.line([(33, 3), (33, 80)])
        screen_draw.line([(51, 87), (51, 101)])
        Plot.caption(flatten_prices[len(flatten_prices) - 1], 81, SCREEN_WIDTH,
                     FONT_LARGE, screen_draw)
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    def form_image(self, prices, screen_draw):
        screen_draw.rectangle((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
                              fill="#ffffff")
        screen_draw = self.screen_draw
        if self.mode == "candle":
            Plot.candle(prices,
                        size=(SCREEN_WIDTH - 45, 130),
                        position=(41, 2),
                        draw=screen_draw)
        else:
            last_prices = [x[3] for x in prices]
            Plot.line(last_prices,
                      size=(SCREEN_WIDTH - 42, 130),
                      position=(42, 2),
                      draw=screen_draw)

        flatten_prices = [item for sublist in prices for item in sublist]
        Plot.y_axis_labels(flatten_prices,
                           FONT_SMALL, (0, 2), (38, 126),
                           draw=screen_draw)

        screen_draw.line([(39, 4), (39, 129)])
        screen_draw.line([(65, SCREEN_HEIGHT - 30), (65, SCREEN_HEIGHT - 5)])
        screen_draw.line([(5, SCREEN_HEIGHT - 40), (255, SCREEN_HEIGHT - 40)])
        Plot.caption(flatten_prices[len(flatten_prices) - 1],
                     SCREEN_HEIGHT - 35, SCREEN_WIDTH, FONT_LARGE, screen_draw)
Ejemplo n.º 7
0
    def update(self, prices):
        image = Image.new('1', (SCREEN_WIDTH, SCREEN_HEIGHT), 255)
        screen_draw = ImageDraw.Draw(image)
        if self.mode == "candle":
            Plot.candle(prices,
                        size=(SCREEN_WIDTH - 45, 93),
                        position=(41, 0),
                        draw=screen_draw)
        else:
            last_prices = [x[3] for x in prices]
            Plot.line(last_prices,
                      size=(SCREEN_WIDTH - 42, 93),
                      position=(42, 0),
                      draw=screen_draw)

        flatten_prices = [item for sublist in prices for item in sublist]
        Plot.y_axis_labels(flatten_prices,
                           FONT_SMALL, (0, 0), (38, 89),
                           draw=screen_draw)
        screen_draw.line([(10, 98), (240, 98)])
        screen_draw.line([(39, 4), (39, 94)])
        screen_draw.line([(60, 102), (60, 119)])
        Plot.caption(flatten_prices[len(flatten_prices) - 1], 95, SCREEN_WIDTH,
                     FONT_LARGE, screen_draw)
        image.save(self.filename)
Ejemplo n.º 8
0
    def form_image(self, prices):
        WHITE = self.inky_display.WHITE
        RED = self.inky_display.RED
        BLACK = self.inky_display.BLACK
        screen_draw = ImageDraw.Draw(self.image)
        screen_draw.rectangle([0,0,SCREEN_WIDTH,SCREEN_HEIGHT],fill=WHITE)
        if self.mode == "candle":
            Plot.candle(prices, size=(SCREEN_WIDTH - LEFT_MARGIN, SCREEN_HEIGHT - BOTTOM_MARGIN), position=(LEFT_MARGIN, 0), draw=screen_draw, fill_neg=RED, fill_pos=BLACK)
        else:
            last_prices = [x[3] for x in prices]
            Plot.line(last_prices, size=(SCREEN_WIDTH - LEFT_MARGIN, SCREEN_HEIGHT - BOTTOM_MARGIN), position=(LEFT_MARGIN, 0), draw=screen_draw, fill=BLACK)

        flatten_prices = [item for sublist in prices for item in sublist]
        Plot.y_axis_labels(flatten_prices, FONT_SMALL, (0, 0), (LEFT_MARGIN, SCREEN_HEIGHT - BOTTOM_MARGIN - SMALL_FONT_SIZE - 3), draw=screen_draw, fill=BLACK)
        screen_draw.line([(0, SCREEN_HEIGHT - BOTTOM_MARGIN), (SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_MARGIN)], fill=BLACK)
        screen_draw.line([(LEFT_MARGIN, 0), (LEFT_MARGIN, SCREEN_HEIGHT - BOTTOM_MARGIN)], fill=BLACK)
        Plot.caption(flatten_prices[len(flatten_prices) - 1], SCREEN_HEIGHT - BOTTOM_MARGIN, SCREEN_WIDTH, FONT_LARGE, screen_draw, fill=BLACK, currency_offset=LEFT_MARGIN, price_offset=LEFT_MARGIN)