Wednesday, August 26, 2015

R and JRI Integration with Java for Analytics

Different ways(rJava with JRI, RServ, RCaller, Renjin) are there to integrate R with Java to perform some analytic work inside the Java (Servlet / controller). In this post I would like to show, how you can integrate rJava and JRI with java to run R code inside Java.

JRI Integration with Java: JRI stands for Java-R Interface and It is a part of rJava. Using rJava we can manipulate Java objects inside R using JNI (Java Native Interface) which is the natural way of calling compiled binary code in Java but JRI is reverse of it. In JRI we can call R inside Java. This library has some merit among others, in means of full interoperability between R and Java using callbacks. It is robust for large scale projects, however, it is painless at start-up process for relatively small projects.

To Install R on debian based systems run the following command
sudo apt-get install r-base-dev

Now to install rJava package in R run the following command
sudo apt-get install r-cran-rjava

Other wise you can run following command in R to install rJava
install.packages("rJava")

Once you install the R and rJava, to find the location of JRI inside rJava run the following command in R.
system.file("jri",package="rJava")







Now export R_HOME=/usr/lib/R, LD_LIBRARY_PATH=/usr/lib/R/site-library/rJava/jri into environment and add both of them in the Java library path also.

Now open your eclipse create a simple Java project "JRITest" with the below mentioned code. Before running the code in eclipse set R_HOME and LD_LIBRARY_PATH environment variables in eclipse. For setting up environment variables in eclipse

Right Click on Project -> Run As -> Run Configurations -> Environments then add environment variables with their values as shown below.





Sample Code To Test JRI In Java:
Sample Input Output:


Tuesday, June 23, 2015

Problems Faced By Motor Disability Persons In HCI

                    Computer trainers often comment on the fact that conventional devices are hard to use whose fingers might not be as steady or mobile anymore. Moreover Limited muscular control can cause lack of coordination or involuntary movement or impede movement altogether. Wide range of problems are faced by physical / motor disability persons in accessing computers, Some of them are as follows.

  • Pressing key board keys continuously- A physically challenged user can find pressing key board keys continuously for typing to be laborious due to limitations in motor control.
  • Long key press problem- An alphanumeric key is unintentionally pressed by differently enabled user for longer than the default key repeat delay because of slow typing speed.
  • Additional key press problem- During typing, A key adjacent to the intended key may be activate accidentally.
  • Key bounce problem- The end user may unintentionally presses the intended key more than once.
  • Difficulty in using hot keys- Some times it is not even easy for normal users to use hot keys. So, obviously motor disabilities find it more difficult to use SHIFT, CTRL and ALT keys with the combination of any other Keys.
  • Keys transposition error- When two keys are typed in the wrong order, a transposition error has occurred. Motor disabilities usually face this problem.
  • Mouse pointing problem- Mouse pointing is there in almost every operation of mouse like selecting one icon, among so many icons and closing an active window with mouse etc. So, pointing is the most fundamental mouse operation and also one of the most difficult for motor disabilities because Mouse pointing involves moving pointer in a desired direction and positioning at required place.
  • Navigation problem- For example in Debian based systems, if user wants to open gedit text editor, then user needs to navigate through Applications ->Accessories ->gedit. This requires three mouse button clicks which is inconvenient for some kind of motor disabilities.
  • Selection of text- involves to hold down mouse button and drag or hold down Shift key and press right arrow continuously. So, physically challenged people face problem in selection of text.
  • Hand-eye coordination problem- Hand-eye coordination is the ability of the vision system to coordinate the information received through the eyes to control, guide, and direct the hands in the accomplishment of a given task. Some kind of motor disabilities suffer from this problem because their hands doesn't give them enough support to process information received by eyes.
  • Drag and drop problem- Once a drag had been started, the most common difficulty is in raising the mouse button in the correct position at the end of the drag. Another common problem is in holding down the mouse button while moving the mouse to the target.

Sunday, June 14, 2015

