def prepare(GESTURES, SHOW=True, SAVE=False, DEBUG=False): if SHOW: for gest in GESTURES: df = pd.read_csv(BASE_DIR + gest + ".csv") g.graph(df, SAVE) # create a one-hot encoded matrix that is used in the output ONE_HOT_ENCODED_GESTURES = np.eye(len(GESTURES)) if DEBUG: print(ONE_HOT_ENCODED_GESTURES) # Will hold the input data in inputs and matching clasification in outputs inputs = [] outputs = [] # read each csv file and push an input and output for gesture_index in range(len(GESTURES)): gesture = GESTURES[gesture_index] print(f"Processing index {gesture_index} for gesture '{gesture}'.") output = ONE_HOT_ENCODED_GESTURES[gesture_index] # df = pd.read_csv("/content/" + gesture + ".csv") df = pd.read_csv(BASE_DIR + gesture + ".csv") # calculate the number of gesture recordings in the file num_recordings = int(df.shape[0] / SAMPLES_PER_GESTURE) print(f"\tThere are {num_recordings} recordings of the {gesture} gesture.") for i in range(num_recordings): tensor = [] for j in range(SAMPLES_PER_GESTURE): index = i * SAMPLES_PER_GESTURE + j # normalize the input data, between 0 to 1: # - acceleration is between: -4 to +4 # - gyroscope is between: -2000 to +2000 tensor += [ (df['aX'][index] + 4) / 8, (df['aY'][index] + 4) / 8, (df['aZ'][index] + 4) / 8, (df['gX'][index] + 2000) / 4000, (df['gY'][index] + 2000) / 4000, (df['gZ'][index] + 2000) / 4000 ] inputs.append(tensor) outputs.append(output) # convert the list to numpy array inputs = np.array(inputs) outputs = np.array(outputs) return inputs, outputs
def graphics(self): # # Plot frequences per each score assigned by chosen algorithm algo = "" if int(self.v.get()) == 1: algo = "Qgrs" if int(self.v.get()) == 2: algo = "QgrsWeb" if int(self.v.get()) == 3: algo = "Pqs" print(qlibs.get_scorename(algo)) graphs.graph(self.pop.get(), self.file.get(), qlibs.get_scorename(algo), self.tit.get(), True) return
def shape(s): # not creating exctra variable using global variables global animation global A global B global a global b global c global d global r #set variables as radio button A, B, a, c, b, d, r = graph(s) # set value of sliders as radio button sxphase.valinit, syphase.valinit, sxamp.valinit, syamp.valinit, sxfreq.valinit, syfreq.valinit, sphase_diff.valinit = b, d, A, B, a, c, r sxphase.reset() syphase.reset() sxamp.reset() syamp.reset() sxfreq.reset() syfreq.reset() sphase_diff.reset() fig.canvas.draw_idle()
def get(self, graph_param): try: graph_type, graph_interval = graph_param.split("-") except ValueError: raise web.HTTPError(404) if graph_type not in graphs.GRAPH_TYPES.keys(): raise web.HTTPError(404) if graph_interval not in graphs.GRAPH_INTERVALS.keys(): raise web.HTTPError(404) self.set_header("Content-Type", "image/png") self.write(graphs.graph(graph_type, graph_interval))
while not checking_now.empty(): node = checking_now.get() for index, route in enumerate(routes): if route[-1] == current_node and (route + node) not in routes: routes.append(route + node) routes_weights.append(routes_weights[index] + g.get_node( current_node).calculate_distance_to(g.get_node(node))) checking_now.task_done() g.remove_node(current_node) g = graph(4) print(g) print('all', g.all) print('current', g.current) starting_node = 'a' first_layer = g.all[starting_node] for letter in first_layer: routes.append(starting_node) routes_weights.append(0) print('----------------------------') BFS(g, 'a') BFS(g, 'b') BFS(g, 'c') BFS(g, 'd')
for edgs in edges_out: if edgs not in visited: _dfs(edgs, visited, visitedNodes, g) visitedNodes.append(vrtx) def top_sort(g): visited = set() n = len(g.vertices) stack = [] for vrtx in g.vertices: if vrtx not in visited: visitedNodes = [] _dfs(vrtx, visited, visitedNodes, g) for node in visitedNodes: stack.append(node) return stack[::-1] if __name__ == '__main__': g = graphs.graph() g.addedge(30, 40) g.addedge(10, 20) g.addedge(10, 30) g.addedge(20, 40) g.addedge(40, 50) g.addedge(20, 50) g.addedge(10, 50) #print(g.vertices) print(top_sort(g))
for path in extended_path: path_.append(path) return path_ return None e = [ node("a", ["c"]), node("b", ["c", "e"]), node("c", ["a", "b", "d", "e"]), node("d", ["c"]), node("e", ["c", "b"]), node("f", []), ] f = { "a": ["d", "f"], "b": ["c"], "c": ["b", "c", "d", "e"], "d": ["a", "c"], "e": ["c"], "f": ["d"] } node_list = graph(e) n_ = G(f) print("Verticies: {}".format(n_.verticies())) print("Edges: {}".format(n_.generate_edges())) print("Find paths: {}".format(n_.find_paths("a", "b")))
def all_graphs(career: Tag) -> Tuple[str, str, dict]: ''' gets timed played for all heroes ''' top_5 = dict(islice( ((hero.find(bar_name).text, { 'time': hero.find(bar_stats).text, 'percent': float(hero['data-overwatch-progress-percent']), 'id': hero.img['src'].split('/')[-1].split('.')[0]}) for hero in career.find('div', attrs = {'data-category-id': '0x0860000000000021'}).children ), 5)) all_heroes = { hero.find(bar_name).text: {'time': float(hero['data-overwatch-progress-percent'])} for hero in career.find('div', attrs = {'data-category-id': '0x0860000000000021'}).children } ''' gets win percentages for all heroes ''' for hero in career.find('div', attrs = {'data-category-id': '0x08600000000003D1'}).children: name = hero.find(bar_name).text win = hero.find(bar_stats).text if name in top_5: top_5[name]['win'] = win all_heroes[name]['win'] = (int(win.replace('%', '')) / 100) * all_heroes[name]['time'] ''' converts individual hero stats into role stats ''' _all_classes = {} for hero in all_heroes: role = all_heroes[hero] _all_classes.setdefault(role, {'time': 0, 'win': 0}) for n in ('time', 'win'): _all_classes[role][n] += all_heroes[hero][n] ''' converts decimal values to percentages ''' time_list = lambda: (_all_classes[role]['time'] for role in _all_classes) total_time = sum(time_list()) max_time = max(time_list()) time_pld = clock_to_mins(career.find('tr', attrs = {'data-stat-id': '0x0860000000000026'}).contents[1].text) all_classes = { role: { 'time' : mins_to_clock(_all_classes[role]['time'] / total_time * time_pld), 'percent' : _all_classes[role]['time'] / max_time, 'win' : str(int(_all_classes[role]['win'] / _all_classes[role]['time'] * 100)) + '%' } for role in _all_classes } return graph(top_5), graph(all_classes), {hero: top_5[hero]['id'] for hero in top_5}