Hi,
I am trying to use a Python script to run many different models, feed each models result to an Analysis node, then consolidate all the Analysis results into a single table
I am struggling to directly access the results from the Analysis node via my Python script.
I am also struggling to write new values back into Modeler (e.g. through updating a DataModel?) so that arbitrary data can be displayed in a table.
Right now, my solution is to have the Analysis node write the output to a file, then I programmatically open the file with Python, process the data to tabular format, write to another file, then use a separate Table node to read in the new file.
This works, but SPSS Modeler doesn't seem to have permission to delete the files created by this process - so leaves a messy directory, thus face the "Are you sure you want to overwrite" dialog.
Thanks for any assistance.
Answer by JulianClinton (156) | Aug 27, 2015 at 03:35 AM
Hi
I may not have understood exactly what you want to end up with but you could export the analysis output explicitly as text. For a single analysis node, this would look like:
from modeler.api import FileFormat
stream = modeler.script.stream()
session = modeler.script.session()
tasks = session.getTaskRunner()
# Assumes there's only one analysis node in the stream
analysisnode = stream.findByType("analysis", None)
results = []
analysisnode.run(results)
analysisoutput = results[0]
tasks.exportDocumentToFile(analysisoutput, "C:/temp/output/analysis1.txt", FileFormat.PLAIN_TEXT)
You could re-run the analysis node multiple times writing to multiple files and then use standard Python to append the different files together (the "exportDocumentToFile()" function always overwrites the content which is why you will need to handle the appending of the files as a separate step).
I hope this helps.
Julian
Hi,
When I try this from Spyder (Interactive Python development environment ), i have this error: ImportError: No module named modeler.api
how can i install this module please ?
Thanks for any assistance. Yacine