Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97150395
Histogram.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jan 2, 23:12
Size
6 KB
Mime Type
text/x-java
Expires
Sat, Jan 4, 23:12 (2 d)
Engine
blob
Format
Raw Data
Handle
23338371
Attached To
R3229 Genome Privacy - SHCS App
Histogram.java
View Options
package
com.example.genomicprivacy
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
org.achartengine.ChartFactory
;
import
org.achartengine.GraphicalView
;
import
org.achartengine.chart.BarChart.Type
;
import
org.achartengine.chart.PointStyle
;
import
org.achartengine.model.XYMultipleSeriesDataset
;
import
org.achartengine.model.XYSeries
;
import
org.achartengine.renderer.XYMultipleSeriesRenderer
;
import
org.achartengine.renderer.XYSeriesRenderer
;
import
FrameWork.DBconnector_mu
;
import
android.app.ActionBar
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.graphics.Paint.Align
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.view.MenuItem
;
import
android.widget.LinearLayout
;
/**
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
public
class
Histogram
extends
Activity
{
/**
* Chart
*/
private
GraphicalView
mChart
;
/**
* result of the patient on which we perform the test
*/
private
double
result
=
ContextApp
.
getResult12
();
/**
* Stats
*/
private
ArrayList
[]
stats
=
null
;
/**
* number of patient
*/
private
ArrayList
<
Integer
>
nbPatient
=
null
;
/**
* AllRequest
*/
private
ArrayList
<
Double
>
allResults
=
null
;
/**
* all the statistics
*/
private
double
[]
x_results
=
null
;
/**
* Number of time a patient has the same susceptibility
*/
private
double
[]
y_patients
=
null
;
/**
* ID_p
*/
private
int
id_p
=
0
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
histo_bar
);
Intent
intent
=
getIntent
();
id_p
=
intent
.
getIntExtra
(
"id_p"
,
0
);
result
=
57
;
new
getStats
().
execute
();
ActionBar
actionBar
=
getActionBar
();
actionBar
.
setDisplayHomeAsUpEnabled
(
true
);
// OpenChart();
}
public
boolean
onOptionsItemSelected
(
MenuItem
item
){
finish
();
return
true
;
}
/**
* Show histogram.
*/
public
class
getStats
extends
AsyncTask
<
Void
,
Void
,
Void
>
{
@Override
protected
Void
doInBackground
(
Void
...
params
)
{
try
{
stats
=
DBconnector_mu
.
getStats
(
12
);
}
catch
(
SQLException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
result
)
{
// TODO Auto-generated method stub
super
.
onPostExecute
(
result
);
double
[]
XAxis
=
new
double
[
21
];
int
index
=
0
;
double
max
=
0
;
for
(
int
i
=
0
;
i
<
XAxis
.
length
;
i
++)
{
XAxis
[
i
]
=
index
;
index
+=
5
;
}
allResults
=
stats
[
0
];
nbPatient
=
stats
[
1
];
x_results
=
new
double
[
allResults
.
size
()];
y_patients
=
new
double
[
nbPatient
.
size
()];
for
(
int
i
=
0
;
i
<
allResults
.
size
();
i
++)
{
x_results
[
i
]
=
allResults
.
get
(
i
);
y_patients
[
i
]
=
(
double
)
nbPatient
.
get
(
i
);
}
// Create XY Series for X Series.
XYSeries
xSeries
=
new
XYSeries
(
"Number of persons"
);
XYSeries
resultPatient
=
new
XYSeries
(
"Patient "
+
id_p
+
", result: "
+
Histogram
.
this
.
result
);
// Adding data to the X Series every 5 unit
ArrayList
<
Double
>
c
=
new
ArrayList
<
Double
>();
for
(
int
i
=
0
;
i
<
x_results
.
length
;
i
++)
{
int
modulo
=
(
int
)
(
x_results
[
i
]
%
5
);
if
(
modulo
<
3
)
{
x_results
[
i
]
=
x_results
[
i
]
-
modulo
;
}
else
{
x_results
[
i
]
=
x_results
[
i
]
-
modulo
+
5
;
}
}
//For the x result we delete the doublon and for each x we map it to number of time it appears.
HashMap
<
Double
,
Double
>
mappingXY
=
new
HashMap
<
Double
,
Double
>();
for
(
int
i
=
0
;
i
<
x_results
.
length
;
i
++)
{
if
(
mappingXY
.
containsKey
(
x_results
[
i
]))
{
mappingXY
.
put
(
x_results
[
i
],
mappingXY
.
get
(
x_results
[
i
])
+
1
);
if
(
mappingXY
.
get
(
x_results
[
i
])>
max
){
max
=
mappingXY
.
get
(
x_results
[
i
]);
}
}
else
{
mappingXY
.
put
(
x_results
[
i
],
1.0
);
}
}
for
(
int
i
=
0
;
i
<
mappingXY
.
size
();
i
++)
{
xSeries
.
add
(
x_results
[
i
],
mappingXY
.
get
(
x_results
[
i
]));
}
// Create a Dataset to hold the XSeries.
XYMultipleSeriesDataset
dataset
=
new
XYMultipleSeriesDataset
();
resultPatient
.
add
(
Histogram
.
this
.
result
,
max
);
// Add X series to the Dataset.
dataset
.
addSeries
(
xSeries
);
dataset
.
addSeries
(
resultPatient
);
// Create XYSeriesRenderer to customize XSeries
XYSeriesRenderer
Xrenderer
=
new
XYSeriesRenderer
();
Xrenderer
.
setColor
(
Color
.
RED
);
Xrenderer
.
setPointStyle
(
PointStyle
.
DIAMOND
);
Xrenderer
.
setDisplayChartValues
(
false
);
Xrenderer
.
setChartValuesTextSize
(
30
);
Xrenderer
.
setLineWidth
(
20
);
XYSeriesRenderer
ResultRenderer
=
new
XYSeriesRenderer
();
ResultRenderer
.
setColor
(
Color
.
BLUE
);
ResultRenderer
.
setPointStyle
(
PointStyle
.
POINT
);
ResultRenderer
.
setLineWidth
(
1
);
// Create XYMultipleSeriesRenderer to customize the whole chart
XYMultipleSeriesRenderer
mRenderer
=
new
XYMultipleSeriesRenderer
();
mRenderer
.
setChartTitle
(
"Result Vs Number People"
);
mRenderer
.
setChartTitleTextSize
(
50
);
mRenderer
.
setAxisTitleTextSize
(
40
);
mRenderer
.
setAxesColor
(
Color
.
BLACK
);
mRenderer
.
setLabelsColor
(
Color
.
BLACK
);
mRenderer
.
setXTitle
(
"Result in %"
);
mRenderer
.
setGridColor
(
Color
.
BLACK
);
mRenderer
.
setApplyBackgroundColor
(
true
);
mRenderer
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
mRenderer
.
setMarginsColor
(
Color
.
argb
(
0x00
,
0x01
,
0x01
,
0x01
));
mRenderer
.
setXLabels
(
10
);
mRenderer
.
setPanEnabled
(
false
);
mRenderer
.
setBarSpacing
(
0.10
);
mRenderer
.
setLegendTextSize
(
40
);
mRenderer
.
setYAxisMin
(
0
);
mRenderer
.
setXAxisMin
(
0
);
mRenderer
.
setXAxisMax
(
100
);
mRenderer
.
setShowGridX
(
true
);
mRenderer
.
setMargins
(
new
int
[]
{
70
,
50
,
70
,
40
});
mRenderer
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
mRenderer
.
setYLabelsAlign
(
Align
.
LEFT
);
// Adding the XSeriesRenderer to the MultipleRenderer.
mRenderer
.
addSeriesRenderer
(
Xrenderer
);
mRenderer
.
addSeriesRenderer
(
ResultRenderer
);
LinearLayout
chart_container
=
(
LinearLayout
)
findViewById
(
R
.
id
.
Chart_layout
);
chart_container
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
// Creating an intent to plot line chart using dataset and
// multipleRenderer
mChart
=
ChartFactory
.
getBarChartView
(
getApplicationContext
(),
dataset
,
mRenderer
,
Type
.
DEFAULT
);
// Add the graphical view mChart object into the Linear layout .
chart_container
.
addView
(
mChart
);
}
}
}
Event Timeline
Log In to Comment