def fetchDataImpl(self): infos = self.m_database.availbleServicesInfo() if infos is None: self.m_data = [] else: self.m_data = list( TableInfo(info[0], False, *info[1:]) for info in infos)
def fetchDataImpl(self): infos = self.m_database.contactAddressInfo(self.m_contactId) if infos is None: self.m_data = [] else: self.m_data = list( TableInfo(info[0], False, *info[1:]) for info in infos)
def addKeyColumn(self): key = self.ui.schemaColumnsColumnTable.model().keyColumn() if key is not None: res = QMessageBox.question( None, 'Key Exists', "Table already have Primary key '%s'. \n" "Do you want to drop it before adding new one?" % key.value(0).modifiedValue, QMessageBox.Yes, QMessageBox.No) if res == QMessageBox.Yes: self.ui.schemaColumnsColumnTable.model().dropPrimaryKey() idx = self.newRowIndex() newCol = self.m_database.uidColumn() newCol = TableInfo(0, True, *newCol[1:]) newCol.setAdded() self.ui.schemaColumnsColumnTable.model().insertRow(idx, newCol) self.scrolltoIndex(idx)
def save(self): try: self.modelAboutToBeReset.emit() for row in range(self.rowCount()): if self.rowIsModified(row): self.m_database.saveTable( tableName=self.m_data[row].value(0), group=self.m_data[row].value(1), title=self.m_data[row].value(2), description=self.m_data[row].value(3), isSpatial=self.m_data[row].value(4), spatialType=self.m_data[row].value(5), schema=self.m_data[row].value(6), connId=self.m_connId) self.m_data[row].commitChanges() local, tableName, group, title, description, isSpatial, spatialType, schema = \ self.m_database.tableInfo(schema=self.m_data[row].value(6).originalValue, connId=self.m_connId, tableName=self.m_data[row].value(0).originalValue) self.m_data[row] = TableInfo( 0, local, tableName, group, title, description, "Yes" if isSpatial else 'No', spatialType if isSpatial else "", schema) self.m_modified = False self.modelReset.emit() self.modified.emit(self.m_modified) except Exception as e: print(e)
def __init__(self, database, connId): super(ColumnsModel2, self).__init__() self.m_data = [] columns = database.commonColumnsInfo(connId) for col in columns: self.m_data.append(TableInfo(col[0], False, *col[1:])) self.m_data[-1].freez(True)
def fetchData(self): self.modelAboutToBeReset.emit() infos = self.m_database.commonColumnsInfo(self.m_connId) self.m_data = list( TableInfo(info[0], False, *info[1:]) for info in infos) self.m_modified = False self.modelReset.emit() self.modified.emit(self.m_modified)
def __init__(self, data, database, connId): super(OtherColumnseModel, self).__init__() self.m_data = [] columns = database.commonColumnsInfo(connId) for col in columns: if not col[0] in [d.id() for d in data]: self.m_data.append(TableInfo(col[0], False, *col[1:])) self.m_data[-1].freez(True)
def addKeyColumn(self): newCol = self.m_database.uidColumn() if newCol is None: if len(self.m_data) == 0: pass elif not self.m_data[0].frozen() or self.m_data[0].id() != 0: pass else: # UID column exists del self.m_data[0] else: if len(self.m_data) == 0: self.m_data.append(TableInfo(newCol[0], False, *newCol[1:])) self.m_data[0].freez(True) elif not self.m_data[0].frozen() or self.m_data[0].id() != 0: self.m_data.insert(0, TableInfo(newCol[0], False, *newCol[1:])) self.m_data[0].freez(True) else: # UID column exists self.m_data[0] = TableInfo(newCol[0], False, *newCol[1:]) self.m_data[0].freez(True)
def insertInfo(self, row, tableName, schema): self.rowsAboutToBeInserted.emit(QModelIndex(), row, row) local, tableName, group, title, description, isSpatial, spatialType, schema = self.m_database.tableInfo( schema, self.m_connId, tableName) info = TableInfo(0, local, tableName, group, title, description, "Yes" if isSpatial else 'No', spatialType if isSpatial else "", schema) self.m_data.insert(row, info) self.rowsInserted.emit(QModelIndex(), row, row)
def run_simulation(configId, goalInd, open_b, part_b, planner_type, debug = False): num_steps = 0 successful_grasp_steps = 0 has_experiment_finished = False tableinfo = TableInfo(configId, goalInd) tableinfo.open_b = open_b tableinfo.part_b = part_b while(not has_experiment_finished): visible_objects = tableinfo.get_visible_objects() belief = tableinfo.get_current_belief(visible_objects) if debug: print "EXECUTE PLANNING Input: ", belief, visible_objects, planner_type latticeInd = execute_planning_step(belief, visible_objects, planner_type) if debug: print "EXECUTE PLANNING Output: ", latticeInd if latticeInd == 0: has_experiment_finished = True # no longer going to search for the goal elif latticeInd < 0: has_experiment_finished = True if abs(latticeInd) not in tableinfo.latticeids: # goal already removed (no more uncertainities on grasps) successful_grasp_steps += 1 # return goal is a success grasp always else: index = tableinfo.latticeids.index(-latticeInd) prob = tableinfo.f_grasps[index] rand = random.random() if rand < prob: # Chance of successful removal of object = Full Graspability probability tableinfo.removeObject(index) successful_grasp_steps += 1 has_experiment_finished = True # grasped & returned the goal object successfully else: index = tableinfo.latticeids.index(latticeInd) prob = tableinfo.f_grasps[index] rand = random.random() if rand < prob: # Chance of successful removal of object = Full Graspability probability tableinfo.removeObject(index) successful_grasp_steps += 1 num_steps += 1 is_success = (latticeInd!=0) # the above while loop can quit only when latticeInd<=0, and when its != 0, its a success if debug: print "Result: ", num_steps, is_success, successful_grasp_steps return num_steps, is_success, successful_grasp_steps
def addRow(self, idx): row = TableInfo(0, False) row.setAdded() row.resize(len(self.columns)) row.value(10).modifiedValue = "No" row.value(10).originalValue = "No" row.value(11).modifiedValue = "Yes" row.value(11).originalValue = "Yes" self.rowsAboutToBeInserted.emit(QModelIndex(), idx, idx) self.m_data.insert(idx, row) self.rowsInserted.emit(QModelIndex(), idx, idx) self.m_modified = True self.modified.emit(self.m_modified) if self.m_commitAfterChange: self.commitChanges()
def setTableName(self, schema, tableName): self.modelAboutToBeReset.emit() self.m_tableName = tableName self.m_schema = schema if tableName == "": self.m_data = [] else: infos = self.m_database.columnsInfo(schema, tableName, self.m_connId) self.m_data = list(TableInfo(0, False, *info) for info in infos) self.m_modified = False self.modelReset.emit() self.modified.emit(self.m_modified)
def populateCommonColumns(self): columns = self.m_database.commonColumnsInfo(self.m_connId) tableIdx = 0 while tableIdx < len(self.m_data): if not self.m_data[tableIdx].frozen( ) or self.m_data[tableIdx].id() <= 0: # Not a common column tableIdx += 1 continue # Find id in new columns id = not self.m_data[tableIdx].id() newCol = [col for col in columns if col[0] == id] if len(newCol) == 0: # Common column deleted del self.m_data[tableIdx] continue newCol = newCol[0] self.m_data[tableIdx] = TableInfo(newCol[0], False, *newCol[1:]) tableIdx += 1
def addGeometryColumn(self, add, type): if add: geomColumnIdx = 0 if self.keyColumneExists(): geomColumnIdx = 1 if len(self.m_data ) > geomColumnIdx and self.m_data[geomColumnIdx].frozen( ) and self.m_data[geomColumnIdx].id() == -1: self.rowsAboutToBeRemoved.emit(QModelIndex(), geomColumnIdx, geomColumnIdx) del self.m_data[geomColumnIdx] self.rowsRemoved.emit(QModelIndex(), geomColumnIdx, geomColumnIdx) newCol = self.m_database.geomColumn(type, self.m_connId) if newCol is None: return self.rowsAboutToBeInserted.emit(QModelIndex(), geomColumnIdx, geomColumnIdx) self.m_data.insert(geomColumnIdx, TableInfo(newCol[0], False, *newCol[1:])) self.m_data[geomColumnIdx].freez(True) self.rowsInserted.emit(QModelIndex(), geomColumnIdx, geomColumnIdx) else: geomColumnIdx = 0 if self.keyColumneExists(): geomColumnIdx = 1 if len(self.m_data) > geomColumnIdx and self.m_data[geomColumnIdx].frozen() and \ self.m_data[geomColumnIdx].id() == -1: self.rowsAboutToBeRemoved.emit(QModelIndex(), geomColumnIdx, geomColumnIdx) del self.m_data[geomColumnIdx] self.rowsRemoved.emit(QModelIndex(), geomColumnIdx, geomColumnIdx)
def analyzeTables(self): tableNames = self.getTables() # 解析表,封装表的信息 tableInfos = [] for tableName in tableNames: # tmpTable = tmpTable[0] tableDescs = self.descTable(tableName) tableInfo = TableInfo() tableInfo.name = str(tableName[0]) # appendAttr(tableInfo, "name", str(tmpTable[0])) # 表中所有字段 fullColumns = parseColumns(tableDescs) tableInfo.fullColumns = fullColumns # 表中非主键的字段(从所有字段中删掉主键字段) tableInfo.otherColumns = parseOtherColumns(fullColumns.copy()) # 表中主键字段(从所有字段获取主键字段) tableInfo.pkColumn = parsePKColumns(fullColumns.copy()) # 获取所有外键引用列表 b = self.getAllForignKey(self.projectConfig.get("MysqlDb"), tableName[0]) tableInfo.foreignInfos = parseForignInfo(b) # 表结构封装 tableInfos.append(tableInfo) # 反射给Tables所有属性添加xxxxCamelCase的属性,,如name,添加了nameCamelCase tableInfos = appendsNameCaseAttr(tableInfos) # 最后表信息齐全了, 把具有外键引用的表,两个表的所有字段合并到一起。 tableInfos = parseJoinTables(tableInfos) return tableInfos