Namit Gaur Posted January 10, 2017 Share Posted January 10, 2017 I have requirement wherein a Data Relationships calculation has to be createdfrom a table already existing in the analysis, using ironpython scripting. I have explored the Spotfire Ironpython API, got some functions but don't know how to use them Link to comment Share on other sites More sharing options...
Sean Riley Posted January 10, 2017 Share Posted January 10, 2017 Here is an example script to add/remove data table relations: from Spotfire.Dxp.Data import * ##Define the 2 tables to be used table1=Document.Data.Tables["Table1"] table2=Document.Data.Tables["Table2"] dm=Application.GetService(DataManager) ## (1) Add data table relation ##Id & Name are the names of the columns available in the 2 tables dm.Relations.Add(table1, table2, '[Table1].[id]=[Table2].[id] and [Table1].[Name]=[Table2].[Name]') ## (2) Get All Relations for the specified table, uncomment if required #existingRelations=dm.Relations.FindRelations(table1) ## (3) Delete Relations for the specified tables, uncomment if required #existingRelations=dm.Relations.FindRelations(table1,table2) #for exRel in existingRelations: #dm.Relations.Remove(exRel) Link to comment Share on other sites More sharing options...
Namit Gaur Posted January 11, 2017 Author Share Posted January 11, 2017 Thanks for the response Sean, but what I needed was an ironpython script to creata a data relationships tool which gives linear regression calculation and correlation between two sets of columns. We do it manually by using the option Tools->Data Relationships but I need it to automate it using script. Link to comment Share on other sites More sharing options...
Sean Riley Posted January 11, 2017 Share Posted January 11, 2017 Ah : ) Link to comment Share on other sites More sharing options...
Sean Riley Posted January 11, 2017 Share Posted January 11, 2017 Here is an example of adding a linear regression like via Tools > Data Relationships: In this case we have a table named "cars" with a column "Sold" and a calculated column "[sold]*3" which are used when creating the table "Data Relationships". DataRelationshipsCalculation relationships = app.Document.Calculations.AddNewDataRelationshipsCalculation(); relationships.CalculationSettings.ComparisonMethod = ComparisonMethod.LinearRegression; DataColumn foo = app.Document.Data.Tables["cars"].Columns["Sold"]; DataColumn bar = app.Document.Data.Tables["cars"].Columns["[sold]*3"]; relationships.CalculationSettings.XColumns.Add(foo); relationships.CalculationSettings.YColumns.Add(bar); relationships.Execute(CalculationExecutionPromptMode.Never); API Reference:https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/topic=html/N_Spotfire_Dxp_Application_Calculations_DataRelationships.htm Link to comment Share on other sites More sharing options...
. . 14 Posted July 16, 2019 Share Posted July 16, 2019 Hi Sean, i tried the above script to dynamically run the Anova but throws a lot of errors, would you please be able to post the working script Thank You Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now