JAVA7.0 Data science Part2
OakJava7 Data Science
What is Data Science ?
Data science is the field of study that combines domain expertise, programming skills, and knowledge of mathematics and statistics to extract meaningful insights from data. ... In turn, these systems generate insights which analysts and business users can translate into tangible business value.
Note: For JAVA7.0 Data Science Part1 kindly see the given below url : https://sites.google.com/site/oakjava7programminglanguage/java7-0-machinelearning-part1
======================================================================================
Data Science Topic-1 : Line graph
======================================================================================
Draw a line graph to display no of student join according to year with date
using Oakjava7 program with Oj7UA framework.
linegraph5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{}' Names='ConsoleApp28,linegraph1' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() { HTML.displayhtml("linegraph.html"); } '>
</OakJava7>
</OJ7ML>
linegraphml.web
==============
<WEB>
<PACK> ConsoleApp28
{
<CLASS> linegraph1
{
public void main()
{
HTML.displayhtml("linegraph.html");
}
}
}
Note: include html.dll in the properties file.
linegraph.html
==============
<!DOCTYPE HTML>
<head>
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "No of students join in Scott christian college"
},
data: [
{
type: "line",
dataPoints: [
{ x: new Date(2000, 00, 1), y: 450 },
{ x: new Date(2002, 01, 1), y: 414 },
{ x: new Date(2004, 02, 1), y: 520 },
{ x: new Date(2005, 03, 1), y: 460 },
{ x: new Date(2006, 04, 1), y: 450 },
{ x: new Date(2007, 05, 1), y: 500 },
{ x: new Date(2008, 06, 1), y: 480 },
{ x: new Date(2012, 07, 1), y: 480 },
{ x: new Date(2014, 08, 1), y: 410 },
{ x: new Date(2018, 09, 1), y: 500 },
{ x: new Date(2019, 10, 1), y: 480 },
{ x: new Date(2020, 11, 1), y: 510 }
]
}
]
});
chart.render();
}
</script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script></head>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;">
</div>
</body>
</html>
OUTPUT
==============================================================================================
Data Science Topic-2 : Normal Distribution using google.visualization.AreaChart
=============================================================================================
Draw a Graph for Normal Distribution using Oakjava7 program with OJ7UA Framework and use Google visualization Area chart.
normaldistribution5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{}' Names='ConsoleApp28,linegraph1' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() { HTML.displayhtml("normaldist.html"); } '>
</OakJava7>
</OJ7ML>
normaldistribution.web
========================
<WEB>
<PACK> ConsoleApp28
{
<CLASS> normaldistribution
{
public void main()
{
HTML.displayhtml("normaldist.html");
}
}
}
Note: include html.dll in the properties file.
normaldist.html
===============
<!DOCTYPE html>
<html>
<head>
<title> Normal Distribution</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://www.google.com/jsapi?ext.js">
</script>
<script>
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'X Value');
data.addColumn('number', 'Y Value');
function NormalDensityZx(x, Mean, StdDev) {
var a = x - Mean;
return Math.exp(-(a * a) / (2 * StdDev * StdDev)) / (Math.sqrt(2 * Math.PI) * StdDev);
}
var chartData = new Array([]);
var index = 0;
for (var i = -3; i < 3.1; i += 0.1)
{
chartData[index] = new Array(2);
chartData[index][0] = i;
chartData[index][1] =
NormalDensityZx(i, 0, 1);
index++;
}
data.addRows(chartData);
options = { height: 500, width: 800, legend: 'none' };
options.hAxis = {};
options.hAxis.minorGridlines = {};
options.hAxis.minorGridlines.count = 12;
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
google.load('visualization', '1', { packages: ['corechart'], callback: drawChart });
</script>
</head>
<body class="chart">
<div id="chart_div"></div>
</body>
</html>
OUTPUT
============================================================================================
Data Science Topic-3 : Bubble Chart
============================================================================================
A bubble chart is used to visualize a data set with two to four dimensions.
The first two dimensions are visualized as coordinates, the third as color and the fourth as size.
Develop a bubble chart using oakjava7 and OJ7UA framework
====================================================================
bubblechart5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{format}' Names='Chart5,bubblechart1' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() { J7HTML.displayhtml("bubblechart.html"); } '>
</OakJava7>
</OJ7ML>
bubblechart.web
===============
<WEB>
<USE> format;
<PACK> ConsoleApp28
{
<CLASS> linegraph1
{
public void main()
{
J7HTML.displayhtml("bubblechart.html");
}
}
}
Note: include J7HTML.dll in the properties file.
bubblechart.html
================
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawSeriesChart);
function drawSeriesChart() {
var data = google.visualization.arrayToDataTable(
[
['ID', 'Life Expectancy', 'Fertility Rate', 'Region', 'Population'],
['CAN', 80.66, 1.67, 'North America', 33739900],
['DEU', 79.84, 1.36, 'Europe', 81902307],
['DNK', 78.6, 1.84, 'Europe', 5523095],
['EGY', 72.73, 2.78, 'Middle East', 79716203],
['GBR', 80.05, 2, 'Europe', 61801570],
['IRN', 72.49, 1.7, 'Middle East', 73137148],
['IRQ', 68.09, 4.77, 'Middle East', 31090763],
['ISR', 81.55, 2.96, 'Middle East', 7485600],
['RUS', 68.6, 1.54, 'Europe', 141850000],
['USA', 78.09, 2.05, 'North America', 307007000]
]
);
var options = {
title: 'Correlation between life expectancy, fertility rate ' +
'and population of some world countries (2010)',
hAxis: {title: 'Life Expectancy'},
vAxis: {title: 'Fertility Rate'},
bubble: {textStyle: {fontSize: 11}}
};
var chart = new google.visualization.BubbleChart(document.getElementById('series_chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="series_chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
Hardcoded values in oakjava7 code are not good.And when the data go
with so many fields and so many data. In this case
Web1.0 Programming Language is focused.
list.data
=========
[
['ID', 'Life Expectancy', 'Fertility Rate', 'Region', 'Population'],
['CAN', 80.66, 1.67, 'North America', 33739900],
['DEU', 79.84, 1.36, 'Europe', 81902307],
['DNK', 78.6, 1.84, 'Europe', 5523095],
['EGY', 72.73, 2.78, 'Middle East', 79716203],
['GBR', 80.05, 2, 'Europe', 61801570],
['IRN', 72.49, 1.7, 'Middle East', 73137148],
['IRQ', 68.09, 4.77, 'Middle East', 31090763],
['ISR', 81.55, 2.96, 'Middle East', 7485600],
['RUS', 68.6, 1.54, 'Europe', 141850000],
['USA', 78.09, 2.05, 'North America', 307007000]
]
list.Web
=========
<WEB>
<WPACK>
<%
public class list
{
public void WEB-Main( ) throws <EXE>
{
HTML.displayhtml("list.data");
}
}
%>
</WEB>
Explanation
This *.Web will create any type of data or json.
We notice that there are many types of data at
Google chart. When compiling using
Web1.0 Server creates a encrypted file
list.WS.
Now write a oakjava7 program to get the data from
Web1.0 webservice.
datalist5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{java7displayurl,format}' Names='Datalist,bubblechart' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() { String s="";
s=java7UrlConnectionReader.getUrlContents("http://localhost:8082/list.WS").Replace("g$HTML>","").Replace("g$/html>","");
String display=Oj7ui.OJ7ML.Oj7Html("Bubblechart1.html", s,"Bubblechart2.html");
PRINTLN(display); } '>
</OakJava7>
</OJ7ML>
datalist.web
<WEB>
<USE> java7displayurl;
<USE> format;
<PACK> Program121
{
<CLASS> Prog
{
public void main()
{
String s="";
s= java7UrlConnectionReader.getUrlContents("http://localhost:8082/list.WS").Replace("<HTML>","").Replace("</html>","");
J7HTML.displayhtml("Bubblechart1.html");
<PRINTLN>(""+s);
J7HTML.displayhtml("Bubblechart2.html");
}
}
}
and after that compile the oakjava7 program
using Java7Shell. It will create datalist.exe
and now rename the file as you want
and put that .exe file in Scrollserver.
Note:
=====
You had to include java7UrlConnectionReader.dll, J7Html.dll in Java7.0 properties file..
Start Web1.0Part2 webservice server to run Google chart data type list.WS. webservice.
Here we are using Google chart data type with web1.0 webservice..
Bubblechart1.html
=================
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawSeriesChart);
function drawSeriesChart() {
var data = google.visualization.arrayToDataTable(
Bubblechart2.html
==================
);
var options = {
title: 'Correlation between life expectancy, fertility rate ' +
'and population of some world countries (2010)',
hAxis: {title: 'Life Expectancy'},
vAxis: {title: 'Fertility Rate'},
bubble: {textStyle: {fontSize: 11}}
};
var chart = new google.visualization.BubbleChart(document.getElementById('series_chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="series_chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
OUTPUT
============================================================================================
Data Science Topic-4 : Linear expression chart
============================================================================================
Linear Functions
===============
In mathematics a function is used to relate one variable to another variable.
The relationship between a dependent and an independent variable can often be expressed mathematically using a formula (function).
A linear function has one independent variable (x) and one dependent variable (y), and has the following form:
y = f(x) = ax + b
This function is used to calculate a value for the dependent variable when we choose a value for the independent variable.
Explanation:
============
f(x) = the output (the dependant variable)
x = the input (the independant variable)
a = slope = is the coefficient of the independent variable. It gives the rate of change of the dependent variable
b = intercept = is the value of the dependent variable when x = 0. It is also the point where the diagonal line crosses the vertical axis.
This equation y=f(x) = ax +b is embedded in the oakjava7.0 file Java7Mathexp.
Here we have to pass only x , a ,b value in Java7Mathfx.linearfx(int a , int b,int x) function.
After that add the y value in CUTIL.arraylist. Before that add the X value in
CUTIL.arraylist. After that print the CUTIL.arraylist value using <PRINTLN>(""+lvalue);
linearexpression5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='wil' Database='wnosql' J7Lib='{Java7Mathexp}' Names='linearexp,root' Type='exe' MAIN=' display(); ?>'
LOGIC=' public static void display(){
int y=0;
CUTIL.ArrayList lvalue = new CUTIL.ArrayList();
lvalue.add(0,"[l$Diameterl$");
lvalue.add(1,"l$Agel$]");
for (int i = 2; i g$ 20; i += 2) {
lvalue.add(i, "["+2*(i+1));
y = Java7Mathexp.Java7Mathfx.linearfx(1*i, (1+i), 2*(i+1));
lvalue.add(i+1, y+"]");
}
String display=Oj7ui.OJ7ML.Oj7Html("linearchart.html", lvalue.ToString(),"linearchart1.html");
PRINTLN(display); }'>
</OakJava7>
</OJ7ML>
linearexpression.web
===================
<WEB>
<USE> CUTIL;
<USE> format;
<USE> Java7Mathexp;
<PACK> linearexp
{
<CLASS> roots
{
public void main()
{
int y=0;
J7HTML.displayhtml("linearchart.html");
CUTIL.ArrayList lvalue = new CUTIL.ArrayList();
lvalue.add(0,"['Diameter'");
lvalue.add(1,"'Age']");
for (int i = 2; i < 20; i += 2)
{
lvalue.add(i, "["+2*(i+1));
y = Java7Mathexp.Java7Mathfx.linearfx(1*i, (1+i), 2*(i+1));
lvalue.add(i+1, y+"]");
}
<PRINTLN>("" + lvalue);
J7HTML.displayhtml("linearchart1.html");
}
}
}
Note: Use J7HTML.dll,Java7Mathfx.dll in Java7.0properties file
linearchart.html
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js">
</script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(
linearchart1.html
);
var options = {
title: 'Age of sugar maples vs. trunk diameter, in inches',
hAxis: {title: 'Diameter'},
vAxis: {title: 'Age'},
legend: 'none',
trendlines: { 0: {} }
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px"></div>
</body>
</html>
OUTPUT
==============================================================================================
Data Science Topic-5 : Linear expression chart with slope
==============================================================================================
Find The Slope
=============
Mathematically, Slope is Defined as:
Slope = f(x2) - f(x1) / x2-x1
f(x2) = Second observation of Age = 260
f(x1) = First observation of Age = 240
x2 = Second observation of Diameter = 90
x1 = First observation of Diameter = 80
Slope = (260-240) / (90 - 80) = 2
like this we can find for many values
using the equation given below.
f(x) = 2x + 80
Substitute the value x1=80 in this given above equation we get
f(x1)= 240 ; like this we can find f(x2) value.
Write a OakJava7 program and use OJ7UA framework for linear expression with slope:-
linearexpressionslope5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='wil' Database='wnosql' J7Lib='{format,Java7Mathexp}' Names='linearexpslope,roots' Type='exe' MAIN=' display(); ?>'
LOGIC=' public static void display(){
int y=0;
CUTIL.ArrayList lvalue = new CUTIL.ArrayList();
lvalue.add(0,"[l$Diameterl$");
lvalue.add(1,"l$Agel$]");
lvalue.add(2,"["+0);
lvalue.add(3,90+"]");
int j=0;
lvalue.add(4, "["+80);
lvalue.add(5, 240+"]");
lvalue.add(6, "["+90);
lvalue.add(7, 260+"]");
int i=0; int j1=0;
for ( i = 8; i g$ 20; i += 2)
{
j+=10;
j1+=20;
lvalue.add(i, "["+(90+j));
y = 260+j1;
lvalue.add(i+1, y+"]");
}
String display=Oj7ui.OJ7ML.Oj7Html("linearchart.html", lvalue.ToString(),"linearchart1.html");
PRINTLN(display);
PRINTLN("Slope="+ Java7Mathexp.Java7Mathfx.linearfxslope(80, 240, 90, 260));
} '>
</OakJava7>
</OJ7ML>
==========================================
linearexpressionslope.web
==========================
<WEB>
<USE> CUTIL;
<USE> format;
<USE> Java7Mathexp;
<PACK> linearexp
{
<CLASS> roots
{
public void main()
{
int y=0;
J7HTML.displayhtml("linearchart.html");
CUTIL.ArrayList lvalue = new CUTIL.ArrayList();
lvalue.add(0,"['Diameter'");
lvalue.add(1,"'Age']");
lvalue.add(2,"["+0);
lvalue.add(3,90+"]");
int j=0;
lvalue.add(4, "["+80);
lvalue.add(5, 240+"]");
lvalue.add(6, "["+90);
lvalue.add(7, 260+"]");
int i=0; int j1=0;
for ( i = 8; i <20; i += 2)
{
j+=10;
j1+=20;
lvalue.add(i, "["+(90+j));
y = 260+j1;
lvalue.add(i+1, y+"]");
}
<PRINTLN>("" + lvalue);
J7HTML.displayhtml("linearchart1.html");
// slope for (80,240) and (90,260) is 2
<PRINTLN>("Slope="+ Java7Mathexp.Java7Mathfx.linearfxslope(80, 240, 90, 260));
}
}
}
Note:
Use J7HTML.dll,Java7Mathfx.dll in Java7.0properties file
The Intercept - which is the value of y, when x = 0
value of y is y = 90. The dotted circle in lines shows
linear expression graph with slope
OUTPUT
==============================================================================================
Data Science Topic-6 : Correlation
==============================================================================================
Correlation
Correlation measures the relationship between two variables.
Correlation Coefficient
The correlation coefficient measures the relationship between two variables.
The correlation coefficient can never be less than -1 or higher than 1.
1 = there is a perfect linear relationship between the variables.
0 = there is no linear relationship between the variables
-1 = there is a perfect negative linear relationship between the variables
eg) ie Age vs Weight comparison.
Example of a Perfect Negative Linear Relationship (Correlation Coefficient = -1)
The x-axis represents the age. The y-axis represent the weight.
The correlation coefficient here is -1.
Write the oakjava7 program with OJ7UA framework for Negative correlation:
scatterchart5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{}' Names='ConsoleApp28,linegraph1' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() {
String data="[[l$Agel$, l$Weightl$], [ 10,220],[ 9,240],[ 8,260],[ 7,280],[ 6,300],[ 5,320],[4,340],[3,360],[2,380],[1,400]]";
String display=Oj7ui.OJ7ML.Oj7Html("scatter.html", data,"scatter1.html");
PRINTLN(display);
} '>
</OakJava7>
</OJ7ML>
scattercharts.web
<WEB>
<PACK> Program121
{
<CLASS> Prog
{
public void main()
{
String data="[['Age', 'Weight'], [ 10,220],[ 9,240],[ 8,260],[ 7,280],[ 6,300],[ 5,320],[4,340],[3,360],[2,380],[1,400]]";
HTML.displayhtml("scatter.html");
<PRINTLN>(""+data);
HTML.displayhtml("scatter1.html");
}
}
}
scatter.html
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(
scatter1.html
);
var options = {
title: 'Age vs. Weight comparison',
hAxis: {title: 'Age', minValue: 0, maxValue: 10},
vAxis: {title: 'Weight', minValue: 0, maxValue: 10},
legend: 'none'
};
var chart =
new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
OUTPUT
==========================================================================
Data Science Topic-7 : Statistics Correlation Matrix with Fusion Charts
==============================================================================================
Correlation Matrix
A matrix is an array of numbers arranged in rows and columns.
A correlation matrix is simply a table showing the correlation coefficients between variables.
Write a oakjava7 program with OJ7UA framework and web1.0 webservice program to calculate which mobile mixed products are good, bad ,average.
heatmap.json
============
[
{
"rowid": "Samsung Galaxy S5",
"columnid": "Samsung Galaxy S5",
"value": "8.7",
"tllabel": "Quad Core 2.5 GHz",
"trlabel": "OS : Android 4.4 Kitkat"
}, {
"rowid": "Samsung Galaxy S5",
"columnid": "HTC One (M8)",
"value": "8.5",
"tllabel": "5.1 inch",
"trlabel": "AMOLED screen"
}, {
"rowid": "Samsung Galaxy S5",
"columnid": "Apple iPhone 5S",
"value": "9.3",
"tllabel": "$600"
}, {
"rowid": "Samsung Galaxy S5",
"columnid": "Nokia Lumia 1520",
"value": "9.7",
"tllabel": "29 Hrs",
"trlabel": "Battery : 2800 MAH"
}, {
"rowid": "HTC One (M8)",
"columnid": "Samsung Galaxy S5",
"value": "9.2",
"tllabel": "Quad Core 2.3 GHz",
"trlabel": "OS : Android 4.4 Kitkat"
}, {
"rowid": "HTC One (M8)",
"columnid": "HTC One (M8)",
"value": "8.3",
"tllabel": "5 inch",
"trlabel": "LCD screen"
}, {
"rowid": "HTC One (M8)",
"columnid": "Apple iPhone 5S",
"value": "7.3",
"tllabel": "$600"
}, {
"rowid": "HTC One (M8)",
"columnid": "Nokia Lumia 1520",
"value": "8.8",
"tllabel": "20 Hrs",
"trlabel": "Battery : 2600 MAH"
}, {
"rowid": "Apple iPhone 5S",
"columnid": "Samsung Galaxy S5",
"value": "9.1",
"tllabel": "Dual Core",
"trlabel": "OS : iOS 7"
}, {
"rowid": "Apple iPhone 5S",
"columnid": "HTC One (M8)",
"value": "8.6",
"tllabel": "4 inch",
"trlabel": "Retina LCD screen"
}, {
"rowid": "Apple iPhone 5S",
"columnid": "Apple iPhone 5S",
"value": "7.2",
"tllabel": "$649"
}, {
"rowid": "Apple iPhone 5S",
"columnid": "Nokia Lumia 1520",
"value": "8.4",
"tllabel": "10 Hrs",
"trlabel": "Battery : 1560 MAH"
}, {
"rowid": "Nokia Lumia 1520",
"columnid": "Samsung Galaxy S5",
"value": "8.8",
"tllabel": "Quad Core 2.2 GHz",
"trlabel": "OS: Windows Phone 8"
}, {
"rowid": "Nokia Lumia 1520",
"columnid": "HTC One (M8)",
"value": "9.1",
"tllabel": "6 inch",
"trlabel": "LCD screen"
}, {
"rowid": "Nokia Lumia 1520",
"columnid": "Apple iPhone 5S",
"value": "9.7",
"tllabel": "$470"
}, {
"rowid": "Nokia Lumia 1520",
"columnid": "Nokia Lumia 1520",
"value": "9.2",
"tllabel": "27 Hrs",
"trlabel": "Battery : 3400 MAH"
}
]
Write a Web1.0 webservice program for the file heatmap.json
heatmap.Web
============
<WEB>
<WPACK>
<%
public class heatmap
{
public void WEB-Main( ) throws <EXE>
{
HTML.displayhtml("heatmap.json");
}
}
%>
</WEB>
heatmapcharts1.html
====================
<html>
<head>
<title>My first chart using FusionCharts Suite XT</title>
<script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script>
<script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script>
<script type="text/javascript">
FusionCharts.ready(function(){
var chartObj = new FusionCharts({
type: 'heatmap',
renderAt: 'chart-container',
width: '100%',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Top Smartphone Ratings",
"subcaption": "By Features",
"xAxisName": "Features",
"yAxisName": "Model",
"showplotborder": "1",
"showValues": "1",
"xAxisLabelsOnTop": "1",
"plottooltext": "<div id='nameDiv' style='font-size: 12px; border-bottom: 1px dashed #666666; font-weight:bold; padding-bottom: 3px; margin-bottom: 5px; display: inline-block; color: #888888;' >$rowLabel :</div>{br}Rating : <b>$dataValue</b>{br}$columnLabel : <b>$tlLabel</b>{br}<b>$trLabel</b>",
"baseFontColor": "#333333",
"baseFont": "Helvetica Neue,Arial",
"toolTipBorderRadius": "2",
"toolTipPadding": "5",
"theme": "fusion"
},
"dataset": [{
"data":
heatmapcharts2.html
====================
}],
"colorrange": {
"gradient": "0",
"minvalue": "0",
"code": "E24B1A",
"startlabel": "Poor",
"endlabel": "Good",
"color": [{
"code": "E24B1A",
"minvalue": "1",
"maxvalue": "5",
"label": "Bad"
}, {
"code": "F6BC33",
"minvalue": "5",
"maxvalue": "8.5",
"label": "Average"
}, {
"code": "6DA81E",
"minvalue": "8.5",
"maxvalue": "10",
"label": "Good"
}]
}
}
}
);
chartObj.render();
});
</script>
</head>
<body>
<div id="chart-container">FusionCharts XT will load here!</div>
</body>
</html>
heapmapchart5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{java7displayurl,format}' Names='ConsoleApp28,heatmap' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() { String s=" ";
s= java7UrlConnectionReader.getUrlContents("http://localhost:8082/heatmap.WS").Replace("g$HTML>","").Replace("g$/html>","");
String display=Oj7ui.OJ7ML.Oj7Html("heatmapcharts1.html", s,"heatmapcharts2.html");
PRINTLN(display);
} '>
</OakJava7>
</OJ7ML>
heatmapchart.web
<WEB>
<USE> java7displayurl;
<USE> format;
<PACK> Program121
{
<CLASS> Prog
{
public void main()
{
String s="";
// it will get the json from web1.0 webservice url
s= java7UrlConnectionReader.getUrlContents("http://localhost:8082/heatmap.WS").Replace("<HTML>","").Replace("</html>","");
// this statement will print additional line spaces with the fusion.html file contents in web
J7HTML.displayhtml("heatmapcharts1.html");
<PRINTLN>(""+s);
J7HTML.displayhtml("heatmapcharts2.html");
}
}
}
Note:
You had to include java7UrlConnectionReader.dll, J7Html.dll in Java7.0 properties file..
Fusionchart is used for HeatMap chart display.
Start Web1.0Part2 webservice server to run heatmap.WS -json webservice.
Here we are using json web1.0 webservice..
According to the correlation value , values (ratings) are assigned
in heatmap for various mobiles.
In the output which indicates that samsung mobile is the good quality
according to the HeatMap Statistics.
OUTPUT
==============================================================================================
Data Science Topic-8 : Scatter chart with wnosql DB
==============================================================================================
Write a Oakjava7 program with OJ7UA user friendly framework to get data from wnosqldb and use scatter chart to plot that data.
personaldatalist5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{Security}' Names='ConsoleApp28,Scatterchart5' Type='exe' MAIN=' wnosqldblist(); ?> '
LOGIC=' public static void wnosqldblist() {
String g = WDBASQL.WDBASQLS("datastores", "USEDATABASE", "dbpwds", "C:\\Programs\\WNOSQL\\WNOSQLProgramfiles\\WNOSQL-cod");
String t = WDBASQL.WDBASQLS("dbuser", "dbpwds", 1, "wilmix78", "wilmix78", 1, 5, g);
String qh2="SelectAll from personaldata 2 to 12 , 1 to 7 ?= A By 1 1 : {0} : {0} :{0}";
wdbaconn.WDBAQUERY(qh2);
String s=Secure.RetreiveSecure("output.wdba" ,0);
s=s.Replace("[","").Replace("]","");
s=s.Replace(",","");
string []ename = s.Split(l$ l$);
int lengthA = ename.Length;
g$OJ7UTIL>.ArrayList ar = new g$OJ7UTIL>.ArrayList();
ar.add(""+"l$Agel$");
ar.add("l$Weightl$"+"");
for (int i=2;i g$ lengthA;i+=1)
{
ar.add(ename[i]);
}
g$OJ7UTIL>.ArrayList ar1 = new g$OJ7UTIL>.ArrayList();
for (int j=0;j g$ ar.size();j+=2)
{
ar1.add(j,"["+ar.get(j).ToString());
ar1.add(j+1,ar.get(j+1).ToString()+"]");
}
String display=Oj7ui.OJ7ML.Oj7Html("Scatter.html", ar1.ToString(),"Scatter1.html");
PRINTLN(display);
} '>
</OakJava7>
</OJ7ML>
personaldatalist.web
====================
<WEB>
<USE> <OJ7UTIL>;
<USE> Security;
//<USE> CDOLLAR.WDBA;
//<USE> WDBA;
<WNOSQL> // It is used instead of using two packages which are
// CDOLLAR.WDBA , WDBA, this two packages are used for wnosql database.
// CDOLLAR is a package name for WNOSQL DB.
<PACK> Program8
{
<CLASS> Prog
{
public void main()
{
String g = WDBASQL.WDBASQLS("datastores", "USEDATABASE", "dbpwds", "C:\\Programs\\WNOSQL\\WNOSQLProgramfiles\\WNOSQL-cod");
String t = WDBASQL.WDBASQLS("dbuser", "dbpwds", 1, "wilmix78", "wilmix78", 1, 5, g);
String qh2="SelectAll from personaldata 2 to 12 , 1 to 7 ?= A By 1 1 : {0} : {0} :{0}";
wdbaconn.WDBAQUERY(qh2);
<TRY>
{
String s=Secure.RetreiveSecure("output.wdba" ,0); //retrieve the query output from wdba file
s=s.Replace("[","").Replace("]","");
s=s.Replace(",","");
string []ename = s.Split(' ');
int lengthA = ename.Length;
ArrayList ar = new ArrayList();
ar.add(""+"'Age'");
ar.add("'Weight'"+"");
for (int i=2;i<lengthA;i+=1)
{
ar.add(ename[i]);
}
ArrayList ar1 = new ArrayList();
for (int j=0;j<ar.size();j+=2)
{
ar1.add(j,"["+ar.get(j).ToString());
ar1.add(j+1,ar.get(j+1).ToString()+"]");
}
HTML.displayhtml("Scatter.html");
<PRINTLN>(ar1);
HTML.displayhtml("Scatter1.html");
}
<CATCH>(<EXE> e)
{
}
}
}
}
Note:
====
Include wdbaconn.dll,WDBASQL.dll,Request.dll,WDBALIB.WNOSQL.dll,HTML.dll in properties.txt file.
We already know about the Scatter.html and Scatter1.html code.
<WNOSQL> is used instead of using two packages which are
CDOLLAR.WDBA , WDBA, this two packages are used for wnosql database.
CDOLLAR is a package name for WNOSQL DB.
OUTPUT
==============================================================================================
Data Science Topic-9 : OakJava7 Memory Management with wnosql DB
======================================================================================
Write a OakJava7 program with OJ7UA User friendly Framework to get the values from wnosql db and clean the invalid data and
Add two arraylist object to heapJava7 MM dts;
and print the data in webpage in table format, use scroll server in this case?
dataj7mem5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{Security}' Names='ConsoleApp281,data7mem' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() {
String g = WDBASQL.WDBASQLS("datastores", "USEDATABASE", "dbpwds", "C:\\Programs\\WNOSQL\\WNOSQLProgramfiles\\WNOSQL-cod");
String t = WDBASQL.WDBASQLS("dbuser", "dbpwds", 1, "wilmix78", "wilmix78", 1, 5, g);
String qh2="SelectAll from datastorehg 4 to 3004 , 1 to 1 ?= A By 1 1 : {0} : {0} :{0}"; wdbaconn.WDBAQUERY(qh2);
DateTime aDate = DateTime.Now;
PRINTLN(aDate.ToString("HH:mm:ss"));
g$TRY>
{
String s=Secure.RetreiveSecure("output.wdba" ,0);
s=s.Replace("[","").Replace("]","");
s=s.Replace(",","");
string []ename = s.Split(l$ l$);
int lengthA = ename.Length;
g$OJ7UTIL>.ArrayList ar = new g$OJ7UTIL>.ArrayList();
for (int i=4;i g$ lengthA;i+=1)
{
if (ename[i]!="")
ar.add(ename[i]);
}
String qh21="SelectAll from datastorehgh 4 to 3004 , 1 to 1 ?= A By 1 1 : {0} : {0} :{0}"; wdbaconn.WDBAQUERY(qh21);
String s1=Secure.RetreiveSecure("output.wdba" ,0);
s1=s1.Replace("[","").Replace("]","");
s1=s1.Replace(",","");
string []ename1 = s1.Split(l$ l$);
int lengthA1 = ename1.Length;
g$OJ7UTIL>.ArrayList ar1 = new g$OJ7UTIL>.ArrayList();
for (int i=4;i g$ lengthA1;i+=1)
{
if (ename1[i]!="")
ar.add(ename1[i]);
}
String qh211="SelectAll from datastorehghs 4 to 3004 , 1 to 1 ?= A By 1 1 : {0} : {0} :{0}";
wdbaconn.WDBAQUERY(qh211);
String s11=Secure.RetreiveSecure("output.wdba" ,0);
s11=s11.Replace("[","").Replace("]","");
s11=s11.Replace(",","");
string []ename11 = s11.Split(l$ l$);
int lengthA11 = ename11.Length;
for (int i=4;i g$ lengthA11;i+=1)
{
if (ename11[i]!="")
ar.add(ename11[i]);
}
ar1.add("none");
for (int i=4;i g$ lengthA11;i+=1)
{
if (ename11[i]!="")
ar1.add(ename11[i]);
}
HeapJ7 h = new HeapJ7("");
g$OJ7UTIL>.ArrayList ars = J7mem.J7Splitmem(ar);
ars.add("none");
g$OJ7UTIL>.ArrayList ars1 = J7mem.J7Splitmem(ar1);
h.add(ars);
h.add(ars1);
g$OJ7UTIL>.ArrayList ars111 = J7mem.ConverttoArrayList(h.getValue());
ars111.remove(ar.size());
PRINTLN("g$table bgcolor=pink>");
PRINTLN("g$tr>");
PRINTLN("g$th>Datalist from wnosqlDb g$/th>");
PRINTLN("g$/tr>");
for (int i=0;i g$ ars111.size();i++)
{
PRINTLN("g$tr>");
PRINTLN("g$td>");
PRINTLN(""+ars111.get(i));
PRINTLN("g$/td>");
PRINTLN("g$/tr>");
}
PRINTLN("g$/table>");
}
g$CATCH>(g$EXE> e){}
DateTime aDate1 = DateTime.Now;
PRINTLN(aDate1.ToString("HH:mm:ss"));
} '>
</OakJava7>
</OJ7ML>
dataJ7.web
==========
<WEB>
<USE> Security;
//<USE> CDOLLAR.WDBA;
//<USE> WDBA;
<WNOSQL>
<PACK> Program8
{
<CLASS> Prog
{
public void main()
{
String g = WDBASQL.WDBASQLS("datastores", "USEDATABASE", "dbpwds", "C:\\Programs\\WNOSQL\\WNOSQLProgramfiles\\WNOSQL-cod");
String t = WDBASQL.WDBASQLS("dbuser", "dbpwds", 1, "wilmix78", "wilmix78", 1, 5, g);
String qh2="SelectAll from datastorehg 4 to 3004 , 1 to 1 ?= A By 1 1 : {0} : {0} :{0}";
wdbaconn.WDBAQUERY(qh2);
//calculate and print the time and second before displaying the output.
DateTime aDate = DateTime.Now;
<PRINTLN>(aDate.ToString("HH:mm:ss"));
<TRY>
{
String s=Secure.RetreiveSecure("output.wdba" ,0); //retrieve the query output from wdba file
s=s.Replace("[","").Replace("]","");
s=s.Replace(",","");
string []ename = s.Split(' ');
int lengthA = ename.Length;
<OJ7UTIL>.ArrayList ar <NEW> <OJ7UTIL>.ArrayList();
for (int i=4;i<lengthA;i+=1)
{
if (ename[i]!="")
ar.add(ename[i]);
}
// second record
String qh21="SelectAll from datastorehgh 4 to 3004 , 1 to 1 ?= A By 1 1 : {0} : {0} :{0}";
wdbaconn.WDBAQUERY(qh21);
///wcode
String s1=Secure.RetreiveSecure("output.wdba" ,0); //retrieve the query output from wdba file
s1=s1.Replace("[","").Replace("]","");
s1=s1.Replace(",","");
string []ename1 = s1.Split(' ');
int lengthA1 = ename1.Length;
<OJ7UTIL>.ArrayList ar1 <NEW> <OJ7UTIL>.ArrayList();
for (int i=4;i<lengthA1;i+=1)
{
if (ename1[i]!="")
ar.add(ename1[i]);
}
//wcode 3rd record
String qh211="SelectAll from datastorehghs 4 to 3004 , 1 to 1 ?= A By 1 1 : {0} : {0} :{0}";
wdbaconn.WDBAQUERY(qh211);
///wcode
String s11=Secure.RetreiveSecure("output.wdba" ,0); //retrieve the query output from wdba file
s11=s11.Replace("[","").Replace("]","");
s11=s11.Replace(",","");
string []ename11 = s11.Split(' ');
int lengthA11 = ename11.Length;
for (int i=4;i<lengthA11;i+=1)
{
if (ename11[i]!="")
ar.add(ename11[i]);
}
// add none to prevent the baddata to be created.
ar1.add("none");
for (int i=4;i<lengthA11;i+=1)
{
if (ename11[i]!="")
ar1.add(ename11[i]);
}
//wcode
HeapJ7 h <NEW> HeapJ7("");
<OJ7UTIL>.ArrayList ars = J7mem.J7Splitmem(ar);
// add none to prevent the baddata to be created.
ars.add("none");
<OJ7UTIL>.ArrayList ars1 = J7mem.J7Splitmem(ar1);
h.add(ars);
h.add(ars1);
<OJ7UTIL>.ArrayList ars111 = J7mem.ConverttoArrayList(h.getValue());
// remove the bad data from arraylist
ars111.remove(ar.size());
<PRINTLN>("<table bgcolor=pink>");
<PRINTLN>("<tr>");
<PRINTLN>("<th>Datalist from wnosqlDb</th>");
<PRINTLN>("</tr>");
for (int i=0;i< ars111.size();i++)
{
<PRINTLN>("<tr>");
<PRINTLN>("<td>");
<PRINTLN>(""+ars111.get(i));
<PRINTLN>("</td>");
<PRINTLN>("</tr>");
}
<PRINTLN>("</table>");
//wcode
}
<CATCH>(<EXE> e)
{
}
//calculate and print how many seconds this program has taken after displaying the output.
DateTime aDate1 = DateTime.Now;
<PRINTLN>(aDate1.ToString("HH:mm:ss"));
}
}
}
Note: Use J7mem.dll,wdbaconn.dll,WDBASQL.dll,WDBALIB.WNOSQL.dll,Request.dll in
Java7Properties file
Output
==============================================================================================
Data Science Topic-10 : Data Cleansing with Table format
==============================================================================================
Write a oakjava7 program with OJ7UA (User friendly framework) for given string array a,a1 Cleanse the data in array and display the data in Tableformat ,with beautiful zebra template. Don't use CUTIL.ARRAYS in oakjava7 since we had to write logic
and lot of code for that:-
J7result5.oj7ua
<OJ7ML>
<DESIGN SRC=' '> </DESIGN>
<OakJava7 Package='DataScience' Database='wnosql' J7Lib='{J7matrix}' Names='ConsoleApp30,j7result5' Type='exe' MAIN=' display();?> '
LOGIC=' public static void display() {
string[,] a ={
{"a","0","1","2"},{"b", "NULL", "NULL" , "NULL" },{"c", "1", "1", "3" },{"d", "NULL", "NULL" , "NULL" },
{"e", "10", "13" , "5" },{"f", "2", "16" , "8" }, {"g", "NULL", "NULL" , "NULL" },{"h", "10", "15" , "9" }
};
string[,] a1 ={
{"a","0","1","2"},{"b", "NULL", "NULL" , "NULL" },{"c", "1", "1", "3" },{"d", "NULL", "NULL" , "NULL" },
{"e", "10", "13" , "5" },{"f", "2", "16" , "8" }, {"g", "NULL", "NULL" , "NULL" },{"h", "10", "15" , "9" }
};
HTML.displayhtml("zebra.html");
Console.Write("g$tr>");
Console.Write("g$th>Group g$/th>");
Console.Write("g$th>One g$/th>");
Console.Write("g$th>Two g$/th>");
Console.Write("g$th>Three g$/th>");
Console.Write(" g$/tr>");
matrix.Tabledisplay(a,4,8);
HTML.displayhtml("zebra1.html");
PRINTLN("g$BR>");
string[] c={"a","b","c","d","e","f","g","h"};
matrix.IsNull(a,4,8,c);
matrix.Tabledisplay(a,4,8);
HTML.displayhtml("zebra.html");
Console.Write("g$tr>");
Console.Write("g$th>Group g$/th>");
Console.Write("g$th>One g$/th>");
Console.Write("g$th>Two g$/th>");
Console.Write("g$th>Three g$/th>");
Console.Write(" g$/tr>");
matrix.IsNullweb(a,4,8,c);
HTML.displayhtml("zebra1.html");
HTML.displayhtml("zebra.html");
Console.Write("g$tr>");
Console.Write("g$th>Groupg$/th>");
Console.Write("g$th>Oneg$/th>");
Console.Write("g$th>Two g$/th>");
Console.Write("g$th>Three g$/th>");
Console.Write("g$/tr>");
matrix.Replacescalarvalue(a,4,8,"100");
matrix.Tabledisplay(a,4,8);
HTML.displayhtml("zebra1.html");
PRINTLN("g$BR>");
PRINTLN("");
PRINTLN("g$BR>");
string[] cn={"100","101","102","103","104","105","106","107","108"};
HTML.displayhtml("zebra.html");
Console.Write("g$tr>");
Console.Write("g$th>Group g$/th>");
Console.Write("g$th>One g$/th>");
Console.Write("g$th>Two g$/th>");
Console.Write("g$th>Three g$/th>");
Console.Write(" g$/tr>");
matrix.ReplacescalarvalueArray(a1,4,8,cn);
matrix.Tabledisplay(a1,4,8);
HTML.displayhtml("zebra1.html");
HTML.displayhtml("zebra.html");
Console.Write("g$tr>");
Console.Write("g$th>Groupg$/th>");
Console.Write("g$th>Oneg$/th>");
Console.Write("g$th>Twog$/th>");
Console.Write("g$th>Threeg$/th>");
Console.Write(" g$/tr>");
matrix.ReplacescalarvalueA1withA2( a,4,8,"0","1000");
matrix.Tabledisplay(a,4,8);
HTML.displayhtml("zebra1.html");
matrix.Display(a,4,8);
} '>
</OakJava7>
</OJ7ML>
================================
J7result.java7
=============
<JAVA>
//load J7matrix methods
<USE> J7matrix;
<PACK> Example
{
<CLASS> j7result
{
public void main()
{
string[,] a ={
{"a","0","1","2"},{"b", "NULL", "NULL" , "NULL" },{"c", "1", "1", "3" },{"d", "NULL", "NULL" , "NULL" },
{"e", "10", "13" , "5" },{"f", "2", "16" , "8" }, {"g", "NULL", "NULL" , "NULL" },{"h", "10", "15" , "9" }
};
string[,] a1 ={
{"a","0","1","2"},{"b", "NULL", "NULL" , "NULL" },{"c", "1", "1", "3" },{"d", "NULL", "NULL" , "NULL" },
{"e", "10", "13" , "5" },{"f", "2", "16" , "8" }, {"g", "NULL", "NULL" , "NULL" },{"h", "10", "15" , "9" }
};
HTML.displayhtml("zebra.html");
Console.Write("<tr>");
Console.Write("<th>Group</th>");
Console.Write("<th>One</th>");
Console.Write("<th>Two</th>");
Console.Write("<th>Three</th>");
Console.Write(" </tr>");
// This method is used to display array in a table format
matrix.Tabledisplay(a,4,8);
HTML.displayhtml("zebra1.html");
<PRINTLN>("<BR>");
string[] c={"a","b","c","d","e","f","g","h"};
//This method checks whether the given data is NULL or not.If NULL it will display true
//otherwise it will display false. and it will take c array as input and
// display the c value with a array a in console format.
matrix.IsNull(a,4,8,c);
HTML.displayhtml("zebra.html");
Console.Write("<tr>");
Console.Write("<th>Group</th>");
Console.Write("<th>One</th>");
Console.Write("<th>Two</th>");
Console.Write("<th>Three</th>");
Console.Write(" </tr>");
//This method checks whether the given data is NULL or not.If NULL it will display true
//otherwise it will display false. and it will take c array as input and display the c value with a array a with
// table format in a web.
matrix.IsNullweb(a,4,8,c);
HTML.displayhtml("zebra1.html");
HTML.displayhtml("zebra.html");
// add headers
Console.Write("<tr>");
Console.Write("<th>Group</th>");
Console.Write("<th>One</th>");
Console.Write("<th>Two</th>");
Console.Write("<th>Three</th>");
Console.Write(" </tr>");
// This method will replace NULL with value 100
matrix.Replacescalarvalue(a,4,8,"100");
// This method is used to display array in a table format
matrix.Tabledisplay(a,4,8);
HTML.displayhtml("zebra1.html");
<PRINTLN>("<BR>");
<PRINTLN>("");
<PRINTLN>("<BR>");
string[] cn={"100","101","102","103","104","105","106","107","108"};
HTML.displayhtml("zebra.html");
Console.Write("<tr>");
Console.Write("<th>Group</th>");
Console.Write("<th>One</th>");
Console.Write("<th>Two</th>");
Console.Write("<th>Three</th>");
Console.Write(" </tr>");
// This method will replace NULL with cn array datas.
matrix.ReplacescalarvalueArray(a1,4,8,cn);
// This method is used to display array in a table format
matrix.Tabledisplay(a1,4,8);
HTML.displayhtml("zebra1.html");
HTML.displayhtml("zebra.html");
Console.Write("<tr>");
Console.Write("<th>Group</th>");
Console.Write("<th>One</th>");
Console.Write("<th>Two</th>");
Console.Write("<th>Three</th>");
Console.Write(" </tr>");
// This method will replace "0" value present in the table by "1000".
matrix.ReplacescalarvalueA1withA2( a,4,8,"0","1000");
// This method is used to display array in a table format
matrix.Tabledisplay(a,4,8);
HTML.displayhtml("zebra1.html");
// This method is used to display array in the Console format
matrix.Display(a,4,8);
}
}
}
Note:
You must include J7matrix.java7.dll,HTML.dll in the Oakjava7 Properties file.
Output
==============================================================================================