Search in sources :

Example 1 with Stats

use of com.ichi2.libanki.Stats in project Anki-Android by Ramblurr.

the class ChartBuilder method onCreate.

// public void setRenderer(int type, int row) {
// Resources res = getResources();
// XYSeriesRenderer renderer = new XYSeriesRenderer();
// if (type <= 2) {
// switch (row) {
// case 0:
// renderer.setColor(res.getColor(R.color.statistics_due_young_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_due_mature_cards));
// break;
// case 2:
// // renderer.setColor(res.getColor(R.color.statistics_due_failed_cards));
// break;
// }
// } else if (type == 3) {
// switch (row) {
// case 0:
// // renderer.setColor(res.getColor(R.color.statistics_reps_new_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_reps_young_cards));
// break;
// case 2:
// renderer.setColor(res.getColor(R.color.statistics_reps_mature_cards));
// break;
// }
// } else {
// renderer.setColor(res.getColor(R.color.statistics_default));
// }
// mRenderer.addSeriesRenderer(renderer);
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(AnkiDroidApp.TAG, "ChartBuilder.OnCreate");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    restorePreferences();
    Resources res = getResources();
    Stats stats = Stats.currentStats();
    if (stats != null) {
        mSeriesList = stats.getSeriesList();
        mMeta = stats.getMetaInfo();
    } else if (savedInstanceState != null) {
        int len = savedInstanceState.getInt("seriesListLen");
        mSeriesList = new double[len][];
        for (int i = 0; i < len; i++) {
            mSeriesList[i] = (double[]) savedInstanceState.getSerializable("seriesList" + i);
        }
        mMeta = (Object[]) savedInstanceState.getSerializable("meta");
    } else {
        finish();
    }
    String title = res.getString((Integer) mMeta[1]);
    boolean backwards = (Boolean) mMeta[2];
    int[] valueLabels = (int[]) mMeta[3];
    int[] barColors = (int[]) mMeta[4];
    int[] axisTitles = (int[]) mMeta[5];
    String subTitle = (String) mMeta[6];
    if (mSeriesList == null || mSeriesList[0].length < 2) {
        Log.i(AnkiDroidApp.TAG, "ChartBuilder - Data variable empty, closing chartbuilder");
        finish();
        return;
    }
    if (mFullScreen) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    View mainView = getLayoutInflater().inflate(R.layout.statistics, null);
    setContentView(mainView);
    mainView.setBackgroundColor(Color.WHITE);
    mTitle = (TextView) findViewById(R.id.statistics_title);
    if (mChartView == null) {
        if (mFullScreen) {
            mTitle.setText(title);
            mTitle.setTextColor(Color.BLACK);
        } else {
            setTitle(title);
            AnkiDroidApp.getCompat().setSubtitle(this, subTitle);
            mTitle.setVisibility(View.GONE);
        }
        for (int i = 1; i < mSeriesList.length; i++) {
            XYSeries series = new XYSeries(res.getString(valueLabels[i - 1]));
            for (int j = 0; j < mSeriesList[i].length; j++) {
                series.add(mSeriesList[0][j], mSeriesList[i][j]);
            }
            mDataset.addSeries(series);
            XYSeriesRenderer renderer = new XYSeriesRenderer();
            renderer.setColor(res.getColor(barColors[i - 1]));
            mRenderer.addSeriesRenderer(renderer);
        }
        if (mSeriesList.length == 1) {
            mRenderer.setShowLegend(false);
        }
        if (backwards) {
            mPan = new double[] { mSeriesList[0][0] - 0.5, 0.5 };
        } else {
            mPan = new double[] { -0.5, mSeriesList[0][mSeriesList[0].length - 1] + 0.5 };
        }
        mRenderer.setLegendTextSize(17);
        mRenderer.setBarSpacing(0.4);
        mRenderer.setLegendHeight(60);
        mRenderer.setAxisTitleTextSize(17);
        mRenderer.setLabelsTextSize(17);
        mRenderer.setXAxisMin(mPan[0]);
        mRenderer.setXAxisMax(mPan[1]);
        mRenderer.setYAxisMin(0);
        mRenderer.setGridColor(Color.LTGRAY);
        mRenderer.setShowGrid(true);
        mRenderer.setXTitle(res.getStringArray(R.array.due_x_axis_title)[axisTitles[0]]);
        mRenderer.setYTitle(res.getString(axisTitles[1]));
        mRenderer.setBackgroundColor(Color.WHITE);
        mRenderer.setMarginsColor(Color.WHITE);
        mRenderer.setAxesColor(Color.BLACK);
        mRenderer.setLabelsColor(Color.BLACK);
        mRenderer.setYLabelsColor(0, Color.BLACK);
        mRenderer.setYLabelsAngle(-90);
        mRenderer.setXLabelsColor(Color.BLACK);
        mRenderer.setXLabelsAlign(Align.CENTER);
        mRenderer.setYLabelsAlign(Align.CENTER);
        mRenderer.setZoomEnabled(false, false);
        mRenderer.setMargins(new int[] { 15, 48, 30, 10 });
        mRenderer.setAntialiasing(true);
        mRenderer.setPanEnabled(true, false);
        mRenderer.setPanLimits(mPan);
        mChartView = ChartFactory.getBarChartView(this, mDataset, mRenderer, BarChart.Type.STACKED);
        LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
        layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    } else {
        mChartView.repaint();
    }
    gestureDetector = new GestureDetector(new MyGestureDetector());
    mChartView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    });
}
Also used : XYSeries(org.achartengine.model.XYSeries) LayoutParams(android.view.ViewGroup.LayoutParams) GestureDetector(android.view.GestureDetector) View(android.view.View) GraphicalView(org.achartengine.GraphicalView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) Stats(com.ichi2.libanki.Stats) XYSeriesRenderer(org.achartengine.renderer.XYSeriesRenderer) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Example 2 with Stats

