A script to use an Alma set as a basis for analysis
Although it is possible to create a set in Alma from an analysis, for now it is not possible to do the opposite.
In Analytics you would need to create an “is equal to / is in” filter with lots of data and doing it manually is very difficult, so I developed a Python script that retrieves all the data from a set of Alma directly via API or reads it from a field of a CSV file (which could be obtained from an exported set or even from another source); the data obtained will be used to construct the filter and insert it into an analysis.
- The script almaset2analytics.py is available on GitHub:
How to use the script
As an example, I have a set of titles in Alma and I want to use all MMS IDs from it as a basis for an analysis report containing creation and modification date, and total number of loans.
In Analytics, create a new Title Analysis (o use an existing one):
Add a “is prompted” filter on the column you want to populate with data from the set (if you want you can add more filters, but only one can be a “is prompted” filter type)
Go to the “Advanced” tab, select all and copy the text into the “Analysis XML” box:
Past all xml in a text editor and save it in the same directory of the script (report_example.xml):
In Alma, copy the set id from “Set Details”:
Open a terminal/CMD in the script directory and invoke this command:
python almaset2analytics.py report_example.xml -s 2073710990003298 -o report_output.xml
The script retrieves the analysis in report_example.xml, collecting all members of the set and writes the modified analysis in report_output.xml.
Now open the report_output.xml file:
As you can see, the script added the set members as a “IN” filter of “Bibliographic Details”.”MMS ID” column, that was previously filtered with a “Is prompted” filter.
Now you can re-open the analysis in Analytics, or if you prefer create a new empty one, then go to the “Advanced” tab and delete all content in the “Analysis XML” box:
Copy all the content of report_output.xml file and past it into the box, then click on the “Apply XML” button:
Now you can see the analysis changed:
And here you get the results:
SET id as source of data (via Configuration and Administration API)
The example above uses the “retrieve set members” API method to collect data: a Configuration and Administration API key is needed and has to be copied in the INI section of the script:
If you add the -d argument when you invoke the script, the data are collected from the description tag instead of the id tag (look here about the xml data format returned by the retrieve members set API : https://developers.exlibrisgroup.com/alma/apis/docs/xsd/rest_members.xsd/?tags=GET)
CSV file as source of data
Instead of set id, you can use a CSV file as source of data, getting it for example from an excel/calc export of a set:
Save it as CSV file (ex., result.csv) with headings in the same directory of the script, and remember the column from where to collect the data (ex., “MMS ID”), then invoke this command:
python almaset2analytics.py report_example.xml -f results.csv -c "MMS ID" -o report_output.xml
and then proceed to copy the new analysis in Analytics as above.
This method is recommended for large data sets, because it is faster and doesn’t need multiple API calls.
I have tested the script using a large set with 42000 members, and it worked fine, even if Analytics was obviously slow to give the results: let me know if you have success or failures with larger sets.