Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member


Part 1: Setup HCP account and IDE, twitter account and download first tweets

 

As a student in SAP HANA Product Management I had to explore what can be done on HCP trial landscape, what runs out-of-the-box, which SAP HANA features are available – and which business needs can be met, in the end? So, here are the results.


 


In this series of blogs I am going to explain how to build an real-time social media analytic application using the SAP HANA cloud platform (HCP). I wanted to make use of predictive algorithms. A hotspot for predictive is marketing. Therefore, I chose this topic. Of course, it is not ready-to-use, like a product. But it is “ready-to-copy-and-learn” and I named it SmartApp. While digging deeper and deeper, of course I learnt a lot through a multitude of other blogs and SAP HANA Academy videos. Thanks to all of you! (I do mention them below.)


 


It is an application that you can follow along yourself. However first let’s have a quick look at the overall scenario of the SmartApp. We are going to access some real-time social media information. I would like to take twitter as the example so we can get information on specific tweets that we want to look for and will pull those tweets out in real-time using the twitter API. The idea for this use was fueled by a nice blog from a Chinese colleague of mine, Wenjun Zhou:http://scn.sap.com/community/developer-center/hana/blog/2014/11/23/real-time-sentiment-rating-of-mov...- kudos to you for this work!


 


We will process those tweets and load them in real-time into the HANA database. However the database is hosted on HCP. It was my ambition to use an HCP developer trial edition for as long as possible (until I need a feature that is only available on a dedicated HANA instance). Once we loaded the data into the database then we can do some further analysis on how to group or segment the different types of tweeters, maybe we to group similar people together, for example the group of people expressing positive or negative sentiments towards the product or company, and it would also make sense to differentiate whether they are influential because a lot of people follow them and their tweets get retweeted. We could identify that group so we can target some education program or reach-out program to those people. So, the idea was to do some predictive analysis in HANA itself in order to segment, cluster or to group similar kinds of people sending tweets. And finally, I wanted to make the results available through web services i.e., OData, XSJS native web services within the HANA platform in order to build a HTML5 application that could run on desktop and mobile devices to look at the analysis results. That’s the overall scenario of the SmartApp.


 


I don't want this blog to stretch like a chewing gum, so I divided the whole story into 3 parts:


  


1. Setup HCP account and IDE, twitter account and download first tweets


2. Refine processing of tweets with text Analysis, building web services and setting HANA Cloud Connector – this is the “heavy lifting” on SAP HANA from my point of view!


3. Do the UX work – use Analytics tools – make it nice :smile:


 


 

In the following sections, of course there is a lot of overlap with many existing blogs out there. Thank you to everybody I learnt from. Here are just a few of them:




 

Prerequisites

 

Before we start to build the application, we need to register for HCP trial developer account and create Hana instance within the trial account (recommended to give instance name as “dev” and Database system as HANA XS (shared)since we can refer it in many applications).




Open SAP HANA Administration console perspective by clicking top right cornerof eclipse.


 

Find API keys

 

 


SET SCHEMA


 

First, identify the schema name to put application specific artifacts like tables, views:

To Identify and set Application schema keep DEV_xxx schema selected and hit onSQL button.



Make sure to set the database connection by clicking on.

 


Copy the following statements to the sql console in eclipse:


To Identify application schema,copy:


SELECT SCHEMA_NAME FROM "HCP"."HCP_DEV_METADATA";


 


To Identify current user,copy:


SELECT CURRENT_USER FROM DUMMY;


 


To Verify predictive analysis library is available,copy:


SELECT * FROM SYS.AFL_FUNCTIONS WHERE PACKAGE_NAME='PAL';


 


To Set application schema - paste in value below,copy:


SET SCHEMA NEO_;


Select & Run the statement to identify application schema:


SELECT SCHEMA_NAME FROM "HCP"."HCP_DEV_METADATA";  execute by clicking .  As a result, the schema name is shown.


 

Then right click on the schema name and copy the cells. To set application schema – Paste the value below as


SET SCHEMA NEO_xxxxxxxxxxx; execute it to activate the schema.


 


Create Tweets table executing the below code:


