def create_tables(): """Creating Std tables""" db_obj.execute_query(db_connection, 'Show Tables') tables_to_execute = list( OrderedSet(['User', 'Admin', 'ProductCategory', 'Product', 'Cart']) - set([i[0] for i in db_connection])) mapper_ = OrderedDict({ 'User': """Create Table User ( customer_id int NOT NULL, name varchar(255) NOT NULL, email varchar(255), address varchar(255), PRIMARY KEY (customer_id))""", 'Admin': """Create Table Admin ( admin_id int NOT NULL, name varchar(255) NOT NULL, email varchar(255), address varchar(255), PRIMARY KEY (admin_id))""", 'ProductCategory': """Create Table ProductCategory( category_id int NOT NULL, name varchar(255) NOT NULL,description varchar(255),PRIMARY KEY (category_id))""", 'Product': """Create Table Product ( product_id int NOT NULL, name varchar(255) NOT NULL, category_id int not null,description varchar(255),PRIMARY KEY (product_id), foreign key(category_id) references ProductCategory(category_id))""", 'Cart': """ Create Table Cart ( cart_id int not null, customer_id int,address varchar(255), email varchar(255), product_id int not null, discount_amount int not null, total_amount int not null, PRIMARY KEY (cart_id), foreign key(customer_id) references User(customer_id), foreign key(product_id) references Product(product_id))""" }) for query in tables_to_execute: try: db_obj.execute_query(db_connection, mapper_.get(query)) except Error as e: db_obj.db_close() raise e
def firstUniqChar(self, s: str) -> int: from _collections import OrderedDict order_dict = OrderedDict() for char in s: order_dict[char] = order_dict.get(char,0)+1 for key,val in order_dict.items(): if val == 1: return s.index(key) return -1
def build_experience_buffer(grid, Vx_rzns, Vy_rzns, paths, sampling_interval, num_of_paths, num_actions): exp_buffer_all_trajs = [] for k in range(num_of_paths): exp_buffer_kth_traj = [] Vxt = Vx_rzns[k, :, :] Vyt = Vy_rzns[k, :, :] trajectory = paths[0, k] # append starting point to traj coord_traj = [(trajectory[0][0], trajectory[0][1])] s_i, s_j = compute_cell(grid, trajectory[0]) state_traj = [(s_i, s_j)] # make dictionary states mapping to coords. and choose middle coord to append to traj traj_dict = OrderedDict() for j in range(0, len(trajectory)): s_i, s_j = compute_cell(grid, trajectory[j]) s = (s_i, s_j) c = (trajectory[j][0], trajectory[j][1]) if not traj_dict.get(s): traj_dict[s] = [c] else: traj_dict[s].append(c) keys = list(traj_dict.keys()) keys.remove(keys[0]) #remove first and last keys (states). keys.remove(keys[-1]) #They are appended separately for s in keys: state_traj.append(s) l = len(traj_dict[s]) coord_traj.append(traj_dict[s][int(l // 2)]) coord_traj.append((trajectory[-1][0], trajectory[-1][1])) s_i, s_j = compute_cell(grid, trajectory[-1]) state_traj.append((s_i, s_j)) state_traj.reverse() coord_traj.reverse() #build buffer print("check warning: ", k) # print("s1, p1, p2, Vxt, Vyt") for i in range(len(state_traj) - 1): s1 = state_traj[i + 1] s2 = state_traj[i] # t ,m,n=s1 m, n = s1 p1 = coord_traj[i + 1] p2 = coord_traj[i] """COMMENTING THIS STATEMENT BELOW""" # if (s1[1],s1[2])!=(s2[1],s2[2]): #vx=Vxt[t,i,j] vx = Vxt[m, n] vy = Vyt[m, n] # print(s1,p1,p2, vx, vy) a1 = Calculate_action(s1, p1, p2, vx, vy, grid) r1 = grid.move_exact(a1, vx, vy) exp_buffer_kth_traj.append([s1, a1, r1, s2]) #append kth-traj-list to master list exp_buffer_all_trajs.append(exp_buffer_kth_traj) return exp_buffer_all_trajs