def get_BhaSelectedwells(bhaTable): # Return: list of bha's selected # Last updated: 6/30/18 # Created by: Tyler Hunt # # 1.0 - Create list to hold bha marked pn # 2.0 - Create Cursor references to the PN and Tag in the wells tables # 3.0 - Iterate through table column rows to retrieve the values # 1.0 - Create list to hold bha marked pn bha_selectedPnList = [] # 2.0 - Create Cursor references to the PN and Tag in the wells tables cursor_BhaPN = DataValueCursor.CreateFormatted( bhaTable.Columns['propertynumber']) cursor_BhaTags = DataValueCursor.CreateFormatted( bhaTable.Columns['Selected']) # 3.0 - Iterate through table column rows to retrieve the values for row in bhaTable.GetRows(cursor_BhaPN, cursor_BhaTags): pn = cursor_BhaPN.CurrentValue tag = cursor_BhaTags.CurrentValue if pn <> str.Empty and tag == 'Selected': bha_selectedPnList.append(str(pn)) # print(bha_selectedPnList) return bha_selectedPnList
def get_column_as_list(doc, table_name, col_name): """Fetches a specific column in a specific data table args: doc (Spotfire document instance): document to read from table_name (str): name of table to read from col_name (str): name of column to read """ from Spotfire.Dxp.Data import DataValueCursor #, List table = get_table(doc, table_name) # place generic data cursor on a specific column cursor = DataValueCursor.CreateFormatted(table.Columns[col_name]) # list object to store retrieved values values = [] # iterate through table column rows to retrieve the values for row in table.GetRows(cursor): #rowIndex = row.Index ##un-comment if you want to fetch the row index # into some defined condition value = cursor.CurrentValue if value <> str.Empty: values.append(value) return values
def delete_all_rows(doc, table_name='Active'): """Deletes all rows in a table args: doc (Spotfire document instance): document to work with table_name (str): name of table to delete from """ from Spotfire.Dxp.Data import IndexSet from Spotfire.Dxp.Data import DataValueCursor table = get_table(doc, table_name) rowfilter = findrowfilter(table) cursor =DataValueCursor.CreateFormatted(table.Columns[0]) for row in table.GetRows(cursor): rowfilter.AddIndex(row.Index) rowfilter = rowfilter LOGGER.debug('Rows in table' + str(len(str(rowfilter)))) _delete_rows_(table, rowfilter)
def del_based_on_column_value(doc, column_name, remove_list, table_name='Active'): """Removes rows in datatable based on a list args: doc (Spotfire document instance): document to work with table_name (str): name of table to delete from column_name (str): name of column with criteria in remove_list (list): values of column that triggers delete """ from Spotfire.Dxp.Data import DataValueCursor from System import Convert table = get_table(doc, table_name) cursor = [] cursor = DataValueCursor.CreateFormatted(table.Columns[column_name]) rowfilter = findrowfilter(table) for row in table.GetRows(cursor): if Convert.ToString(cursor.CurrentValue) in remove_list: rowfilter.AddIndex(row.Index) printstr = '{} from column {}'.format(join_list(remove_list), column_name) _delete_rows_(table, rowfilter, printstr)
from Spotfire.Dxp.Data import DataValueCursor myLatCursor = DataValueCursor.CreateFormatted( Document.Data.Tables["mydatatable"].Columns["latitude"]) myLongCursor = DataValueCursor.CreateFormatted( Document.Data.Tables["mydatatable"].Columns["longitude"]) markedRows = Document.Data.Markings["Marking"].GetSelection( Document.Data.Tables["mydatatable"]).AsIndexSet() for row in Document.Data.Tables["mydatatable"].GetRows(markedRows, myLatCursor): Document.Properties['refLat'] = myLatCursor.CurrentValue for row in Document.Data.Tables["mydatatable"].GetRows(markedRows, myLongCursor): Document.Properties['refLong'] = myLongCursor.CurrentValue
#Laurent Cesaro #This script permit to recover a row in a datatable and display it in a label (Document.Properties) #Inport library from Spotfire.Dxp.Data import DataValueCursor #Create cursor on table myStatusCursor = DataValueCursor.CreateFormatted( Document.Data.Tables["Table_Name"].Columns["Column_Name"]) #Select marked row markedRows = Document.Data.Markings["Marking"].GetSelection( Document.Data.Tables["Table_Name"]).AsIndexSet() #Add in your Document.Properties the table value for row in Document.Data.Tables["Table_Name"].GetRows(markedRows, myStatusCursor): Document.Properties["Porprety_Name"] = myStatusCursor.CurrentValue
from Spotfire.Dxp.Data import IndexSet, RowSelection from Spotfire.Dxp.Data import DataValueCursor tableName = "BCO_Information_Link" SourceValue = 'market' TargetValue = 'region' SourceProper = SourceValue[0:1].upper() + SourceValue[1:].lower() SourceColumn = SourceValue.upper() TargetProper = TargetValue[0:1].upper() + TargetValue[1:].lower() TargetColumn = TargetValue.upper() #Building the IndexSet to find the parent division of the market if Document.Properties[SourceProper] != None: Sm = "[" + SourceColumn + "] = '" + Document.Properties[SourceProper] + "'" #Initializing variables rowcount = 0 dT = Document.Data.Tables[tableName] cursorD = DataValueCursor.CreateFormatted(dT.Columns[TargetColumn]) mrows = dT.Select(Sm) #Find the division from the first row for row in Document.ActiveDataTableReference.GetRows(mrows.AsIndexSet(), cursorD): if cursorD.CurrentValue != '(Empty)': Document.Properties[TargetProper] = cursorD.CurrentValue break
# Initialize variables / Properties Document.Properties["newusage"] = "" Document.Properties["existingusage"] = "" sum_new = 0.00 sum_existing = 0.00 sum_new_used = 0.00 sum_ex_used = 0.00 new_usage = 0.00 ex_usage = 0.00 dT = Document.Data.Tables["NEEDS_NAVIGATOR"] dcolumn = dT.Columns["TO_DATE"] cursorn = DataValueCursor.CreateFormatted(dT.Columns["NEW_CUSTOMER"]); cursore = DataValueCursor.CreateFormatted(dT.Columns["EXISTING_CUSTOMER"]); cursornu = DataValueCursor.CreateFormatted(dT.Columns["NN_USED_NEW_CUSTOMER"]); cursoreu = DataValueCursor.CreateFormatted(dT.Columns ["NN_USED_EXISTING_CUSTOMER"]); #Find max date (mx) and display date (mxd) mxd = dcolumn.RowValues.GetMaxValue().ValidValue # If the latest Data is not loaded then flip back to the max available date if date(mxd.Year,mxd.Month,mxd.Day) < datetime.date(to_date) : mx = date(mxd.Year,mxd.Month,mxd.Day) else: mx = to_date.date() wf = mx+ timedelta(days=-7)
def tag_bhaSelectedItems(columnName, tableName, bha_SelectedWells): # Return: list of bha's selected # Last updated: 6/30/18 # Created by: Tyler Hunt # # 1.0 - Create cursor to the bha selected marker # 2.0 - Create references to the bha table row count, rows to include and rows to mark # 3.0 - Loop thru the selected wells and add bhaSelected tag to wellsTable # 3.1 - Loop through the selcted well bha list # 3.2 - Loop through the wellsTable and mark the bha selected pn in wellsTable # 4.0 - Reference to the Tag Column # 5.0 - Get the marked rows # 5.1 - Tag the filtered data set with the # 5.2 - Print confirmation message(2) # 1.0 - Create cursor to the bha selected marker cursor_WellsPN = DataValueCursor.CreateFormatted( wellsTable.Columns['alt_well_pn']) # 2.0 - Create references to the bha table row count, rows to include and rows to mark rowCount = wellsTable.RowCount rowsToInclude = IndexSet(rowCount, True) rowsToMark = IndexSet(rowCount, False) # 3.0 - Loop thru the selected wells and add bhaSelected tag to wellsTable if not bha_SelectedWells: pass else: # 3.1 - Loop through the selcted well bha list for bhaPN in bha_SelectedWells: # 3.2 - Loop through the wellsTable and mark the bha selected pn in wellsTable for row in wellsTable.GetRows(cursor_WellsPN): rowIndex = row.Index wellsPN = cursor_WellsPN.CurrentValue # 3.3 - Mark well in wells table # TODO: Might need to check the Selcted status???? if wellsPN == bhaPN: rowsToMark.AddIndex(rowIndex) Document.ActiveMarkingSelectionReference.SetSelection( RowSelection(rowsToMark), wellsTable) # 4.0 - Reference to the Tag Column tagsCol = tableName.Columns[columnName].As[TagsColumn]() # Tag nname tagName = 'Selected' # Time updated timeUpdated = datetime.datetime.now().strftime("%m-%d-%Y %H:%M:%S") # 5.0 - Get the marked rows filteringRowSelection = Document.ActiveMarkingSelectionReference.GetSelection( tableName) filteredSet = IndexSet(filteringRowSelection.AsIndexSet()) # 5.0 - Check if index set is empty if filteredSet.Count != 0: # 5.1 - Tag the filtered data set with the tagsCol.Tag(tagName, RowSelection(filteredSet)) # 5.2 - Print confirmation message print('Bha Tag(s) have been created successfully @ ' + timeUpdated) else: # 5.2 - Print confirmation message print('No Bha tag(s) have been created @ ' + timeUpdated)
dataTable).AsIndexSet() vc = vis.As[VisualContent]() dataTable = vc.Data.DataTableReference for filter in Document.FilteringSchemes[ Document.ActiveFilteringSelectionReference]: filteredRows = filter.FilteredRows marking = vc.Data.MarkingReference marking.SetSelection(RowSelection(rows), dataTable) # Create a cursor for the table column to get the values from. # Add a reference to the data table in the script. dataTable = Document.Data.Tables["AllData"] cursor = DataValueCursor.CreateFormatted(dataTable.Columns["LookUpID"]) # Retrieve the marking selection markings = Document.ActiveMarkingSelectionReference.GetSelection(dataTable) # Create a List object to store the retrieved data marking selection markedata = List[str]() # Iterate through the data table rows to retrieve the marked rows for row in dataTable.GetRows(markings.AsIndexSet(), cursor): #rowIndex = row.Index ##un-comment if you want to fetch the row index into some defined condition value = cursor.CurrentValue if value <> str.Empty and value <> "(Empty)": markedata.Add(value) # Get only unique values