Skip to content

Commit

Permalink
issue - 4113
Browse files Browse the repository at this point in the history
Only formating of the one if block
  • Loading branch information
Tomas Musilek authored and Tomas Musilek committed Mar 7, 2016
1 parent 5d1ed5d commit 45803c0
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 63 deletions.
22 changes: 11 additions & 11 deletions AnkiDroid/src/main/java/com/ichi2/anki/Statistics.java
Expand Up @@ -191,15 +191,15 @@ public boolean onPrepareOptionsMenu(Menu menu) {
return true;
}
switch (mTaskHandler.getStatType()){
case Stats.TYPE_MONTH:
case TYPE_MONTH:
MenuItem monthItem = menu.findItem(R.id.item_time_month);
monthItem.setChecked(true);
break;
case Stats.TYPE_YEAR:
case TYPE_YEAR:
MenuItem yearItem = menu.findItem(R.id.item_time_year);
yearItem.setChecked(true);
break;
case Stats.TYPE_LIFE:
case TYPE_LIFE:
MenuItem lifeItem = menu.findItem(R.id.item_time_all);
lifeItem.setChecked(true);
break;
Expand All @@ -219,24 +219,24 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.item_time_month:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
if (mTaskHandler.getStatType() != Stats.TYPE_MONTH) {
mTaskHandler.setStatType(Stats.TYPE_MONTH);
if (mTaskHandler.getStatType() != Stats.AxisType.TYPE_MONTH) {
mTaskHandler.setStatType(Stats.AxisType.TYPE_MONTH);
mSectionsPagerAdapter.notifyDataSetChanged();
}
return true;
case R.id.item_time_year:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
if (mTaskHandler.getStatType() != Stats.TYPE_YEAR) {
mTaskHandler.setStatType(Stats.TYPE_YEAR);
if (mTaskHandler.getStatType() != Stats.AxisType.TYPE_YEAR) {
mTaskHandler.setStatType(Stats.AxisType.TYPE_YEAR);
mSectionsPagerAdapter.notifyDataSetChanged();
}
return true;
case R.id.item_time_all:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
if (mTaskHandler.getStatType() != Stats.TYPE_LIFE) {
mTaskHandler.setStatType(Stats.TYPE_LIFE);
if (mTaskHandler.getStatType() != Stats.AxisType.TYPE_LIFE) {
mTaskHandler.setStatType(Stats.AxisType.TYPE_LIFE);
mSectionsPagerAdapter.notifyDataSetChanged();
}
return true;
Expand Down Expand Up @@ -419,7 +419,7 @@ public static class ChartFragment extends StatisticFragment {
private int mWidth = 0;
private int mSectionNumber;

private int mType = Stats.TYPE_MONTH;
private Stats.AxisType mType = Stats.AxisType.TYPE_MONTH;
private boolean mIsCreated = false;

private AsyncTask mCreateChartTask;
Expand Down Expand Up @@ -588,7 +588,7 @@ public static class OverviewStatisticsFragment extends StatisticFragment{

private WebView mWebView;
private ProgressBar mProgressBar;
private int mType = Stats.TYPE_MONTH;
private Stats.AxisType mType = Stats.AxisType.TYPE_MONTH;
private boolean mIsCreated = false;
private AsyncTask mCreateStatisticsOverviewTask;

Expand Down
Expand Up @@ -44,7 +44,7 @@ public class AnkiStatsTaskHandler {

private Collection mCollectionData;
private float mStandardTextSize = 10f;
private int mStatType = Stats.TYPE_MONTH;
private Stats.AxisType mStatType = Stats.AxisType.TYPE_MONTH;
private boolean mIsWholeCollection = false;
private static Lock sLock = new ReentrantLock();

Expand Down Expand Up @@ -340,11 +340,11 @@ public void setmStandardTextSize(float mStandardTextSize) {
this.mStandardTextSize = mStandardTextSize;
}

public int getStatType() {
public Stats.AxisType getStatType() {
return mStatType;
}

public void setStatType(int mStatType) {
public void setStatType(Stats.AxisType mStatType) {
this.mStatType = mStatType;
}

Expand Down
10 changes: 5 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/anki/stats/ChartBuilder.java
Expand Up @@ -41,7 +41,7 @@ public class ChartBuilder {
private int mFrameThickness = 60;

int mMaxCards = 0;
private int mType;
private Stats.AxisType mType;
private int[] mValueLabels;
private int[] mColors;
private int[] mAxisTitles;
Expand All @@ -62,18 +62,18 @@ public ChartBuilder(ChartView chartView, Collection collectionData, boolean isWh
mChartType = chartType;
}

private void calcStats(int type){
private void calcStats(Stats.AxisType type){
mType = type;
Stats stats = new Stats(mCollectionData, mIsWholeCollection);
switch (mChartType){
case FORECAST:
stats.calculateDue(mChartView.getContext(), mType);
break;
case REVIEW_COUNT:
stats.calculateDone(mType, true);
stats.calculateReviewCount(mType);
break;
case REVIEW_TIME:
stats.calculateDone(mType, false);
stats.calculateReviewTime(mType);
break;
case INTERVALS:
stats.calculateIntervals(mChartView.getContext(), mType);
Expand Down Expand Up @@ -106,7 +106,7 @@ private void calcStats(int type){
mDynamicAxis = (Boolean) metaData[20];
}

public PlotSheet renderChart(int type){
public PlotSheet renderChart(Stats.AxisType type){
calcStats(type);
Paint paint = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
Expand Down
Expand Up @@ -16,13 +16,15 @@

package com.ichi2.anki.stats;

import com.ichi2.libanki.Stats;

/**
* Interface between Stats.java and AdvancedStatistics.java
*/
public class StatsMetaInfo {
boolean mDynamicAxis = false;
boolean mHasColoredCumulative = false;
int mType;
Stats.AxisType mType;
int mTitle;
boolean mBackwards;
int[] mValueLabels;
Expand Down Expand Up @@ -81,11 +83,11 @@ public void setmHasColoredCumulative(boolean mHasColoredCumulative) {
this.mHasColoredCumulative = mHasColoredCumulative;
}

public int getmType() {
public Stats.AxisType getmType() {
return mType;
}

public void setmType(int mType) {
public void setmType(Stats.AxisType mType) {
this.mType = mType;
}

Expand Down
74 changes: 45 additions & 29 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Stats.java
Expand Up @@ -37,9 +37,11 @@
*/
public class Stats {

public static final int TYPE_MONTH = 0;
public static final int TYPE_YEAR = 1;
public static final int TYPE_LIFE = 2;
public static enum AxisType{
TYPE_MONTH,
TYPE_YEAR,
TYPE_LIFE
}

public static enum ChartType {FORECAST, REVIEW_COUNT, REVIEW_TIME,
INTERVALS, HOURLY_BREAKDOWN, WEEKLY_BREAKDOWN, ANSWER_BUTTONS, CARDS_TYPES, OTHER};
Expand All @@ -53,7 +55,7 @@ public static enum ChartType {FORECAST, REVIEW_COUNT, REVIEW_TIME,
private double[][] mSeriesList;

private boolean mHasColoredCumulative = false;
private int mType;
private AxisType mType;
private int mTitle;
private boolean mBackwards;
private int[] mValueLabels;
Expand Down Expand Up @@ -172,7 +174,7 @@ public int[] calculateTodayStats(){
return new int[]{cards, thetime, failed, lrn, rev, relrn, filt, mcnt, msum};
}

public boolean calculateDue(Context context, int type) {
public boolean calculateDue(Context context, AxisType type) {

// Not in libanki
StatsMetaInfo metaInfo = new StatsMetaInfo();
Expand Down Expand Up @@ -210,15 +212,15 @@ public boolean calculateDue(Context context, int type) {
* Due and cumulative due
* ***********************************************************************************************
*/
private boolean calculateDue(int type) {
private boolean calculateDue(AxisType type) {
mHasColoredCumulative = false;
mType = type;
mDynamicAxis = true;
mBackwards = false;
mTitle = R.string.stats_forecast;
mValueLabels = new int[] { R.string.statistics_young, R.string.statistics_mature };
mColors = new int[] { R.attr.stats_young, R.attr.stats_mature };
mAxisTitles = new int[] { type, R.string.stats_cards, R.string.stats_cumulative_cards };
mAxisTitles = new int[] { type.ordinal(), R.string.stats_cards, R.string.stats_cumulative_cards };
int end = 0;
int chunk = 0;
switch (type) {
Expand Down Expand Up @@ -272,9 +274,9 @@ private boolean calculateDue(int type) {
if (end == -1 && dues.size() < 2) {
end = 31;
}
if (type != TYPE_LIFE && dues.get(dues.size() - 1)[0] < end) {
if (type != AxisType.TYPE_LIFE && dues.get(dues.size() - 1)[0] < end) {
dues.add(new int[] { end, 0, 0 });
} else if (type == TYPE_LIFE && dues.size() < 2) {
} else if (type == AxisType.TYPE_LIFE && dues.size() < 2) {
dues.add(new int[] { Math.max(12, dues.get(dues.size() - 1)[0] + 1), 0, 0 });
}

Expand Down Expand Up @@ -365,15 +367,29 @@ public static double[][] getSmallDueStats(Collection col) {
return serieslist;
}

public boolean calculateDone(int type, boolean reps) {
public boolean calculateReviewCount(AxisType type) {
return calculateDone(type, ChartType.REVIEW_COUNT);
}

public boolean calculateReviewTime(AxisType type) {
return calculateDone(type, ChartType.REVIEW_TIME);
}

/**
* Calculation of Review count or Review time
* @param type
* @param charType CharType.REVIEW_COUNT or Chartype.REVIEW_TIME
* @return
*/
private boolean calculateDone(AxisType type, ChartType charType) {
mHasColoredCumulative = true;
mDynamicAxis = true;
mType = type;
mBackwards = true;
if (reps) {
if (charType == ChartType.REVIEW_COUNT) {
mTitle = R.string.stats_review_count;
mAxisTitles = new int[] { type, R.string.stats_answers, R.string.stats_cumulative_answers };
} else {
mAxisTitles = new int[] { type.ordinal(), R.string.stats_answers, R.string.stats_cumulative_answers };
} else if(charType == ChartType.REVIEW_TIME) {
mTitle = R.string.stats_review_time;
}
mValueLabels = new int[] { R.string.statistics_learn, R.string.statistics_relearn, R.string.statistics_young,
Expand Down Expand Up @@ -415,14 +431,14 @@ public boolean calculateDone(int type, boolean reps) {
}
String ti;
String tf;
if (!reps) {
if (charType == ChartType.REVIEW_TIME) {
ti = "time/1000";
if (mType == TYPE_MONTH) {
if (mType == AxisType.TYPE_MONTH) {
tf = "/60.0"; // minutes
mAxisTitles = new int[] { type, R.string.stats_minutes, R.string.stats_cumulative_time_minutes };
mAxisTitles = new int[] { type.ordinal(), R.string.stats_minutes, R.string.stats_cumulative_time_minutes };
} else {
tf = "/3600.0"; // hours
mAxisTitles = new int[] { type, R.string.stats_hours, R.string.stats_cumulative_time_hours };
mAxisTitles = new int[] { type.ordinal(), R.string.stats_hours, R.string.stats_cumulative_time_hours };
}
} else {
ti = "1";
Expand Down Expand Up @@ -461,9 +477,9 @@ public boolean calculateDone(int type, boolean reps) {
}

// small adjustment for a proper chartbuilding with achartengine
if (type != TYPE_LIFE && (list.size() == 0 || list.get(0)[0] > -num)) {
if (type != AxisType.TYPE_LIFE && (list.size() == 0 || list.get(0)[0] > -num)) {
list.add(0, new double[] { -num, 0, 0, 0, 0, 0 });
} else if (type == TYPE_LIFE && list.size() == 0) {
} else if (type == AxisType.TYPE_LIFE && list.size() == 0) {
list.add(0, new double[] { -12, 0, 0, 0, 0, 0 });
}
if (list.get(list.size() - 1)[0] < 0) {
Expand Down Expand Up @@ -556,14 +572,14 @@ public boolean calculateDone(int type, boolean reps) {
* Intervals ***********************************************************************************************
*/

public boolean calculateIntervals(Context context, int type) {
public boolean calculateIntervals(Context context, AxisType type) {
mDynamicAxis = true;
mType = type;
double all = 0, avg = 0, max_ = 0;
mBackwards = false;

mTitle = R.string.stats_review_intervals;
mAxisTitles = new int[] { type, R.string.stats_cards, R.string.stats_percentage };
mAxisTitles = new int[] { type.ordinal(), R.string.stats_cards, R.string.stats_percentage };

mValueLabels = new int[] { R.string.stats_cards_intervals};
mColors = new int[] { R.attr.stats_interval};
Expand Down Expand Up @@ -629,9 +645,9 @@ public boolean calculateIntervals(Context context, int type) {
if (num == -1 && list.size() < 2) {
num = 31;
}
if (type != TYPE_LIFE && list.get(list.size() - 1)[0] < num) {
if (type != AxisType.TYPE_LIFE && list.get(list.size() - 1)[0] < num) {
list.add(new double[] { num, 0 });
} else if (type == TYPE_LIFE && list.size() < 2) {
} else if (type == AxisType.TYPE_LIFE && list.size() < 2) {
list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0 });
}

Expand Down Expand Up @@ -687,7 +703,7 @@ public boolean calculateIntervals(Context context, int type) {
/**
* Hourly Breakdown
*/
public boolean calculateBreakdown(int type) {
public boolean calculateBreakdown(AxisType type) {
mTitle = R.string.stats_breakdown;
mAxisTitles = new int[] { R.string.stats_time_of_day, R.string.stats_percentage_correct, R.string.stats_reviews };

Expand Down Expand Up @@ -825,7 +841,7 @@ public int compare(double[] s1, double[] s2) {
* Weekly Breakdown
*/

public boolean calculateWeeklyBreakdown(int type) {
public boolean calculateWeeklyBreakdown(AxisType type) {
mTitle = R.string.stats_weekly_breakdown;
mAxisTitles = new int[] { R.string.stats_day_of_week, R.string.stats_percentage_correct, R.string.stats_reviews };

Expand Down Expand Up @@ -952,7 +968,7 @@ public boolean calculateWeeklyBreakdown(int type) {
* Answer Buttons
*/

public boolean calculateAnswerButtons(int type) {
public boolean calculateAnswerButtons(AxisType type) {
mHasColoredCumulative = true;
mTitle = R.string.stats_answer_buttons;
mAxisTitles = new int[] { R.string.stats_answer_type, R.string.stats_answers, R.string.stats_cumulative_correct_percentage };
Expand All @@ -969,9 +985,9 @@ public boolean calculateAnswerButtons(int type) {
if (lim.length() > 0)
lims.add(lim);

if (type == TYPE_MONTH)
if (type == AxisType.TYPE_MONTH)
days = 30;
else if (type == TYPE_YEAR)
else if (type == AxisType.TYPE_YEAR)
days = 365;
else
days = -1;
Expand Down Expand Up @@ -1083,7 +1099,7 @@ else if(currentType == 2)
/**
* Cards Types
*/
public boolean calculateCardsTypes(int type) {
public boolean calculateCardsTypes(AxisType type) {
mTitle = R.string.stats_cards_types;
mIsPieChart = true;
mAxisTitles = new int[] { R.string.stats_answer_type, R.string.stats_answers, R.string.stats_cumulative_correct_percentage };
Expand Down

0 comments on commit 45803c0

Please sign in to comment.