package org.linaro.iasenov.benchmarkframework; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.Toast; import com.github.mikephil.charting.charts.HorizontalBarChart; import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.formatter.ValueFormatter; import com.github.mikephil.charting.utils.ColorTemplate; import com.github.mikephil.charting.utils.ViewPortHandler; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by iasenov on 10/5/16. */ public class Chart extends AppCompatActivity { private static String TAG = "Chart"; final String[] nameTestItems = {"MemSpeed", "RandMem", "Linaro-Libc-Bench", "Linaro-StringBench", "Linaro-Harness", "Linaro-Dhrystone", "Iozone", "Bonnie++", "Algorithm(ART)", "BMsGame(ART)", "Caffeine(ART)", "Jit-out(ART)", "Math(ART)", "Micro(ART)", "Stanford(ART)", "DrawArc(GPU)", "DrawCircle2(GPU)", "DrawImage(GPU)", "DrawRect(GPU)", "DrawText(GPU)", "DrawCircle(GPU)", "Kubench(GPU)", "Nehe08(GPU)", "Nehe16(GPU)", "TeapotES(GPU)", "Tiotester", "Himeno", "Stream", "FS-Mark", "Bork", "SciMark", "Smallpt", "Tscp", "Hint", "Fhourstones", "Monte-Carlo", "Bonds", "Repo", "N-queens", "SysBench", "BinaryTrees", "MallocBench", "StressBench", "TuXBencH", "Later", "LinPack"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); List> groupList = new ArrayList>(); ArrayList group = new ArrayList<>(); ArrayList labels = new ArrayList(); ArrayList group_average = new ArrayList<>(); int index = 0; boolean isAllNeededEntriesInitialized = false; int repeat = 1; for (int j = 0; j < nameTestItems.length; j++) { if (MainActivity.mapTimes.containsKey(nameTestItems[j])) { //Log.i(TAG,nameTestItems[j] + "--->" + MainActivity.mapTimes.get(nameTestItems[j])); String points[] = MainActivity.mapTimes.get(nameTestItems[j]).split(":"); repeat = points.length; //Log.i(TAG, "repeatttt:" + repeat); int sumPoints = 0; for(int i = 0; i < points.length; i++){ if(!isAllNeededEntriesInitialized) { group = new ArrayList<>(); groupList.add(group); if(i == points.length -1 ) { groupList.add(group_average); } } double pointD = Double.parseDouble(points[i]); int point = (int)(50*100/pointD); sumPoints = sumPoints + point; if(isAllNeededEntriesInitialized){ group = groupList.get(i) ; } group.add(new BarEntry(point, index)); //groupList.add(group); } group_average.add(new BarEntry(sumPoints/repeat, index)); isAllNeededEntriesInitialized = true;//all group arrays are initialized and filled with firts results labels.add(nameTestItems[j]); index++; } } BarData data = new BarData(labels); for(int k = 0; k < repeat ;k++){ ArrayList entries = groupList.get(k); BarDataSet dataset = new BarDataSet(entries, "Points"); dataset.setColors(ColorTemplate.COLORFUL_COLORS); final Echo echo = new Echo(k+1); dataset.setValueFormatter(new ValueFormatter() { @Override public String getFormattedValue(float value, Entry entry, int i, ViewPortHandler viewPortHandler) { return (int) value + " [" + echo.x +"]"; } }); data.addDataSet(dataset); if(k == repeat-1){ //add data for average //Log.i(TAG, "k:"+k + " repeat:"+repeat); entries = groupList.get(k+1); dataset = new BarDataSet(entries, "Points"); dataset.setColor(ColorTemplate.rgb("#b6b2ae")); //set different color for average points if(repeat > 1) { //Show average group when repeat > 1 dataset.setValueFormatter(new ValueFormatter() { @Override public String getFormattedValue(float value, Entry entry, int i, ViewPortHandler viewPortHandler) { return (int) value + " [avg]"; } }); data.addDataSet(dataset); } } } //final HorizontalBarChart chart = new HorizontalBarChart(this); //setContentView(chart); setContentView(R.layout.chart); // Find the toolbar view inside the activity layout Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarId); // Sets the Toolbar to act as the ActionBar for this Activity window. // Make sure the toolbar exists in the activity and is not null setSupportActionBar(toolbar); final HorizontalBarChart chart = (HorizontalBarChart) findViewById(R.id.chartId); Button saveBtn = (Button) findViewById(R.id.saveButtonId); saveBtn.setOnClickListener(new View.OnClickListener(){ @Override //On click function public void onClick(View v) { chart.saveToGallery("Chart_" + MainActivity.autoTestFileNameIdentifier + ".jpg", 100); Toast.makeText(v.getContext(), "Chart was saved to Gallery", Toast.LENGTH_SHORT).show(); } }); data.setValueTextSize(8f); chart.setData(data); chart.setDescription("# Benchmark Results"); chart.setDragEnabled(true); // on by default //chart.setVisibleXRangeMaximum(15); //chart.setVisibleXRangeMaximum(20); chart.animateXY(3000, 3000); chart.setDrawValueAboveBar(false); chart.setTouchEnabled(false); chart.getAxisLeft().setStartAtZero(true); chart.getAxisRight().setStartAtZero(true); chart.invalidate(); setTitle("Benchmark Chart"); } public class Echo{ int x; public Echo(int x){ this.x = x; } } //********************************************************************************************** }//Chart //**********************************************************************************************