Serverless Functions for TM1/Planning Analytics in 20 Minutes
Key Takeaways
This video demonstrates how to deploy serverless functions for TM1/Planning Analytics using IBM Cloud Functions, Python, and TM1PI, allowing users to interact with their Planning Analytics environment from anywhere. It covers setting up virtual environments, installing dependencies, writing Python scripts, and deploying serverless functions using Cloud Foundry.
Full Transcript
[Music] the resemblance is uncanny right what's happening guys my name is nicolas for not and in this video we're going to be taking a look at how you can use serverless functions and specifically we're going to be taking a look at how you can use serverless functions with planning analytics let's take a look in greater detail as to what we're going to be going through so in this video we're going to be covering a bunch of stuff but specifically we're going to be focusing on how to create virtual environments with python we're then going to take a look at how you can write a serverless function to push data into planning analytics and then last but not least we're actually going to use this as a web hook and deploy it using ibm cloud functions so in terms of how we're going to be doing it we're going to be using a python function to load data into our planning analytics cube but really this could be a database or it could be a csv it could be a text file could be really any other external repository when we actually go and deploy that function we're going to be using ibm cloud functions to deploy this as a serverless web hook and the reason why this is so useful is because later on we're going to be able to integrate with watson assistant to load information into that source using natural language processing ready to get to it let's do it what's happening guys so in today's video we're going to be taking a look at serverless functions and specifically we're going to be setting up a serverless function that allows us to send commentary to our planning analytics cube so if you haven't worked with planning analytics before basically it's a super sophisticated modeling tool that's used all around the world for a whole bunch of stuff including budgeting forecasting and all that good stuff now in terms of how we're going to get started with this we're going to have to set up a python virtual environment first up then we're going to write some code we're going to run it and then deploy it on ibm cloud now the first thing that we need to do is set up our virtual environment now i'm already inside of this folder here within my terminal so you can see i'm inside of the folder called pa serverless now what i need to do in order to create a virtual environment is just use the virtual env command now if you haven't worked with virtual environments before basically it's taking a copy of your python environment and encapsulating it all in its own little package so let's go ahead and set one up now in order to do this as i said we're going to use the virtual env command so what i've typed in is virtual env and then virtual emv again so the first virtual env is the actual command the second virtual env is actually what we're going to be calling our virtual environment so if we run that you can see that we've now created a virtual environment inside of our folder and then we can activate this using the source activate command so we can type in source virtual env bin slash activate and you can see that we've now activated our virtual environment over here now that we've set up our virtual environment we can sort of work with this as we would any other python environment now in order to build our serverless function we're going to need tm1pi so this is going to allow us to work with our planning analytics server so we can install that just using the regular pip install command so let's do that okay so what i've typed in is pip install tier 1 pi this is going to allow us to install tier 1 pi inside of our virtual environment so let's go ahead and run that perfect so that's all done so that's now installed now what we're going to do is open it up inside of our favorite coding environment so in this case i'm going to be using vs code and we're going to start writing our python script now the core purpose of this python script is to load commentary into our planning analytics cube so eventually we're going to be able to hook this up to what's an assistant in a future video to be able to send commentary through using natural language processing so we're largely focused on capturing our commentary as well as where we want our commentary to be within our planning analytics cube in order to send that through now to start off with we're just going to create a python script and this is going to be where we encapsulate all of our code so let's go ahead and create a new python file and we're just going to call it main dot pi now inside of here we're going to be doing a bunch of stuff so let's make this a little bit bigger so we can see what we're doing and we've got a bit of a to-do list so first thing we need to import our dependencies then we're going to be writing up a main function and this is going to be what our serverless function calls then we're going to grab our tm1 credentials create a cell set write that to the cube and then return our result and then right at the end we're basically going to call our function as well so first up let's go ahead and import our dependencies and that's our core dependency so really all we're going to need is tier 1 pi and specifically the tm1 service now what we can go ahead and do is create our main function so this is going to be the main function that gets called whenever we run our serverless function on ibm cloud so let's do that so in order to create a function we use the def statement we then pass through what we want our function name to be so in this case we're calling it main and then if we want to pass through any parameters or any keyword arguments then we're basically passing them through here now what we want to do is actually write all the code that needs to be within our function so in this case all of this stuff is going to be encapsulated within our function so first up we're going to grab our credentials and get our cell set right to the cube then return our result so our credential details as well as the details for the cube that we want to push through to are going to be stored within our parameters now what we can do is we can access anything from our parameters using params and then basically typing in the keyword so it might be username might be password so on and so forth so for example it might look like that now but what we want to do is actually put this inside of a python dictionary so that we can easily pass it through to t in one pipe so let's go on ahead and set up our credentials and then we're going to start building our cell set so that's our credentials dictionary setup so what we've basically gone and done is created a new python dictionary called creds and then we've passed through a bunch of keys so specifically we've got our user we've got our password our port whether or not we want ssl enabled or not as well as our server address and we're basically going to be passing through these through as keyword arguments inside of our parameters so we're grabbing out of that our pa user so that's going to be our user pa password which is going to be our password pa port which is going to be our port and pa address which is going to be our server address we're going to do a similar thing for our cell set so let's go ahead and do that okay so that's our cell set set up now what we've actually gone and done there is again we've created a dictionary and then we've specified first our key so our key basically represents the intersection where we want to push our data to inside of planning analytics so in this case we've specified and this keep in mind this is in the same order of the dimensions with inside your cube so in this case we've got month version currency cost center account project source and measure and then the last value that we're passing through is we're setting the value for that key to the value that we want to pass through so this is going to be effectively the commentary that we send through to planning analytics all right so with that all said and done then what we can do is actually write to the cube so this is going to be using a sort of standard tier one pie line basically we're going to use the with statement we're going to pass through our credentials and then we're going to push our cell set into our teremon cube perfect so that's done now if we take a look at that line of code there so what we're basically doing is we're again we're using the with statement to connect to our tm1 service and then we're using tm1.cubes.cells.writevalues to actually go and write our cell set to our cube the parameters that we pass through to our right values function are first up our cube so in this case we're specifying general ledger because we're going to be hitting our general ledger cube then we're passing through our cell set so this is all the data that we've collected up here and then we're also passing through our dimensions now this is optional but if you've got sandboxes enabled as a dimension within your cube you tend to have to pass through this parameter so this parameter basically specifies the dimensions that you're passing through and in what order within your cell set so in this case we're going in order so we're passing through our time month our version currency cost center account project general ledger source and general ledger measure and if we step back through to our tm1 cube you can see that that's going to be the same order that our dimensions are in so you can see we've got our month our version currency cost center account project source and measure alrighty so that's our write done now what we want to do is return a result to our user so if we're successful then we basically want to return a yes that was written successfully to our cube perfect so that's us returning our results so first up we're going to print the data's loaded and then last but not least we're going to return our headers so we need to pass through some headers whenever we're returning something so in this case we're sending through json and then we're also specifying the body so our body is going to include our message and it's basically going to say commentary loaded now what we can do is actually set up our call so in this case we're basically going to be running this entire file so it's going to detect whether or not we're running the file and then it's actually going to go ahead and call our service and push through some commentary so let's set this up alrighty and that's all of our code done so basically what we've said is if we're running this file then basically we're going to set up our default parameters so these are just defaults in this case but when we actually go and deploy this as a cloud function we're going to be able to pass through our own parameters so what we're doing is we're passing through our pa user pa password pa port and pa address which are going to help us populate our credentials up there and then what we're also passing through is the month version currency cost center account project general ledger source general ledger measure and our value as well so these are basically going to help us populate our cell set that we've got here and then we're calling our function so this is basically going to go ahead and call this main function here and ideally all things holding equal this should push through and send some comments to our pa cube so let's open up a terminal here and then what we can actually go and do is actually go and run this function so in order to do that we just need to run a python under squat underscore main underscore underscore dot pi and you can see that our data looks like it's loaded so let's go ahead and check it out and you can see that we've actually gone and loaded a test comment so right now this is obviously running on our local machine actually let's test that out a little bit more so let's go and try something else let's say this is a new test comment or just something random hotline bling and then let's run it again we refresh you can see that we're now refreshing our commentary so the power of this is that we can use these functions and once they're deployed we can hit them from anywhere with a single api request so now if we wanted to we can actually go and deploy this as a function on ibm cloud so if we step on over to cloud.ibm.com forward slash functions you can see this is basically where we can deploy serverless functions which allow us to go and hit this from just about anywhere and eventually when we go and use our deployed function with what's an assistant this is going to be the web hook that we're hitting so let's go ahead and actually deploy this as a serverless function now so it's actually relatively easy all we need to do is basically log into ibm cloud or first i'm going to zip up everything that we've got within this folder here let's step back my bad we minimize that so in order to do this all we need to do is zip up everything that we've got here we're then going to be able to log into ibm cloud through the cli and then push this function up to there so we've now got a serverless function deployed so let's go on ahead and first up we're going to zip up everything that we've got within that folder so let's do that so in order to zip we're basically using the zip function we're passing through r and then we're specifying the name of our folder so this is going to be called pa serverless.zip once we've zipped it up and we want to include our virtual env folder which is that up there as well as our main.pi file and you can see we've now zipped it up into pa serverless.zip then what we need to do is log into the ibm cloud console so let's go and log in so we can do that using let's just clear this to make it a little bit cleaner so we can do that using ibm cloud login i'm going to be using sso but in this case when you log in you'll be prompted to pass through your username and password so i'm just going to type in sso because i have to and once you're authenticated you just need to select your account so i've got a couple accounts showing but you'll probably only have a single account so that will allow you to specify which account you want to go and deploy this in and we don't want to update then what we need to do is make sure we're targeting the u.s south region so this is going to allow us to bundle up all of our stuff and push it up as a cloud function so let's go on ahead and point to the right region so in order to change our region we just need to type in ibm cloud target dash r us south and that's our region specified and then what we want to do is target cloud foundry so cloud foundry makes it easy to deploy these functions and it's basically going to allow us to deploy this a whole lot easier so in order to target cloud foundry we just need to type in ibm cloud target dash dash cf so you can see we've typed in ibm cloud target dash dash cf so that's cloud foundry and that's now done now the last thing that we need to do is we basically just need to go on ahead and deploy our cloud function so let's go ahead and deploy it okay so that's our cloud function down there so let's just zoom in a little bit so what we've basically done is we're in an ibm cloud so that's going to allow us to use our ibm cloud cli then we've specified that we want to create an action so basically specified function action create then we've specified what we want our function to be called on ibm cloud as well as where all of our stuff is located so in this case it's located in paserlis.zip we've specified what type of function we want to deploy so in this case it's python 3.7 and we've also specified where our main function is so in this case our main function is called main as we saw within our file so you can see it's right up here and then all we need to do is hit enter and this is going to create our serverless function inside of ibm cloud so let's let that deploy and you can see we've successfully created our serverless function it said ok created action pa serverless so now if we go back to ibm cloud functions we should be able to see this deployed so if we select actions you can see that we've got one called pa serverless yes deployed alright so now that our function's deployed there's a couple of key things that we need to do before we can use it so first up we just need to go to parameters and add in our parameters so these are going to be our environment variables or effectively our server variables so in here we can store our planning analytics username password server and port and so on so let's go ahead and specify those all right so we've got four credentials and these are effectively our user our password our port and our address now if we cast our mind back to our code these are effectively helping us populate our credentials here so let's fill these in so the first two parameters that we're passing through are just our regular planning analytics username and password then our port is going to be our http port so in this case i got lucky i've got one two three four five and then our server name is effectively going to be our server address so in this case we can just copy this and paste that in here and remove the http and there we go so that's our parameters set up now the next thing that we can do is actually invoke this code now in order to send through our cube and our values we can basically invoke this with some parameters so in order to send this through we just need to have a json object so i've got a json object here and in this case we've got our month our version our currency cost center account so on now if we wanted to actually go and send this through all we need to do is hit apply and then we can hit invoke and that will run our function and there you go so we've successfully sent through data to our planning analytics cube and you can see that we've written out data loaded so if we go back and hit refresh you can see that our commentary is now coming through now if we wanted to we can change our comment so in this case we're sending it to fy2019 budget local all cost centers all accounts but we could say our budget will not catch up likely to be a saving and we can hit apply and then invoke it again and again this is going to go through the same process use our function and send it through so you can see it ran pretty fast that time and you can see that our commentary is now coming through to our cube so this is basically a precursor to us setting this up with watson assistant eventually we're going to be able to call this function from watson assistant and pass through our commentary using natural language processing so we covered a bunch in this video specifically we set up our virtual environment we wrote all of our python code to send our commentary to our planning analytics cube we then deployed our function using ibm cloud foundry and our serverless functions and then last but not least we actually went and tested it out and we invoked our serverless function thanks so much for tuning in guys hopefully you found this video useful if you did be sure to give it a thumbs up hit subscribe and tick that bell so you get notified of when i release future videos and let me know what you're going to be using serverless functions for thanks again for tuning in [Music] peace you
Original Description
Want to interact with your Planning Analytics environment…from anywhere?
Say hello to cloud functions!
“What’s a cloud function?”
Cloud functions (aka server less functions) allow you to deploy and run your code as and when you need it without having a dedicated server. Using them, you can save a heap on server running costs but more excitingly…you can begin to load data into Planning Analytics using Watson Assistant!!
In this video you’ll learn how to:
1. Create Python Virtual Environments
2. Load data into Planning Analytics from Python Functions
3. Setup Webhooks for Planning Analytics with Cloud Functions
Github Repo for the Project: https://github.com/nicknochnack/PlanningAnalyticsCloudFunctions
Want to learn more about it all:
Cloud Functions: https://cloud.ibm.com/functions/
TM1py: https://github.com/cubewise-code/tm1py
Planning Analytics: https://www.ibm.com/au-en/products/planning-analytics
Oh, and don't forget to connect with me!
LinkedIn: https://www.linkedin.com/in/nicholasrenotte
Facebook: https://www.facebook.com/nickrenotte/
GitHub: https://github.com/nicknochnack
Happy coding!
Nick
P.s. Let me know how you go and drop a comment if you need a hand!
Music by Lakey Inspired
Chill Day - https://www.youtube.com/watch?v=3HjG1Y4QpVA
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Nicholas Renotte · Nicholas Renotte · 59 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
▶
60
Face Detection - Build An Image Classifier with IBM Watson - Part 7
Nicholas Renotte
Food Image Classification - Build An Image Classifier with IBM Watson - Part 6
Nicholas Renotte
General Image Classification - Build An Image Classifier with IBM Watson - Part 5
Nicholas Renotte
Installing Watson Developer Cloud - Build An Image Classifier with IBM Watson - Part 4
Nicholas Renotte
Generating Credentials - Build An Image Classifier with IBM Watson - Part 3
Nicholas Renotte
Creating A Service - Build An Image Classifier with IBM Watson - Part 2
Nicholas Renotte
Getting an IBMid - Build An Image Classifier with IBM Watson - Part 1
Nicholas Renotte
How to Analyse Review Data - Part 2 - Python Yelp Sentiment Analysis
Nicholas Renotte
How to Lemmatize Text - Part 4 - Python Yelp Sentiment Analysis
Nicholas Renotte
How to Calculate Sentiment Using TextBlob - Part 5 - Python Yelp Sentiment Analysis
Nicholas Renotte
How to Collect Business Reviews Using Python - Part 1 - Python Yelp Sentiment Analysis
Nicholas Renotte
How to Clean Text Based Data for NLP - Part 3 - Python Yelp Sentiment Analysis
Nicholas Renotte
How to Setup a IBM Watson Personality Insights Service - Part 1 - Watson Personality Insights
Nicholas Renotte
How to Create a Customer Profile with IBM Watson - Part 2 - Watson Personality Insights
Nicholas Renotte
Visualising The Profile Part 3 Watson Personality Insights
Nicholas Renotte
How to Plot Personality Insights Features at Lightspeed - Part 4 - IBM Watson Personality Insights
Nicholas Renotte
Getting Started With IBM Watson Studio Machine Learning - Part 1 - Predicting Used Car Prices
Nicholas Renotte
Upload and Visualize Data In IBM Watson Studio - Part 2 - Predicting Used Car Prices
Nicholas Renotte
Clean Data and Feature Engineer in IBM Watson Studio - Part 3 - Predict Used Car Prices
Nicholas Renotte
Using Watson Model Builder to Predict Car Prices - Part 4 - Predicting Used Car Prices
Nicholas Renotte
Deploy and Make Predictions With Watson Studio - Part 5 - Predicting Used Car Prices
Nicholas Renotte
Getting Started With IBM Watson Discovery - Part 1 - Stock News Crawler
Nicholas Renotte
How to Run Advanced Queries with Watson Discovery - Part 5 - Stock News Crawler
Nicholas Renotte
How to Run Search Queries with IBM Watson Discovery - Part 4 - Stock News Crawler
Nicholas Renotte
How to Understand the Watson Discovery Data Schema - Part 3 - Stock News Crawler
Nicholas Renotte
How to Build a Watson Discovery Web Crawler - Part 2 - Stock News Crawler
Nicholas Renotte
AI learns what to do next using Tensorflow and Python
Nicholas Renotte
Chatbot Crash Course for Absolute Beginners - Full 20 Minute Tutorial
Nicholas Renotte
Shopify Customer Service Chatbot using Python Automation
Nicholas Renotte
Building a Reddit Keyword Research Chatbot
Nicholas Renotte
Chatbot App Tutorial with Javascript Node.js [Part 1]
Nicholas Renotte
Javascript Chatbot From Scratch with React.Js [Part 2]
Nicholas Renotte
Predicting Churn with Automated Python Machine Learning
Nicholas Renotte
Sales Forecasting in Excel with Machine Learning and Python Automation
Nicholas Renotte
Automate Budgeting with Python and Planning Analytics
Nicholas Renotte
AI vs Machine Learning vs Deep Learning vs Data Science
Nicholas Renotte
Optimizing Marketing Spend using Linear Programming || Marketing Opt PT.1
Nicholas Renotte
Solving Optimization Problems with Python Linear Programming
Nicholas Renotte
Loading Data into Planning Analytics with Python || Marketing Opt PT.2
Nicholas Renotte
Building Marketing Dashboards with Planning Analytics Workspace || Marketing Opt PT.3
Nicholas Renotte
Optimizing Resource Allocation with Docplex and Planning Analytics || Marketing Opt PT.4
Nicholas Renotte
Exploratory Data Analysis With Pandas || Python Machine Learning PT.1
Nicholas Renotte
Preparing Pandas Dataframes for Machine Learning || Python Machine Learning PT.2
Nicholas Renotte
Python Machine Learning with Scikit Learn - Regression || Python Machine Learning PT.3
Nicholas Renotte
Deploying Machine Learning Models with Watson Machine Learning || Python Machine Learning PT.4
Nicholas Renotte
Mind Blowing Machine Learning Apps with Node.JS and Watson Machine Learning || Python ML PT.5
Nicholas Renotte
Build FAST Machine Learning Apps with Javascript React.Js and Watson || Python ML PT.6
Nicholas Renotte
Analyzing Twitter Accounts with Python and Personality Insights
Nicholas Renotte
Converting Speech to Text in 10 Minutes with Python and Watson
Nicholas Renotte
Build a Face Mask Detector in 20 Minutes with Watson and Python
Nicholas Renotte
AI Text to Speech in 10 Minutes with Python and Watson TTS
Nicholas Renotte
Pandas for Data Science in 20 Minutes | Python Crash Course
Nicholas Renotte
Language Translation and Identification in 10 Minutes with Python and Watson AI
Nicholas Renotte
Analyse ANY Conversation in 10 Minutes with Python and Watson Tone Analyser
Nicholas Renotte
Deep Reinforcement Learning Tutorial for Python in 20 Minutes
Nicholas Renotte
NumPy for Beginners in 15 minutes | Python Crash Course
Nicholas Renotte
Real Time Pose Estimation with Tensorflow.Js and Javascript
Nicholas Renotte
Transcribe Video to Text with Python and Watson in 15 Minutes
Nicholas Renotte
Serverless Functions for TM1/Planning Analytics in 20 Minutes
Nicholas Renotte
Building a AI Budget Bot for Planning Analytics with Watson Assistant in 20 Minutes
Nicholas Renotte
More on: Tool Use & Function Calling
View skill →
🎓
Tutor Explanation
DeepCamp AI