Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Averaqe Daily Load stats on deck front page #111

Open
wants to merge 2 commits into
base: v2.1-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions res/layout-xlarge/studyoptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@
android:textColor="#007700" />
</LinearLayout>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_width="wrap_content"
android:text="studyoptions_avgdailyload"
android:paddingRight="5dip"/>
<TextView
android:id="@+id/studyoptions_forecast"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_width="wrap_content"
android:gravity="right"/>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
Expand Down
14 changes: 14 additions & 0 deletions res/layout/studyoptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@
android:textColor="#007700" />
</LinearLayout>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_width="wrap_content"
android:text="@string/studyoptions_avgdailyload"
android:paddingRight="5dip"/>
<TextView
android:id="@+id/studyoptions_forecast"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_width="wrap_content"
android:gravity="right"/>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions res/values-ar/01-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<string name="ok">موافق</string>
<string name="studyoptions_deck_name">اسم مجموعة البطاقات</string>
<string name="studyoptions_due_today">المستحق اليوم:</string>
<string name="studyoptions_avgdailyload">Daily load:</string>
<string name="studyoptions_new_total">مجموع البطاقات الجديدة:</string>
<string name="studyoptions_total_cards">مجموع البطاقات:</string>
<string name="studyoptions_eta">الوقت المقدر (دقيقة):</string>
Expand Down
1 change: 1 addition & 0 deletions res/values-fr/01-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<string name="ok">OK</string>
<string name="studyoptions_deck_name">Nom du paquet</string>
<string name="studyoptions_due_today">Prévues aujourd’hui :</string>
<string name="studyoptions_avgdailyload">Charge journalière :</string>
<string name="studyoptions_new_total">Cartes inédites :</string>
<string name="studyoptions_total_cards">Cartes :</string>
<string name="studyoptions_eta">Durée estimée (mn) :</string>
Expand Down
5 changes: 3 additions & 2 deletions res/values/01-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<!--<string name="studyoptions_title">Study Options</string>
--><string name="studyoptions_deck_name">Deck name</string>
<string name="studyoptions_due_today">Due today:</string>
<string name="studyoptions_avgdailyload">Daily load:</string>
<string name="studyoptions_new_total">Total new cards:</string>
<string name="studyoptions_total_cards">Total cards:</string>
<string name="studyoptions_eta">Estimated time (min):</string>
Expand Down Expand Up @@ -102,8 +103,7 @@
<!-- <string name="menu_deck_properties">Deck Properties</string> -->
<string name="menu_about">About</string>

<string name="menu_dismiss_note">Dismiss Note...</string>
<string name="menu_bury_note">Bury Note</string>
<string name="menu_dismiss_note">Dismiss Note...</string><string name="menu_bury_note">Bury Note</string>
<string name="menu_suspend_card">Suspend Card</string>
<string name="menu_suspend_note">Suspend Note</string>
<string name="menu_delete_note">Delete Note</string>
Expand Down Expand Up @@ -180,4 +180,5 @@
<string name="help_cloze">help</string>

<string name="button_sync">Sync</string>

</resources>
6 changes: 6 additions & 0 deletions src/com/ichi2/anki/StudyOptionsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public class StudyOptionsFragment extends Fragment {
private TextView mTextTotal;
private TextView mTextETA;
private LinearLayout mSmallChart;
private TextView mTextAvgDailyLoad;
private LinearLayout mDeckCounts;
private LinearLayout mDeckChart;
private ImageButton mAddNote;
Expand Down Expand Up @@ -443,6 +444,7 @@ public void onConfigurationChanged(Configuration newConfig) {
CharSequence lrnToday = mTextTodayLrn.getText();
CharSequence revToday = mTextTodayRev.getText();
CharSequence newTotal = mTextNewTotal.getText();
CharSequence avgDailyLoad = mTextAvgDailyLoad.getText();
CharSequence total = mTextTotal.getText();
CharSequence eta = mTextETA.getText();
// long timelimit = mCol.getTimeLimit() / 60;
Expand All @@ -460,6 +462,7 @@ public void onConfigurationChanged(Configuration newConfig) {
mTextTodayNew.setText(newToday);
mTextTodayLrn.setText(lrnToday);
mTextTodayRev.setText(revToday);
mTextAvgDailyLoad.setText(avgDailyLoad);
mTextNewTotal.setText(newTotal);
mTextTotal.setText(total);
mTextETA.setText(eta);
Expand Down Expand Up @@ -644,6 +647,7 @@ private void initAllContentViews(LayoutInflater inflater) {
mTextTotal = (TextView) mStudyOptionsView.findViewById(R.id.studyoptions_total);
mTextETA = (TextView) mStudyOptionsView.findViewById(R.id.studyoptions_eta);
mSmallChart = (LinearLayout) mStudyOptionsView.findViewById(R.id.studyoptions_mall_chart);
mTextAvgDailyLoad = (TextView) mStudyOptionsView.findViewById(R.id.studyoptions_forecast);

mGlobalMatBar.setVisibility(View.INVISIBLE);
mGlobalBar.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -1231,6 +1235,7 @@ public void onPostExecute(DeckTask.TaskData result) {
mProgressAll = (Double) obj[6];
int eta = (Integer) obj[7];
double[][] serieslist = (double[][]) obj[8];
double forecast = (Double) obj[9];

updateStatisticBars();
updateChart(serieslist);
Expand Down Expand Up @@ -1264,6 +1269,7 @@ public void onPostExecute(DeckTask.TaskData result) {
} else {
mTextETA.setText("-");
}
mTextAvgDailyLoad.setText(String.valueOf(forecast));

if (mDeckCounts.getVisibility() == View.INVISIBLE) {
mDeckCounts.setVisibility(View.VISIBLE);
Expand Down
5 changes: 3 additions & 2 deletions src/com/ichi2/async/DeckTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,15 @@ private TaskData doInBackgroundUpdateValuesFromDeck(TaskData... params) {
int totalCount = sched.cardCount();
double progressMature = ((double) sched.matureCount()) / ((double) totalCount);
double progressAll = 1 - (((double) (totalNewCount + counts[1])) / ((double) totalCount));
double[][] serieslist = null;
double[][] serieslist = null;
// only calculate stats if necessary
if ((Boolean) obj[1]) {
serieslist = Stats.getSmallDueStats(sched.getCol());
}
double forecast = sched.avgDailyLoad();
return new TaskData(new Object[] { counts[0], counts[1], counts[2],
totalNewCount, totalCount, progressMature, progressAll,
sched.eta(counts), serieslist });
sched.eta(counts), serieslist, forecast });
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundUpdateValuesFromDeck - an error occurred: " + e);
return null;
Expand Down
25 changes: 25 additions & 0 deletions src/com/ichi2/libanki/Sched.java
Original file line number Diff line number Diff line change
Expand Up @@ -2811,4 +2811,29 @@ public int compare(long[] lhs, long[] rhs) {
}
}

/**
* Compute the average cards per day, which is the sum on the inverse of the frequency of the cards.
* For ex: a card with freq=4 day will worth 0.25 card/day
* @return average cards per day
*/
public double avgDailyLoad() {
Cursor cur = null;
try {
cur = mCol
.getDb()
.getDatabase()
.rawQuery(
"select round(sum(1./ivl),2) from cards where did IN "
+ Utils.ids2str(mCol.getDecks().active()) + " and ivl>0 and queue!=-1", null);
if (!cur.moveToFirst()) {
return -1;
}
return cur.getDouble(0);
} finally {
if (cur != null && !cur.isClosed()) {
cur.close();
}
}
}

}