|
@@ -55,6 +55,11 @@ public class StatisticsFragment extends Fragment {
|
|
|
static final String CHART_TYPE_TITLE_PIE = "Pie Plot";
|
|
|
static final String CHART_TYPE_TITLE_LINE = "Line Plot";
|
|
|
|
|
|
+ static final String OTHER_CHART_TITLE = "Other";
|
|
|
+
|
|
|
+ // MINIMAL 2
|
|
|
+ static int MAX_NUMBER_OF_CHART_OBJECTS = 5;
|
|
|
+
|
|
|
private boolean wasBelowTimePicker;
|
|
|
|
|
|
private LogFilter filter;
|
|
@@ -145,9 +150,39 @@ public class StatisticsFragment extends Fragment {
|
|
|
}
|
|
|
|
|
|
public void configureRootView(View rootView){
|
|
|
- LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
|
|
|
- // DEFAULT
|
|
|
- this.actualiseCurrentPlot();
|
|
|
+ this.setChartType(ChartType.PIE_CHART);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setChartType(ChartType type){
|
|
|
+ boolean shouldChange = true;
|
|
|
+ if (this.currentPlotView != null){
|
|
|
+ if (type == ChartType.PIE_CHART){
|
|
|
+ shouldChange = ! (this.currentPlotView instanceof PieGraph);
|
|
|
+ }
|
|
|
+ if (type == ChartType.LINE_CHART){
|
|
|
+ shouldChange = ! (this.currentPlotView instanceof LineGraph);
|
|
|
+ }
|
|
|
+ if (type == ChartType.BAR_CHART){
|
|
|
+ shouldChange = ! (this.currentPlotView instanceof BarGraph);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (shouldChange){
|
|
|
+ LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
|
|
|
+ this.currentPlotView = this.getPlotViewForType(type);
|
|
|
+ plotLayout.addView(this.currentPlotView);
|
|
|
+ this.actualiseCurrentPlot();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public View getPlotViewForType(ChartType type){
|
|
|
+ switch (type){
|
|
|
+ case PIE_CHART:
|
|
|
+ return this.getPieGraphView();
|
|
|
+ case LINE_CHART:
|
|
|
+ return this.getLineGraphView();
|
|
|
+ default:
|
|
|
+ return this.getBarGraphView();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -174,7 +209,6 @@ public class StatisticsFragment extends Fragment {
|
|
|
public void onClick(int index) {
|
|
|
StatisticsFragment.this.onSliceClick(index);
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
}
|
|
|
/*
|
|
@@ -212,23 +246,28 @@ public class StatisticsFragment extends Fragment {
|
|
|
* */
|
|
|
public void setPieGraphData(PieGraph piegraph){
|
|
|
this.currentData = this.getPieData();
|
|
|
- int index = 0;
|
|
|
+ if (this.currentData == null){
|
|
|
+ this.currentData = new ArrayList<PlotComparisonItem>();
|
|
|
+ }
|
|
|
|
|
|
this.pieGraph.removeSlices();
|
|
|
|
|
|
for (PlotComparisonItem item : this.currentData){
|
|
|
PieSlice slice = new PieSlice();
|
|
|
- slice.setColor(this.getColor(index));
|
|
|
- slice.setValue((Float) item.getValue2());
|
|
|
+ slice.setColor(item.getColor());
|
|
|
+ Double value2 = (Double) item.getValue2();
|
|
|
+ slice.setValue(value2.floatValue());
|
|
|
slice.setTitle(item.getTitle());
|
|
|
this.pieGraph.addSlice(slice);
|
|
|
- index++;
|
|
|
}
|
|
|
this.pieGraph.invalidate();
|
|
|
}
|
|
|
|
|
|
public void setLineGraphData(LineGraph linegraph){
|
|
|
this.currentData = this.getLinedata();
|
|
|
+ if (this.currentData == null){
|
|
|
+ this.currentData = new ArrayList<PlotComparisonItem>();
|
|
|
+ }
|
|
|
int index = 0;
|
|
|
|
|
|
this.lineGraph.removeAllLines();
|
|
@@ -237,7 +276,8 @@ public class StatisticsFragment extends Fragment {
|
|
|
for (PlotComparisonItem item : this.currentData){
|
|
|
LinePoint p = new LinePoint();
|
|
|
p.setX(index);
|
|
|
- p.setY((Float) item.getValue2());
|
|
|
+ Double value2 = (Double) item.getValue2();
|
|
|
+ p.setY(value2.floatValue());
|
|
|
index++;
|
|
|
}
|
|
|
this.lineGraph.addLine(l);
|
|
@@ -248,16 +288,18 @@ public class StatisticsFragment extends Fragment {
|
|
|
|
|
|
public void setBarGraphData(BarGraph bargraph){
|
|
|
this.currentData = this.getLinedata();
|
|
|
- int index = 0;
|
|
|
+ if (this.currentData == null){
|
|
|
+ this.currentData = new ArrayList<PlotComparisonItem>();
|
|
|
+ }
|
|
|
|
|
|
ArrayList<Bar> bars = new ArrayList<Bar>();
|
|
|
|
|
|
for (PlotComparisonItem item : this.currentData){
|
|
|
Bar d = new Bar();
|
|
|
- d.setColor(this.getColor(index));
|
|
|
+ d.setColor(item.getColor());
|
|
|
d.setName(item.getTitle());
|
|
|
- d.setValue((Float)item.getValue2());
|
|
|
- index++;
|
|
|
+ Double value2 = (Double) item.getValue2();
|
|
|
+ d.setValue(value2.floatValue());
|
|
|
}
|
|
|
|
|
|
this.barGraph.setBars(bars);
|
|
@@ -325,20 +367,22 @@ public class StatisticsFragment extends Fragment {
|
|
|
/*PROTOCOLS OVERVIEW*/
|
|
|
public ArrayList<PlotComparisonItem> attacksPerProtocols(){
|
|
|
ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
|
|
|
+ int index = 0;
|
|
|
for (String title : this.getSelectedProtocolTitles()){
|
|
|
int attacksCount = this.dbh.getAttackPerProtocolCount(title);
|
|
|
- PlotComparisonItem item = new PlotComparisonItem(title, title, attacksCount);
|
|
|
+ PlotComparisonItem item = new PlotComparisonItem(title,this.getColor(index), 0., (double) attacksCount);
|
|
|
plotItems.add(item);
|
|
|
+ index++;
|
|
|
}
|
|
|
Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
|
|
|
@Override
|
|
|
public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
|
|
|
- return s1.getTitle().compareToIgnoreCase(s2.getTitle());
|
|
|
+ return s1.getValue2().compareTo(s2.getValue2());
|
|
|
}
|
|
|
});
|
|
|
- return plotItems;
|
|
|
+ return this.resizeData(plotItems);
|
|
|
}
|
|
|
- public ArrayList<PlotComparisonItem> usesPerProtocols(){
|
|
|
+ public ArrayList<PlotComparisonItem> usesPerProtocol(){
|
|
|
ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
|
|
|
for (String title : this.getSelectedProtocolTitles()){
|
|
|
/*At the moment there is no possibillity to get the number of uses for each protocol*/
|
|
@@ -366,15 +410,17 @@ public class StatisticsFragment extends Fragment {
|
|
|
}
|
|
|
list.add(record);
|
|
|
}
|
|
|
+ int index = 0;
|
|
|
for (long date : recordMap.keySet()){
|
|
|
ArrayList<Record> list = recordMap.get(date);
|
|
|
- PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date), date, list.size());
|
|
|
+ PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date),this.getColor(index), (double) date, (double)list.size());
|
|
|
plotItems.add(item);
|
|
|
+ index++;
|
|
|
}
|
|
|
Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
|
|
|
@Override
|
|
|
public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
|
|
|
- return s1.getTitle().compareToIgnoreCase(s2.getTitle());
|
|
|
+ return s1.getValue1().compareTo(s2.getValue1());
|
|
|
}
|
|
|
});
|
|
|
return plotItems;
|
|
@@ -392,15 +438,17 @@ public class StatisticsFragment extends Fragment {
|
|
|
}
|
|
|
list.add(record);
|
|
|
}
|
|
|
+ int index = 0;
|
|
|
for (long time : recordMap.keySet()){
|
|
|
ArrayList<Record> list = recordMap.get(time);
|
|
|
- PlotComparisonItem item = new PlotComparisonItem(this.getDateAsTimeString(time), time, list.size());
|
|
|
+ PlotComparisonItem item = new PlotComparisonItem(this.getDateAsTimeString(time), this.getColor(index) , (double)time, (double) list.size());
|
|
|
plotItems.add(item);
|
|
|
+ index++;
|
|
|
}
|
|
|
Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
|
|
|
@Override
|
|
|
public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
|
|
|
- return s1.getTitle().compareToIgnoreCase(s2.getTitle());
|
|
|
+ return s1.getValue1().compareTo(s2.getValue1());
|
|
|
}
|
|
|
});
|
|
|
return plotItems;
|
|
@@ -421,17 +469,19 @@ public class StatisticsFragment extends Fragment {
|
|
|
count++;
|
|
|
recordMap.put(record.getBssid(), count);
|
|
|
}
|
|
|
+ int index = 0;
|
|
|
for (String key : recordMap.keySet()){
|
|
|
- PlotComparisonItem item = new PlotComparisonItem(key, key, recordMap.get(key));
|
|
|
+ PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., (double)recordMap.get(key));
|
|
|
plotItems.add(item);
|
|
|
+ index++;
|
|
|
}
|
|
|
Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
|
|
|
@Override
|
|
|
public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
|
|
|
- return s1.getTitle().compareToIgnoreCase(s2.getTitle());
|
|
|
+ return s1.getValue2().compareTo(s2.getValue2());
|
|
|
}
|
|
|
});
|
|
|
- return plotItems;
|
|
|
+ return this.resizeData(plotItems);
|
|
|
}
|
|
|
public ArrayList<PlotComparisonItem> attacksPerESSID(String protocol){
|
|
|
LogFilter filter = new LogFilter();
|
|
@@ -448,20 +498,48 @@ public class StatisticsFragment extends Fragment {
|
|
|
count++;
|
|
|
recordMap.put(record.getSsid(), count);
|
|
|
}
|
|
|
+ int index = 0;
|
|
|
for (String key : recordMap.keySet()){
|
|
|
- PlotComparisonItem item = new PlotComparisonItem(key, key, recordMap.get(key));
|
|
|
+ PlotComparisonItem item = new PlotComparisonItem(key,this.getColor(index), 0. , (double)recordMap.get(key));
|
|
|
plotItems.add(item);
|
|
|
+ index++;
|
|
|
}
|
|
|
Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
|
|
|
@Override
|
|
|
public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
|
|
|
- return s1.getTitle().compareToIgnoreCase(s2.getTitle());
|
|
|
+ return s1.getValue2().compareTo(s2.getValue2());
|
|
|
}
|
|
|
});
|
|
|
- return plotItems;
|
|
|
+
|
|
|
+ return this.resizeData(plotItems);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private ArrayList<PlotComparisonItem> resizeData(ArrayList<PlotComparisonItem> plotItems){
|
|
|
+ if (plotItems != null){
|
|
|
+ if (plotItems.size() > MAX_NUMBER_OF_CHART_OBJECTS && MAX_NUMBER_OF_CHART_OBJECTS > 1){
|
|
|
+ ArrayList<PlotComparisonItem> copy = new ArrayList<PlotComparisonItem>();
|
|
|
+ ArrayList<PlotComparisonItem> others = new ArrayList<PlotComparisonItem>();
|
|
|
+ double valueOfOthers = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < plotItems.size(); i++){
|
|
|
+ if (i < MAX_NUMBER_OF_CHART_OBJECTS - 1){
|
|
|
+ copy.add(plotItems.get(i));
|
|
|
+ } else {
|
|
|
+ PlotComparisonItem item = plotItems.get(i);
|
|
|
+ others.add(item);
|
|
|
+ valueOfOthers+=item.getValue2();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PlotComparisonItem otherItem = new PlotComparisonItem(OTHER_CHART_TITLE, this.getOtherColor(), 0., valueOfOthers);
|
|
|
+ copy.add(otherItem);
|
|
|
+
|
|
|
+ return copy;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return plotItems;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* FILTER STUFF
|
|
|
* */
|
|
@@ -506,6 +584,11 @@ public class StatisticsFragment extends Fragment {
|
|
|
*
|
|
|
* */
|
|
|
|
|
|
+
|
|
|
+ public int getOtherColor(){
|
|
|
+ return Color.rgb(0,0,0);
|
|
|
+ }
|
|
|
+
|
|
|
public ArrayList<Integer> getColorList(){
|
|
|
if (this.colorList == null){
|
|
|
this.colorList = new ArrayList<Integer>();
|
|
@@ -518,7 +601,8 @@ public class StatisticsFragment extends Fragment {
|
|
|
}
|
|
|
|
|
|
public Integer getColor(int index){
|
|
|
- if (index > this.colorList.size()) {
|
|
|
+ if (this.colorList == null) this.colorList = new ArrayList<Integer>();
|
|
|
+ if (index >= this.colorList.size()) {
|
|
|
for (int i = this.colorList.size(); i<= index; i++){
|
|
|
Integer color = this.generateColorForIndex(i);
|
|
|
this.colorList.add(color);
|
|
@@ -536,9 +620,9 @@ public class StatisticsFragment extends Fragment {
|
|
|
int a = index % 16;
|
|
|
int n = index % 7;
|
|
|
|
|
|
- int R = Math.max( (r[n] * 255) - (a * 16) , 0);
|
|
|
- int G = Math.max( (g[n] * 255) - ((Math.max(0,(a -1))) * 16), 0);
|
|
|
- int B = Math.max( (b[n] * 255) - ((Math.max(0,(a -2))) * 16), 0);
|
|
|
+ int R = Math.max( (r[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
|
|
|
+ int G = Math.max( (g[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
|
|
|
+ int B = Math.max( (b[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
|
|
|
|
|
|
return Color.rgb(R,G,B);
|
|
|
}
|