use of com.ichi2.libanki.Stats in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundUpdateValuesFromDeck.

private TaskData doInBackgroundUpdateValuesFromDeck(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundUpdateValuesFromDeck");
    try {
        Sched sched = params[0].getCollection().getSched();
        Object[] obj = params[0].getObjArray();
        boolean reset = (Boolean) obj[0];
        if (reset) {
            sched.reset();
        }
        int[] counts = sched.counts();
        int totalNewCount = sched.totalNewForCurrentDeck();
        int totalCount = sched.cardCount();
        double progressMature = ((double) sched.matureCount()) / ((double) totalCount);
        double progressAll = 1 - (((double) (totalNewCount + counts[1])) / ((double) totalCount));
        double[][] serieslist = null;
        // only calculate stats if necessary
        if ((Boolean) obj[1]) {
            serieslist = Stats.getSmallDueStats(sched.getCol());
        }
        return new TaskData(new Object[] { counts[0], counts[1], counts[2], totalNewCount, totalCount, progressMature, progressAll, sched.eta(counts), serieslist });
    } catch (RuntimeException e) {
        Log.e(AnkiDroidApp.TAG, "doInBackgroundUpdateValuesFromDeck - an error occurred: " + e);
        return null;
    }
}
Also used : Sched(com.ichi2.libanki.Sched) JSONObject(org.json.JSONObject)

Example 3 with Stats

use of com.ichi2.libanki.Stats in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundLoadStatistics.

private TaskData doInBackgroundLoadStatistics(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadStatistics");
    Collection col = params[0].getCollection();
    int type = params[0].getInt();
    boolean wholeCollection = params[0].getBoolean();
    Stats stats = new Stats(col, wholeCollection);
    switch(type) {
        default:
        case Stats.TYPE_FORECAST:
            return new TaskData(stats.calculateDue(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH)));
        case Stats.TYPE_REVIEW_COUNT:
            return new TaskData(stats.calculateDone(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), true));
        case Stats.TYPE_REVIEW_TIME:
            return new TaskData(stats.calculateDone(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), false));
    }
}
Also used : Stats(com.ichi2.libanki.Stats) Collection(com.ichi2.libanki.Collection)

Aggregations

Stats (com.ichi2.libanki.Stats)2 Resources (android.content.res.Resources)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Collection (com.ichi2.libanki.Collection)1 Sched (com.ichi2.libanki.Sched)1 GraphicalView (org.achartengine.GraphicalView)1 XYSeries (org.achartengine.model.XYSeries)1 XYSeriesRenderer (org.achartengine.renderer.XYSeriesRenderer)1 JSONObject (org.json.JSONObject)1