C and C++ Code Counter - A Software Metric Tool

         CCCC ( C and C++ Code Counter) a software metrics tool. CCCC  analyses and  reports measurements of source code in C, C++, and Java. It was developed to augment programmers' instinctive application of  numeric  rules  of thumb about what constitutes high or low quality products with an automated analysis tool. CCCC processes the files listed on its command line.  If the  file names include ‘-’, read a list of files from standard input.

         CCCC will provide the following details/information of the code modules.
  • MVG = McCabe's Cyclomatic Complexity
    A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a sub-program. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure. 
  • NOM = Number of modules
    Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
  • LOC = Lines of Code
    Number of non-blank, non-comment lines of source code counted by the analyser.
  • COM = Lines of Comments
    Number of lines of comment identified by the analyser
  • L_C = Lines of code per line of comment
    Indicates density of comments with respect to textual size of program
  • M_C = Cyclomatic Complexity per line of comment
    Indicates density of comments with respect to logical complexity of program
  • IF4 = Information Flow measure
    Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.

Installation: CCCC is included in most of the linux operating systems repositories. You just need to type the following command to install CCCC on debian based systems.

- sudo apt-get install cccc

If the tools not available in your linux system repository you can download it from http://sourceforge.net/projects/cccc/ .

Usage: To know the usage of CCCC type the command man cccc in your terminal. A typical command of cccc usage is as follows.

- cccc your_sourcefile_name.cpp

The above command will generate a html page with name cccc.html in your present working directory, which provides the above mentioned information of your modules in the your_sourcefile_name.cpp. A sample cccc.html screen shot is as follows.


Wednesday, May 20, 2015

Workshop on Oracle 11g

Workshop on Oracle 11g - Database Design using Object Oriented Features: If you are a database enthusiast, then get the maximum benefit from this one day workshop on Oracle 11g by Mr. Sameer Dehadrai. More details can be found in the following picture /  brochure and the Registration can be done at: http://tinyurl.com/lolyj7h

Monday, May 18, 2015

Dooms Day Algorithm to Find Week Day of Given Date

        Using Dooms Day Algorithm / Rule any one can find the week day of given date between 1800 - 2199 years. So, The dooms day rule / formula is as follows



Dooms day = Anchor Day + [Year/12] + Remainder[Year/12] + [Remainder[Year/12]]/4

If the given date's year falls,

between 1800-1899, The Anchor Day is Friday
between 1900-1999, The Anchor Day is Wednesday
between 2000-2099, The Anchor Day is Tuesday
between 2100-2199, The Anchor Day is Sunday 

In the Above formula Year is last 2 digits of given date's year and in above equation solving wherever we get decimal values we have to take integer values only.

Once we get the dooms day for the given date's year using above formula, that dooms day will fall on last day of February (if given year is normal year on Feb 28, otherwise Feb 29), April 4 (4/4), June 6 (6/6), August 8 (8/8), October 10 (10/10) and December 12 (12/12).

Example: Lets find the week day of August 15, 1947.

The given date's year 1947 falls between 1900-1999 so the Anchor day is Wednesday.

Dooms day = Wednesday + [47/12] + Remainder[47/12] + [Remainder[47/12]]/4

Dooms day = Wednesday + 3 + 11 + 2

Dooms day = Wednesday + 16 (Divide this number by 7 and take remainder to find number of odd days)

Dooms day = Wednesday + 2 = Friday.

So the Dooms day for year 1947 is Friday and It will fall on August 8 as I said earlier. So, If August 8 is Friday after one week i.e., on August 15 is also going to be Friday.

So finally August 15, 1947 is Friday :-).

Thursday, January 8, 2015

Recursive Makefile for Sub-Directories

                 As we know, compiling is very tedious work, specially when we want to include several source files and have to type the compiling command every time we want to do compiling. It is even more difficult when our source files are in nested sub- directories.  To escape from these tedious work most of the people create Makefile. Makefile is a special format file that together with the make utility will help to automatically compile our several source files. The advantage of using Makefile is that it performs incremental compilation.

              Here, I would like to share a Makefile which is capable of compiling source files presented in nested sub-directories, creating objects of each source file in its directory and creating a binary from all object files presented in nested sub-directories. (NOTE: if you are using following Makefile, make sure to use tab at required places)

Makefile
***********

PREFIX            = /usr/local
INCLUDE        = /usr/include/X11/
PWDDIR          = $(shell pwd)
CXX                  = g++
RM                   = rm -vf
CONSTANTS   = -D__GXX_EXPERIMENTAL_CXX0X__       
CPPFLAGS      = -O0 -g3 -Wall -c -fmessage-length=0 -fpermissive -std=c++0x
LDFLAGS        = -lX11 -lXi -lXtst -lm
BINARY           = gframework_demo
DEPS               = $(shell find . -name '*.hpp')
SRCFILES       = $(shell find . -name '*.cpp')
OBJFILES        = $(SRCFILES:%.cpp=%.o)

