in_table_name = 'households', id_name='household_id', dataset_name='household') households.get_attribute_names() households.get_id_attribute() households.size() households.get_attribute("income") households.get_attribute_names() households.load_dataset() households.get_attribute_names() #households.plot_histogram("income", bins = 10) #households.r_histogram("income") #households.r_scatter("persons", "income") households.correlation_coefficient("persons", "income") households.correlation_matrix(["persons", "income"]) households.summary() households.add_primary_attribute(data=[4,6,9,2,4,8,2,1,3,2], name="location") households.get_attribute_names() households.modify_attribute(name="location", data=[0,0], index=[0,1]) households.get_attribute("location") households.get_data_element_by_id(5).location #households.write_dataset(out_storage=storage, out_table_name="households_output") households.get_dataset_name() # Working with models from opus_core.choice_model import ChoiceModel choicemodel = ChoiceModel(choice_set=[1,2,3], utilities = "opus_core.linear_utilities",
def viewDatasetAction(self): #print "viewDatasetAction" model = self.model table_name = str(model.fileName(self.currentIndex)) table_name_full = str(model.filePath(self.currentIndex)) parentIndex = model.parent(self.currentIndex) parent_name = str(model.fileName(parentIndex)) parent_name_full = str(model.filePath(parentIndex)) storage = StorageFactory().get_storage( 'flt_storage', storage_location=parent_name_full) columns = storage.get_column_names(table_name) # temporarily use the table name for the dataset name # dataset_name = DatasetFactory().dataset_name_for_table(table_name) # Aaron - please check this way of getting the XMLConfiguration -- is this the best way? # general = self.mainwindow.toolboxBase.opus_core_xml_configuration.get_section('general') # # problem: this gets the package order for the current project, but the viewer shows all the data # package_order = general['dataset_pool_configuration'].package_order # PREVIOUS HACK: # package_order = ['seattle_parcel','urbansim_parcel', 'eugene', 'urbansim', 'opus_core'] # temporary code: just use a generic dataset for now data = Dataset(in_storage=storage, dataset_name=table_name, in_table_name=table_name, id_name=[]) # code to get a more specialized dataset if possible (doesn't work with table names not ending in 's' # unless they are in the exceptions list in DatasetFactory) # data = DatasetFactory().search_for_dataset_with_hidden_id(dataset_name, package_order, # arguments={'in_storage': storage, 'in_table_name': table_name}) # Need to add a new tab to the main tabs for display of the data container = QWidget() widgetLayout = QVBoxLayout(container) summaryGroupBox = QGroupBox(container) summaryGroupBox.setTitle( QString("Year: %s Run name: %s" % (parent_name, table_name_full.split('/')[-3]))) summaryGroupBox.setFlat(True) summaryGroupBoxLayout = QVBoxLayout(summaryGroupBox) # Grab the summary data buffer = StringIO() data.summary(output=buffer, unload_after_each_attribute=True) strng = buffer.getvalue() buffer.close() textBrowser = QTextBrowser() # textBrowser.insertPlainText(strng) textBrowser.insertHtml(self.parse_dataset_summary(strng)) summaryGroupBoxLayout.addWidget(textBrowser) widgetLayout.addWidget(summaryGroupBox) tableGroupBox = QGroupBox(container) tableGroupBox.setTitle(QString("Table View")) tableGroupBox.setFlat(True) tableGroupBoxLayout = QVBoxLayout(tableGroupBox) tv = QTableView() header = columns tabledata_tmp = [] for column in columns: tabledata_tmp.append(data.get_attribute(column)) # Transpose the lists tabledata = map(None, *tabledata_tmp) # If the table data is not empty then we display it if tabledata: #tv.resizeColumnsToContents() tm = TableModel(tabledata, header, container) tv.setModel(tm) tv.setSortingEnabled(True) tableGroupBoxLayout.addWidget(tv) widgetLayout.addWidget(tableGroupBox) container.tabIcon = IconLibrary.icon('inspect') container.tabLabel = QString(table_name) self.manager._attach_tab(container)
def viewDatasetAction(self): #print "viewDatasetAction" model = self.model table_name = str(model.fileName(self.currentIndex)) table_name_full = str(model.filePath(self.currentIndex)) parentIndex = model.parent(self.currentIndex) parent_name = str(model.fileName(parentIndex)) parent_name_full = str(model.filePath(parentIndex)) storage = StorageFactory().get_storage('flt_storage', storage_location=parent_name_full) columns = storage.get_column_names(table_name) # temporarily use the table name for the dataset name # dataset_name = DatasetFactory().dataset_name_for_table(table_name) # Aaron - please check this way of getting the XMLConfiguration -- is this the best way? # general = self.mainwindow.toolboxBase.opus_core_xml_configuration.get_section('general') # # problem: this gets the package order for the current project, but the viewer shows all the data # package_order = general['dataset_pool_configuration'].package_order # PREVIOUS HACK: # package_order = ['seattle_parcel','urbansim_parcel', 'eugene', 'urbansim', 'opus_core'] # temporary code: just use a generic dataset for now data = Dataset(in_storage=storage, dataset_name=table_name, in_table_name=table_name, id_name=[]) # code to get a more specialized dataset if possible (doesn't work with table names not ending in 's' # unless they are in the exceptions list in DatasetFactory) # data = DatasetFactory().search_for_dataset_with_hidden_id(dataset_name, package_order, # arguments={'in_storage': storage, 'in_table_name': table_name}) # Need to add a new tab to the main tabs for display of the data container = QWidget() widgetLayout = QVBoxLayout(container) summaryGroupBox = QGroupBox(container) summaryGroupBox.setTitle(QString("Year: %s Run name: %s" % (parent_name,table_name_full.split('/')[-3]))) summaryGroupBox.setFlat(True) summaryGroupBoxLayout = QVBoxLayout(summaryGroupBox) # Grab the summary data buffer = StringIO() data.summary(output=buffer) strng = buffer.getvalue() buffer.close() textBrowser = QTextBrowser() # textBrowser.insertPlainText(strng) textBrowser.insertHtml(self.parse_dataset_summary(strng)) summaryGroupBoxLayout.addWidget(textBrowser) widgetLayout.addWidget(summaryGroupBox) tableGroupBox = QGroupBox(container) tableGroupBox.setTitle(QString("Table View")) tableGroupBox.setFlat(True) tableGroupBoxLayout = QVBoxLayout(tableGroupBox) tv = QTableView() header = columns tabledata_tmp = [] for column in columns: tabledata_tmp.append(data.get_attribute(column)) # Transpose the lists tabledata = map(None,*tabledata_tmp) # If the table data is not empty then we display it if tabledata: #tv.resizeColumnsToContents() tm = TableModel(tabledata, header, container) tv.setModel(tm) tv.setSortingEnabled(True) tableGroupBoxLayout.addWidget(tv) widgetLayout.addWidget(tableGroupBox) container.tabIcon = IconLibrary.icon('inspect') container.tabLabel = QString(table_name) self.manager._attach_tab(container)