Hi Wim,
the 5 points that you brought up here could be accomplished with TM1py through very little custom code.
This is how I would approach it.
# 1 Print out summary of a cube view
Code: Select all
from TM1py import TM1Service
with TM1Service(address='10.77.19.60', port=12354, user='admin', password='apple', ssl=True) as tm1:
# get the view definition from TM1
view = tm1.cubes.views.get_native_view(
cube_name="Weather Data",
view_name="Default",
private=False
)
# pretty-print the view definition
print("### Titles (Dimension | Subset | Selection)")
for title in view._titles:
print(title.dimension_name, "|", title.subset.name, "|", title.selected)
for axis_label, axis in zip(["Rows", "Columns"], [view._rows, view._columns]):
print("### " + axis_label + " (Dimension | Subset | Elements or Expression)")
for axis_selection in axis:
print(axis_selection.dimension_name, "|", axis_selection.subset.name, "|",
axis_selection.subset.expression or axis_selection.subset.elements)
# 2 From the view definition itself it can not be derived which rows, columns are zero suppressed. In order to get the zero suppressed content of a view you need to execute it. TM1py has different functions to execute views or mdx. Here is one that gives you the coordinates and cells.
Code: Select all
from TM1py import TM1Service
with TM1Service(address='10.77.19.60', port=12354, user='admin', password='apple', ssl=True) as tm1:
cube_name = "Bike Shares"
view_name = "2017 Counts by Month"
# execute a view that is zero suppressed
data = tm1.cubes.cells.execute_view(
cube_name=cube_name,
view_name=view_name,
private=False
)
# print out all coordinates / intersections that were returned
for coordinate, cell in data.items():
print(coordinate)
You can also execute a view and get the data as a (pandas) pivot table
Code: Select all
from TM1py import TM1Service
with TM1Service(address='10.77.19.60', port=12354, user='admin', password='apple', ssl=True) as tm1:
cube_name = "Bike Shares"
view_name = "2017 Counts by Month"
# execute a view that is zero suppressed as pivot table
data = tm1.cubes.cells.execute_view_dataframe_pivot(
cube_name=cube_name,
view_name=view_name,
private=False
)
print(data)
# 3 Not sure if I understand your idea correctly, but you could inject an AsciiOutput statement with all variables at the bottom of the metadata tab like this:
Code: Select all
from TM1py import TM1Service
with TM1Service(address='10.77.19.60', port=12354, user='admin', password='apple', ssl=True) as tm1:
# get process from TM1
process = tm1.processes.get("_temp4")
# extract name of process variables
variables_names = [variable["Name"] for variable in process.variables]
# new line of TI to be added to the process
new_line = "\r\nASCIIOutput('out.txt', " + ",".join(v for v in variables_names) + " );\r\n"
# adjust process: add new line to the metadata procedure
process.metadata_procedure += new_line
# send process back to TM1
tm1.processes.update(process)
# 4 You can read out config parameters like this
Code: Select all
from TM1py import TM1Service
with TM1Service(address='10.77.19.60', port=12354, user='admin', password='apple', ssl=True) as tm1:
config = tm1.server.get_active_configuration()
logging_directory = config["Administration"]["DebugLog"]["LoggingDirectory"]
print(logging_directory)
(when you are using TM1 11) you can also live update the TM1 config with TM1py, like this:
Code: Select all
from TM1py import TM1Service
with TM1Service(address='10.77.19.60', port=12354, user='admin', password='apple', ssl=True) as tm1:
config = {
"Performance": {
"MTQ": {
"MTFeeders": False
}
}
}
# effectively update the .cfg file (and triggers TM1 to re-read the file)
tm1.server.update_static_configuration(config)
# ask TM1 Server about the currently applied config parameters
config = tm1.server.get_active_configuration()
print(config["Performance"]["MTQ"]["MTFeeders"])
# 5 You can query the dimension names of a cube like this:
Code: Select all
from TM1py import TM1Service
with TM1Service(address='10.77.19.60', port=12354, user='admin', password='apple', ssl=True) as tm1:
dimension_names = tm1.cubes.get_dimension_names(cube_name="FX Rates")
print(dimension_names)
Using TM1py generally saves you from reinventing the wheel and provides you a solid and tested layer underneath your custom code.
Only downside of using TM1py really is that you need to use python, which IMHO is generally a good choice, but may not be suitable for all cases.
Cheers,
Marius