all: $(BINARY)

$(BINARY): $(OBJFILES)
    $(CXX) -I$(INCLUDE) -o "$(BINARY)" $(OBJFILES) $(LDFLAGS)

%.o: %.cpp $(DEPS)
     $(CXX) $(CONSTANTS) -I$(INCLUDE) -I"$(PWDDIR)" $(CPPFLAGS) -c $< -o $@

clean:
    $(RM) $(shell find . -name '*.o') *~
    $(RM) $(BINARY)

install: $(BINARY)
    install -m 0755 $(BINARY) $(PREFIX)/bin
       
.PHONY: install

Wednesday, November 12, 2014

Drupal7 Installation and Website Development


For installing drupal7 we need to install LAMP(Linux, Apache, MySql, Php) server. I am assuming that you already installed any Debian based Linux(L) OS like Ubuntu. Run the following commands in terminal to install LAMP server.

Installing Apache(A):

To install apache2 run following command.

- sudo apt-get install apache2

To check apache2 installed, type the URL http://localhost/ in web browser.


Installing Php(P):

To install Php5 run following command.

- sudo apt-get install php5 libapache2-mod-php5

- sudo /etc/init.d/apache2 restart

To check php5 installed properly or not, create test.php in /var/www/ with code shown in screenshot.




Now type http://localhost/test.php in web browser, it will display the information of installed Php as shown in following screenshot.























Installing MySql(M):

To install MySql run following command in terminal.

- sudo apt-get install mysql-server

During MySql server installation do not forget to enter root user password.












Run following command to install phpadmin in terminal.

-  sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

During phpadmin installation select apache2 as default to run phpadmin using apache2, by pressing space tab as shown in screenshot.

During phpadmin installation setup required passwords also.

Now LAMP server is installed. Do the following settings also.

- Uncomment extension=msql.so in /etc/php5/apache2/php.ini file as shown in following screenshot.


- Add  ServerName localhost in /etc/apache2/httpd.conf file.

Creating Required MySql Database:

 Log into MySql using following command

- mysql -u root -p

Then create Required database using following command

- create database drupaldb;

Then create a user to access that database using following command

- create user 'user1'@'localhost';

Set password for created user user1

- update mysql.user set password=password('PassWord') where user='user1';

Grant all privileges to user1 on drupaldb using following command

- grant all privileges on drupaldb.* to 'user1'@'localhost';

Then flush all privileges using following command

- flush privileges;

Installing Drupal7:

Download drupal7 using following command

- wget http://ftp.drupal.org/files/projects/drupal-7.23.tar.gz

Now move downloaded drupal-7.23.tar.gz to /var/www/drupalsite folder and extract there itself. You need to create drupalsite folder in /var/www/. Change the owner of drupalsite by running following command.

- chown -r www-data.www-data drupalsite

Now make sure your apache HTTP listens to port 8001 (if you want you can use any other port also). To listen port 8001, enter Listen 8001 in /etc/apache2/ports.conf file as shown in following screenshot.


Now copy the contents of /etc/apache2/sites-available/default to /etc/apache2/sites-available/drupalsite and add the content shown in following screenshot to /etc/apache2/sites-available/drupalsite file.


Now run the following bunch of commands to take affect of made changes / settings.

- sudo a2ensite /etc/apache2/sites-available/drupalsite
- sudo /etc/init.d/apache2 reload
- sudo a2enmod vhost_alias rewrite
- sudo /etc/init.d/apache2 reload

 Now whatever setup needed for installation of drupal7 is ready. Type http://localhost:8001/install.php URL in web browser and you will see the page as shown in following screenshot.



Now click on Save and continue, in the next screen select english as language. After that, in database configuration enter database details, which you have created in mysql as shown in following screenshot.

In the next step enter all the details like site name, site maintenance e-mail and site maintenance account details.

 Once you enter the above details your drupal site is ready.

Now click on Visit your new site to see your site.

Now your basic drupalsite is ready. By using your site maintenance account you can create new content, new modules etc.

http://accessibledesktop.in is an example site developed using drupal7.