Best Python code snippet using localstack_python
poc_1.py
Source:poc_1.py
...27 x = fix_point(uniform(x_low, x_high))28 y = fix_point(uniform(y_low, y_high))29 ret_group.append((x,y))30 return ret_group31def populate_graph(nx_G, coor_list, nc, res_tup, num_c):32 for coor in coor_list:33 nx_G.add_node(nc, pos=coor, res=uniform(res_tup[0], res_tup[1]),34 mem=num_c)35 nc += 136 return nc37def populate_graph_random(nx_G, coor_list, nc, res_tup, num_groups):38 for coor in coor_list:39 num_c = randint(1, num_groups)40 nx_G.add_node(nc, pos=coor, res=uniform(res_tup[0], res_tup[1]),41 mem=num_c)42 nc += 143 return nc44def populate_edges(nx_G, dist_thres):45 for n_1, attr_1 in nx_G.nodes(data=True):46 G.add_edges_from([(n_1, n_2) for n_2, attr_2 in nx_G.nodes(data=True)47 if n_1 != n_2 48 and (distance(attr_1['pos'], attr_2['pos']) <= dist_thres)])49def build_data(nx_G):50 ret_data = []51 header = ["node", "x", "y", "res_val", "connections", "cluster_num"]52 ret_data.append(header)53 for n, attr in nx_G.nodes(data=True):54 tmp = [n, attr['pos'][0], attr['pos'][1], attr['res'], nx_G.edges(n), attr['mem']]55 ret_data.append(tmp)56 return ret_data57def write_to_csv(fname, data):58 tmp_f = open(fname, 'w')59 with tmp_f:60 writer = csv.writer(tmp_f)61 writer.writerows(data)62def save_g(nx_G, fname):63 json.dump(dict(nodes=[[n, nx_G.node[n]] for n in nx_G.nodes()],64 edges=[[u, v, nx_G.edge[u][v]] for u,v in nx_G.edges()],65 attrs=[[n, attr['pos'], attr['res']] for n, attr in nx_G.nodes(data=True)]),66 open(fname, 'w'), indent=2)67def load_g(fname):68 nx_G = nx.Graph()69 d = json.load(open(fname))70 nx_G.add_nodes_from(d['nodes'])71 nx_G.add_edges_from(d['edges'])72 attr = d['attrs']73 return nx_G, attr74####################################75G = nx.Graph()76group_1 = gen_random_points(-1, 1, -1, 1, 250)77group_2 = gen_random_points(-1, 1, -1, 1, 250)78group_3 = gen_random_points(-1, 1, -1, 1, 250)79group_4 = gen_random_points(-1, 1, -1, 1, 250)80NODE_COUNT = populate_graph_random(G, group_1, NODE_COUNT, (0.0, 0.25), 4)81NODE_COUNT = populate_graph_random(G, group_2, NODE_COUNT, (0.25, 0.5), 4)82NODE_COUNT = populate_graph_random(G, group_3, NODE_COUNT, (0.5, 0.75), 4)83NODE_COUNT = populate_graph_random(G, group_4, NODE_COUNT, (0.75, 1), 4)84# group_11 = gen_normal_points(1, 1, 0.3, 0.25, 25)85# group_01 = gen_normal_points(-1, 1, 0.3, 0.25, 25)86# group_10 = gen_normal_points(1, -1, 0.3, 0.25, 25)87# group_00 = gen_normal_points(-1, -1, 0.3, 0.25, 25)88# NODE_COUNT = populate_graph(G, group_11, NODE_COUNT, (0.75, 1.0), 0)89# NODE_COUNT = populate_graph(G, group_01, NODE_COUNT, (0.5, 0.75), 1)90# NODE_COUNT = populate_graph(G, group_10, NODE_COUNT, (0.25, 0.5), 2)91# NODE_COUNT = populate_graph(G, group_00, NODE_COUNT, (0.0, 0.25), 3)92populate_edges(G, 0.10)93res_list = [attr['res'] for _,attr in G.nodes(data=True)]94nx.draw(G, cmap=plt.get_cmap('Blues'), node_color=res_list)95plt.show()96write_to_csv("poc_2.csv", build_data(G))...
graphPlay.py
Source:graphPlay.py
...11 self.visited = visited12 self.ID = ID13# Let's manually build a graph. Create 10 nodes and keep an id for each node in this graph dictionary.14graph = {ID : Node() for ID in range(10)}15def populate_graph(graph, node_ID, value, children):16 graph[node_ID].value = value17 graph[node_ID].children = children18 graph[node_ID].ID = node_ID19populate_graph(graph, 0, 5, [graph[1],graph[9]])20populate_graph(graph, 1, 9, [graph[2],graph[4]])21populate_graph(graph, 2, 7, [graph[3]])22populate_graph(graph, 3, 2, [graph[1]])23populate_graph(graph, 4, 3, [graph[5],graph[6],graph[7]])24populate_graph(graph, 5, 7, [])25populate_graph(graph, 6, 3, [])26populate_graph(graph, 7, 5, [graph[8]])27populate_graph(graph, 8, 8, [])28populate_graph(graph, 9, 1, [graph[8]])29def bfs(graph,root):30 # Let's do a breadth first search that prints when it visits each node.31 q = Queue()32 q.put(root)33 while q:34 current_node = q.get()35 current_node.visited = True36 print(f'We just visited node {current_node.ID}\n')37 for child in current_node.children:38 if not child.visited:39 q.put(child)40def dfs(graph,root):41 # Let's do a depth first search that prints when it visits each node.42 # Notice we don't visit a node twice, otherwise we would get caught in ...
scholargraph.py
Source:scholargraph.py
1import scholarly as sch2import networkx as nx3def populate_graph(paper, graph):4 '''5 :param paper: scholarly.Publication6 :param graph: networkx.classes.digraph.DiGraph7 :return: None8 '''9 # make node for initial paper in the graph10 graph.add_node(paper.bib['ID'], paper=paper)11 print paper.bib['ID']12 # get citations13 for citation in paper.get_citedby():14 # retrieve full paper information15 citation = citation.fill()16 # check to see if the paper is already on the graph17 if citation.bib['ID'] in graph.nodes():18 # if it already is just add the new edge19 graph.add_edge(paper.bib['ID'], citation.bib['ID'])20 else:21 # if not add the node, and the edge, and populate its children22 graph.add_node(citation.bib['ID'], paper=citation)23 graph.add_edge(paper.bib['ID'], citation.bib['ID'])24 populate_graph(citation, graph)25def test_pop():26 import matplotlib.pyplot as plt27 G = nx.DiGraph()28 search_query = sch.search_pubs_query('10.1109/THS.2013.6698999')29 P = search_query.next()30 P = P.fill()31 populate_graph(P, G)32 nx.draw_spectral(G)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!