Exemplo n.º 1
0
Arquivo: sym.py Projeto: bozzyk/cmds
    def get_cells_contours(self, precision):
        pb = ProgressBar(total=100,
                         decimals=2,
                         prefix="getting cells contours",
                         length=terminal_size.get_terminal_size()[0] - 40,
                         fill='#',
                         zfill='-')
        contours = {}
        l = 1
        step = 100 / len(self.struct)
        for i in self.struct.values():

            x0, x1 = i[0][0], i[0][1]
            y0, y1 = i[1][0], i[1][1]

            bottom_dots = self.section_divide((x0, y0), (x1, y0), precision)
            right_dots = self.section_divide((x1, y0), (x1, y1), precision)
            top_dots = self.section_divide((x1, y1), (x0, y1), precision)
            left_dots = self.section_divide((x0, y1), (x0, y0), precision)

            inner_dots = []
            for k in bottom_dots:
                for j in left_dots:
                    inner_dots.append((k[0], j[1]))

            contours[str(l)] = [(x0, y0)] + bottom_dots + [
                (x1, y0)
            ] + right_dots + [(x1, y1)] + top_dots + [
                (x0, y1)
            ] + left_dots + inner_dots

            pb.print_progress_bar(step * l)

            l += 1
        self.contours = contours
Exemplo n.º 2
0
Arquivo: sym.py Projeto: bozzyk/cmds
    def get_symbolic_image(self, precision, f, g):
        self.get_cells_contours(precision)
        self.get_cells_images(f, g)
        self.get_cells_intersects()

        pb = ProgressBar(total=100,
                         decimals=2,
                         prefix="building graph",
                         length=terminal_size.get_terminal_size()[0] - 45,
                         fill='#',
                         zfill='-')
        step = 50 / len(self.struct)
        m = 1
        G = nx.DiGraph()
        for i in self.struct:
            G.add_node(i)
            pb.print_progress_bar(m * step)
            m += 1

        step = 50 / len(self.intersects)
        m = 1
        for i in self.intersects:
            for j in self.intersects[i]:
                G.add_edge(i, j)
            pb.print_progress_bar(m * step)
            m += 1

        self.symbolic_image = G
        self.clear_table()
Exemplo n.º 3
0
Arquivo: sym.py Projeto: bozzyk/cmds
    def clear_table(self):
        pb = ProgressBar(total=100,
                         decimals=2,
                         prefix="clearing table",
                         length=terminal_size.get_terminal_size()[0] - 40,
                         fill='#',
                         zfill='-')
        connected = tuple(nx.strongly_connected_components(
            self.symbolic_image))
        remember = set()
        rest = {}
        for i in connected:
            if len(i) > 1:
                remember.update(i)
            # else:
            #     try: nx.find_cycle(self.symbolic_image, i)
            #     except nx.exception.NetworkXNoCycle: pass
            #     else: remember.update(i)

        step = 100 / len(self.struct)
        k = 1
        m = 1
        for i in self.struct:
            if i in remember:
                rest[str(k)] = self.struct[i]
                k += 1
            pb.print_progress_bar(m * step)
            m += 1

        self.struct = rest
Exemplo n.º 4
0
 def __init__(
     self, min_value=0, max_value=100, start_value=None, show_as_percents=True, output=sys.stderr, width=None
 ):
     self.__min = min_value
     self.__max = max_value
     self.__value = start_value if start_value is not None else min_value
     self.__show_as_percents = show_as_percents
     self.__output = output
     self.__term_width = width or get_terminal_size()[1]
Exemplo n.º 5
0
def Table(data_arr, keys, opts={}):
    if type(data_arr) != list: data_arr = [data_arr]

    # TODO - doesn't take into account row data that is too long.
    #        need to back out of verticle or build data in list
    #        then determine format
    max_width = len("   ".join(keys))
    console_width = terminal_size.get_terminal_size()[0]

    if max_width < console_width:
        return (Cols(data_arr, keys, opts))
    else:
        return (Rows(data_arr, keys, opts))
Exemplo n.º 6
0
def Table(data_arr,keys,opts={}):
	if type(data_arr) != list:  data_arr = [data_arr]

	# TODO - doesn't take into account row data that is too long.  
	#        need to back out of verticle or build data in list
	#        then determine format
	max_width = len("   ".join(keys))
	console_width = terminal_size.get_terminal_size()[0]

	if max_width<console_width:
		return(Cols(data_arr,keys,opts))
	else:
		return(Rows(data_arr,keys,opts))
Exemplo n.º 7
0
Arquivo: sym.py Projeto: bozzyk/cmds
    def get_cells_images(self, f, g):  #f,g - lambdified functions of x,y
        pb = ProgressBar(total=100,
                         decimals=2,
                         prefix="getting cells images",
                         length=terminal_size.get_terminal_size()[0] - 40,
                         fill='#',
                         zfill='-')
        images = {}
        j = 1
        step = 100 / len(self.contours)
        for i in self.contours.values():
            images[str(j)] = list(
                map(lambda x: (f(x[0], x[1]), g(x[0], x[1])), i))
            pb.print_progress_bar(step * j)
            j += 1

        self.images = images
Exemplo n.º 8
0
Arquivo: sym.py Projeto: bozzyk/cmds
 def get_cells_intersects(self):
     pb = ProgressBar(total=100,
                      decimals=2,
                      prefix="getting cells intersects",
                      length=terminal_size.get_terminal_size()[0] - 45,
                      fill='#',
                      zfill='-')
     intersects = {}
     m = 1
     step = 100 / (len(self.images) * len(self.images['1']))
     for i in self.images:
         intersects[i] = set()
         for j in self.images[i]:
             for k in self.struct:
                 if self.dot_in_cell(j, self.struct[k]):
                     intersects[i].add(k)
             pb.print_progress_bar(step * m)
             m += 1
     self.intersects = intersects