Jump to content

Export customized DAT file


Andrea Quinci

Recommended Posts

Hi everyone,

I need to export data from a cross table visualization, but not in CSV format. I need a DAT file with integers in the first two columns and real with 5 decimal digits on the remaining six, without columns names. The reason is that I need to use this file in another software that wants such a file.

I have already done an IronPython code to do this and it works efficiently in Spotfire Professional (where we develop dashboards) but running on the web player I cannot achieve the writing because it is executed on a server machine and then it cannot find the path I specified (a simple C:UsersUSERNAMEDownloads). But I think that, if you can download a CSV file, there MUST be a way to communicate between machine and user folders and to download also another type of customized file.

The code in reported in the snippet.

Can you help me with this

Thanks in advance for the support.

import System

from System.IO import *

from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

 

#get list of filtered rows

dataTable = Document.Data.Tables['aa_eng_pub_gears_data_topographics_t']

 

#Script configuration

delim = "t"

rowDelim = "n"

 

# filter rows

filtered = Document.ActiveFilteringSelectionReference.GetSelection(dataTable).AsIndexSet()

 

import datetime

from Spotfire.Dxp.Data.Formatters import *

from Spotfire.Dxp.Data import *

 

# set custom formatter for column 3-8

formatter = DataType.Real.CreateLocalizedFormatter()

# Set the formatter category to Number

formatter.Category = NumberFormatCategory.Number

# Set "Decimals:" option:

formatter.DecimalDigits = 5 #Any other integer option (0 to 15)

 

# set custom formatter for column 1-2

formatterInt = DataType.Real.CreateLocalizedFormatter()

# Set the formatter category to Number

formatterInt.Category = NumberFormatCategory.Number

# Set "Decimals:" option:

formatterInt.DecimalDigits = 0 #Any other integer option (0 to 15)

 

 

#generate CSV variable

csv = ""

c = False

for r in filtered:

indicator = False

for col in dataTable.Columns:

if col.Name == "flank_ind":

if col.RowValues.GetFormattedValue® != Document.Properties["flankHFM"]:

indicator = True

if col.Name == "tooth_nbr":

if col.RowValues.GetFormattedValue® != Document.Properties["selectedTooth"]:

indicator = True

if col.Name in ("column_id","PF1") and indicator == False:

csv += col.RowValues.GetFormattedValue(r,formatterInt) + delim

if col.Name in ("x_actual_nbr","y_actual_nbr","z_actual_nbr","nx_actual_nbr","ny_actual_nbr","nz_actual_nbr") and indicator == False:

csv += col.RowValues.GetFormattedValue(r,formatter) + delim

if indicator == False:

csv+=rowDelim

if c==False:

c=True

nameFile = dataTable.Columns["part_number_cd"].RowValues.GetFormattedValue(1) + "_" + dataTable.Columns["serial_number_cd"].RowValues.GetFormattedValue(1) +

"_" + Document.Properties["flankHFM"] + "_" + Document.Properties["selectedTooth"].replace(" ","") + "_" +

str(datetime.datetime.now()).replace(" ","").replace(":","").replace("-","")[0:14] + ".dat"

print(nameFile)

 

#show results

print csv

 

print("C:\Users\"+Document.Properties["SSO"]+"\Downloads\" + nameFile)

saveFilename = "C:\Users\"+Document.Properties["SSO"]+"\Downloads\" + nameFile

 

# open the file and write the string csv with all the table

stream = StreamWriter(saveFilename, True)

 

stream.Write(csv)

 

stream.Dispose()

 

stream.Close()

 

# get notification to user

from Spotfire.Dxp.Framework.ApplicationModel import NotificationService

 

# Notification service

notify = Application.GetService[NotificationService]()

 

notify.AddInformationNotification("File saved successfully","Your file has been exported correctly. Congrats! You are a dashboard pro-user ;)","The file has been saved successfully in "C:\Users\"+

Document.Properties["SSO"]+"\Downloads\" + nameFile + "".");

Andrea

Link to comment
Share on other sites

Hi Andrea,

If you activate the saving of data exports on a network drive (you have to change the web payer configuration by enabling the AllFilePath setting), you could use your python script for the export. If you use the C drive, Spotfire indeeds try to save it locally, so if you can activate the network share, you should be able to get it working.

You can find the way to edit the configuration files here (the example is for Automation services, you need to do this for the Webplayer services):https://docs.tibco.com/pub/spotfire_server/10.10.4/doc/html/TIB_sfire_se...

Kind regards,

David

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...