CREATE COLUMN TABLE "Tweets" (


           


             "id" VARCHAR(256) NOT NULL,


           


              "created" TIMESTAMP,


           


               "text" NVARCHAR(256),


           


               "lang" VARCHAR(256),


           


               "user" VARCHAR(256),


           


               "replyUser" VARCHAR(256),


          


               "retweetedUser" VARCHAR(256),


           


               "lat" DOUBLE,


       


               "lon" DOUBLE,


          


                PRIMARY KEY ("id")


);


 


Now we can find the tweets table in the schema (NEO_xxxxxxx) that we set initially.




 

Now install node.js to access both twitter API and HANA Database very easily that connects together.

 

To download the code of SmartApp from Git hub please click here.

 

Open downloaded SmartApp -> nodejs-> app.js in the editor may be notepad++.

 

In the code snippet we can see a variable called twitter where we actually specify the consumer_key, consumer_secret, access_token_key, access_token_secret. If you remember we already got this information when we registered our application in twitter. Now copy and paste the consumer_key into our file. Similarly do the same for other values also as shown below.


 

var twitter = new twitter({

       consumer_key: 'xxxxxxxx',

 

      consumer_secret: 'xxxxxxxxxxx',

 

      access_token_key: 'xxxxxxxxxxx',

 

       access_token_secret: 'xxxxxxxxxxx'

 

We have a second file called package.json in the nodejs with the list of dependencies like express, request, oauth, twitter, hdb that are used in our application. Now we can install all these with an npm and node installation command. Now click shift+rightmouse button on the nodejs folder in the SmartApp to open a command prompt in that nodejs folder then use “npm install” command to install all the dependencies that we needed in our application.


 

Then Restart the system (computer) so that nodejs could run without errors.





Go to nodejs folder should be able to see node_modules folder which actually consists the code for the modules setup and installed.

 

Setup the Tunnel

 

Let us setup the Database tunnel to connect directly to the HANA database using p-number trial id (pxxxxtrial). In order to setup the database tunnel open a command prompt on the tools folder in neo-java-web-sdk by shift+right click mouse button. Now execute the command “neo open-db-tunnel –h hanatrial.ondemand.com –i dev –a pxxxtrial –u pxxxx” (please enter the command manually don’t copy!) by replacing the account name with your pxxxxxtrial account and username with the pxxxx number.


 


After executing the command enter the password that you gave during the trial account creation. The tunnel opened and gives us the properties to connect to the schema.



Now go to the app.js file, edit the port as 30115 then copy the user, password, Schema name properties and paste in the app.js file respectively as shown below.


 

var hdb = hdb.createClient({

            host     : 'localhost',

            port     : 30115,

            user     : 'DEV_xxxxxxxxxxxxxxxxx',

            password : 'xxxxxxxxxxxxxx'

});

var hdb_schema = "NEO_xxxxxxxxxxxxxx";

 

Now let’s start the application by simply going into command prompt running in the nodejs folder. Goto the downloaded smartApp -> nodejs folder then shift+right click then select open command window.Type “node app.js” as command, application will run and we can see two messages as shown below.



Goto the Chrome browser enter “localhost:8888/do/start?track = productname or companyname”. 


 


Note: Enter the product or company name that you would like to track or make analysis. 


Now we can see in nodejs command prompt that tweets are loading into HANA database. Go to the tweets table in eclipse and refresh by clicking on top right corner. We can see some tweets that are loaded in to table.



If you want to stop loading the tweets go back to chrome browser then type “localhost:8888/do/stop”.


 


Note: While working with tunnel it must remain open for nodejs in order to be connect to the Hana instance. Since it’s a trial account this tunnel only lasts for 24 hours at that time you need to reopen it. However it’s fine for development and testing purposes. When using Productive HCP able to let things run 24/7.


 


Thanks for reading. Hope you enjoyed the blog…. :smile:


 


Next Steps


In the next blog will perform some text analysis on Tweets data, Setup SAP HANA Cloud Connector and Configurations, Building web services using HANA Native development and setup authorizations. I will insert the link in here as soon as it is available!



6 Comments