Customer Banners (Ads) - SpiceUp. AX and SpotfireX Disclaimer



If you find this site useful and you want to support, buy me a coffee   to keep this site alive and without ads.

FittingModel (SF 6.0+)

# -------------------------------------------------------------------------
# Script to get the model of the logistic curve fitting
# and update a table 'Model Parameters' with it
# -------------------------------------------------------------------------

import math
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Application.Visuals.FittingModels import FittingModelTypeIdentifiers,LogisticRegressionFittingModel

viz=visual.As[VisualContent]()
for fm in viz.FittingModels:
if fm.TypeId==FittingModelTypeIdentifiers.LogisticRegressionFittingModel:
  ds = fm.GetResultsDataSource()
  if Document.Data.Tables.Contains("Model Parameters"):
  #Replace data if table exists    table=Document.Data.Tables["Model Parameters"]
    table.ReplaceData(ds)
  else:
  #Create table if doesn't exists    Document.Data.Tables.Add("Model Parameters", ds)

# call the script yo update the Y calculationfrom System.Collections.Generic import Dictionary
from Spotfire.Dxp.Application.Scripting import ScriptDefinition
import clr

scriptDef = clr.Reference[ScriptDefinition]()
Document.ScriptManager.TryGetScript("UpdateCalcY", scriptDef)
paramDict = {"visual":visual}
params = Dictionary[str, object](paramDict)
Document.ScriptManager.ExecuteScript(scriptDef.ScriptCode, params)


# -----------------------------------------------------------------------------------------------------------------------
# Script to recalculate the Y value corresponding to the X value in property SelectedX
# using the parameters in table 'Model Parameters', created by the other script
# -----------------------------------------------------------------------------------------------------------------------

import math
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Application.Visuals.FittingModels import FittingModelTypeIdentifiers,LogisticRegressionFittingModel
from Spotfire.Dxp.Data import DataValueCursor

viz=visual.As[VisualContent]()
x=Document.Properties['SelectedX']
if Document.Data.Tables.Contains("Model Parameters"):
  table=Document.Data.Tables["Model Parameters"]
  minCol=table.Columns['min']
  minCursor=DataValueCursor.Create[float](minCol)
  maxCol=table.Columns['max']
  maxCursor=DataValueCursor.Create[float](maxCol)
  hillCol=table.Columns['Hill']
  hillCursor=DataValueCursor.Create[float](hillCol)
  lX50Col=table.Columns['LoggedX50']
  lX50Cursor=DataValueCursor.Create[float](lX50Col)
  for row in table.GetRows(minCursor,maxCursor,hillCursor,lX50Cursor):
    y=minCursor.CurrentValue+((maxCursor.CurrentValue-minCursor.CurrentValue)/(1.00+math.pow(10,hillCursor.CurrentValue*(lX50Cursor.CurrentValue-x))))
    Document.Properties['CalcY']=y
    break;

2 comments:

Unknown said...

I have gotten this script to work correctly in one file but have not successfully gotten it to run in another. The script is failing with
"The property named 'SelectedX' could not be found"

I can't recall what other items I may have done in my working file to get these scripts working. Any help would be greatly appreciated!

Jose Leviaguirre said...

William, make sure you have a document property called "SelectedX" in your analysis.