Python for test-data
I became aware of Python in the early 2000s when I started automating tasks. Some of our processes utilized python scripts. I never figured it out very well, and we decided to do away with Python because nobody on our team was familiar with it.
Along the way, I heard a lot about Python. My interest was renewed when InterSystems offered bonus points for using Python in contests.
The things I like the most about Python so far is how easy it is to find the mean of the ages of all Titanic passengers. For my test-data app I wanted to find the largest value in the ‘Qty’ column in a CSV file.
The solution was as simple as this:
import numpy as np import pandas as pd def source(): return "ORG" def target(): return "GKH" def maxqty(filename="QuantityOnHandSync.csv"): # Read data qohs = pd.read_csv(filename,",") # Set Qty to a NumPy array qty = qohs['Qty'] # Use numpy to find the maximum qty max_qty = np.nanmax(qty) return str(max_qty)
With Embedded Python, IRIS developers who are familiar with ObjectScript and Python developers have equal access to memory and data. This means both developer groups can use the language of their choice to take advantage of IRIS powerful engine.
With Embedded Python, I can create a class with classmethods and it looks like any ObjectScript class. Inside any classmethod I can use ObjectScript syntax for ObjectScript and Python syntax for Python.
This is a line with familiar ObjectScript code:
Set file = $System.Util.ManagerDirectory()_"data/QuantityOnHandSync.csv"
The lines before and after it both use ObjectScript Set commands, but they utilize Python. The first line imports the Python code
Set td = ##class(%SYS.Python).Import("test-data")
The second line executes the Python code.
Set maxq = td.maxqty(file)
Here is an example with familiar ObjectScript commands Set and Write, but what is written is Python syntax
Set dt = ##class(%SYS.Python).Import("datetime") write dt.date.today().isoformat()
Embedded Python can be used for Interoperability anywhere ObjectScript code can be used.
Here is a BPL example of calling embedded Python in a Business Process:
<assign name="tQty" property="tQty" value="##class(dc.python.test).MaxQuantity()" action="set" xpos='335' ypos='700' >
I used a DTL and here I used ObjectScript code to get a sequence of Social Security Numbers. Of course we can use Embedded Python just as easily as ObjectScript:
<assign value='##class(dc.iris.ssn).GetNextSSN()' property='target.SSN' action='set' />
I very much want to learn more about using Python. I believe it can create nice graphs and dashboards. I want to explore those options in the future.