def generate_data(self, obj): """Generate data to insert into the Permutation table.""" data = { 'id': srz.perm_to_int(obj), 'cycle_decomp': srz.seq_to_int(obj.cycle_decomposition.count) } yield data
def add_data(self): """Add data from a trial to the database.""" # Graph G = self.random_connected_graph() graph_id = srz.graph_to_int(G) if not self.handlers['Graph'].exists(id=graph_id): self.handlers['Graph'].insert(G) # Subset of graph's nodes nodes = sorted(G.nodes) starting_nodes, node_encoding = randobj.random_subsequence(nodes, encoding=True) methods = {'bfs': G.bfs, 'dfs': G.dfs} for mtd, method in methods.iteritems(): # PermGroup group = generate_group(method, starting_nodes) group_repr = srz.encode_objects(group, srz.perm_to_int) group_id = self.handlers['PermGroup'].exists(repr=group_repr) if group_id == None: # Permutation for perm in group: perm_id = srz.perm_to_int(perm) if self.handlers['Permutation'].exists(id=perm_id) == None: self.handlers['Permutation'].insert(perm) # GroupClass group_class = fctn.get_fingerprint(group) group_class_repr = srz.encode_group_class(group_class) group_class_id = self.handlers['GroupClass'].exists(repr=group_class_repr) if group_class_id == None: group_class_id = self.handlers['GroupClass'].insert(group_class)[0][0] # Histogram histogram = {'id': group_class_id, 'fingerprint': group_class} self.handlers['Histogram'].insert(histogram) group_data = {'repr': group_repr, 'cls': group_class_id} group_id = self.handlers['PermGroup'].insert(group_data)[0][0] # GroupElement self.handlers['GroupElement'].insert({'id': group_id, 'elements': group}) # Trial trial_data = { 'graph': graph_id, 'nodes': node_encoding, 'method': mtd, 'grp': group_id } self.handlers['Trial'].insert(trial_data)
def generate_data(self, obj): """Generate data to insert into the GroupElement table.""" for element in obj['elements']: yield {'grp': obj['id'], 'elt': srz.perm_to_int(element)}