Search in sources :

Example 51 with Deck

use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.

the class Decks method active.

/**
 * Deck selection
 * ***********************************************************
 */
/**
 * The currently active dids. Make sure to copy before modifying.
 */
public LinkedList<Long> active() {
    JSONArray activeDecks = mCol.getConf().getJSONArray("activeDecks");
    LinkedList<Long> result = new LinkedList<>();
    for (int i = 0; i < activeDecks.length(); i++) {
        result.add(activeDecks.getLong(i));
    }
    return result;
}
Also used : JSONArray(com.ichi2.utils.JSONArray) LinkedList(java.util.LinkedList)

Example 52 with Deck

use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.

the class Decks method flush.

public void flush() {
    ContentValues values = new ContentValues();
    if (mChanged) {
        JSONObject decksarray = new JSONObject();
        for (Map.Entry<Long, Deck> d : mDecks.entrySet()) {
            decksarray.put(Long.toString(d.getKey()), d.getValue());
        }
        values.put("decks", Utils.jsonToString(decksarray));
        JSONObject confarray = new JSONObject();
        for (Map.Entry<Long, DeckConfig> d : mDconf.entrySet()) {
            confarray.put(Long.toString(d.getKey()), d.getValue());
        }
        values.put("dconf", Utils.jsonToString(confarray));
        mCol.getDb().update("col", values);
        mChanged = false;
    }
}
Also used : ContentValues(android.content.ContentValues) JSONObject(com.ichi2.utils.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 53 with Deck

use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.

the class AdvancedStatistics method calculateDueAsMetaInfo.

/**
 * Determine forecast statistics based on a computation or simulation of future reviews.
 * Returns all information required by stats.java to plot the 'forecast' chart based on these statistics.
 * The chart will display:
 * - The forecasted number of reviews per review type (relearn, mature, young, learn) as bars
 * - The forecasted number of cards in each state (new, young, mature) as lines
 * @param metaInfo Object which will be filled with all information required by stats.java to plot the 'forecast' chart and returned by this method.
 * @param type Type of 'forecast' chart for which to determine forecast statistics. Accepted values:
 *             Stats.TYPE_MONTH: Determine forecast statistics for next 30 days with 1-day chunks
 *             Stats.TYPE_YEAR:  Determine forecast statistics for next year with 7-day chunks
 *             Stats.TYPE_LIFE:  Determine forecast statistics for next 2 years with 30-day chunks
 * @param context Contains The collection which contains the decks to be simulated.
 *             Also used for access to the database and access to the creation time of the collection.
 *             The creation time of the collection is needed since due times of cards are relative to the creation time of the collection.
 *             So we could pass mCol here.
 * @param dids Deck id's
 * @return @see #metaInfo
 */
public StatsMetaInfo calculateDueAsMetaInfo(StatsMetaInfo metaInfo, Stats.AxisType type, Context context, String dids) {
    if (!AnkiDroidApp.getSharedPrefs(context).getBoolean("advanced_statistics_enabled", false)) {
        return metaInfo;
    }
    // To indicate that we calculated the statistics so that Stats.java knows that it shouldn't display the standard Forecast chart.
    Settings = new Settings(context);
    metaInfo.setStatsCalculated(true);
    Collection mCol = CollectionHelper.getInstance().getCol(context);
    double[][] mSeriesList;
    int[] mValueLabels;
    int[] mColors;
    int[] mAxisTitles;
    int mMaxCards = 0;
    int mMaxElements;
    double mFirstElement;
    double mLastElement = 0;
    int mZeroIndex = 0;
    double[][] mCumulative;
    double mMcount;
    mValueLabels = new int[] { R.string.statistics_relearn, R.string.statistics_mature, R.string.statistics_young, R.string.statistics_learn };
    mColors = new int[] { R.attr.stats_relearn, R.attr.stats_mature, R.attr.stats_young, R.attr.stats_learn };
    mAxisTitles = new int[] { type.ordinal(), R.string.stats_cards, R.string.stats_cumulative_cards };
    PlottableSimulationResult simuationResult = calculateDueAsPlottableSimulationResult(type, mCol, dids);
    ArrayList<int[]> dues = simuationResult.getNReviews();
    mSeriesList = new double[REVIEW_TYPE_COUNT_PLUS_1][dues.size()];
    for (int t = 0; t < dues.size(); t++) {
        int[] data = dues.get(t);
        int nReviews = data[REVIEW_TYPE_LEARN_PLUS_1] + data[REVIEW_TYPE_YOUNG_PLUS_1] + data[REVIEW_TYPE_MATURE_PLUS_1] + data[REVIEW_TYPE_RELEARN_PLUS_1];
        if (nReviews > mMaxCards)
            // Y-Axis: Max. value
            mMaxCards = nReviews;
        // In the bar-chart, the bars will be stacked on top of each other.
        // For the i^{th} bar counting from the bottom we therefore have to
        // provide the sum of the heights of the i^{th} bar and all bars below it.
        // X-Axis: Day / Week / Month
        mSeriesList[TIME][t] = data[TIME];
        mSeriesList[REVIEW_TYPE_LEARN_PLUS_1][t] = data[REVIEW_TYPE_LEARN_PLUS_1] + data[REVIEW_TYPE_YOUNG_PLUS_1] + data[REVIEW_TYPE_MATURE_PLUS_1] + // Y-Axis: # Cards
        data[REVIEW_TYPE_RELEARN_PLUS_1];
        mSeriesList[REVIEW_TYPE_YOUNG_PLUS_1][t] = data[REVIEW_TYPE_LEARN_PLUS_1] + data[REVIEW_TYPE_YOUNG_PLUS_1] + // Y-Axis: # Mature cards
        data[REVIEW_TYPE_MATURE_PLUS_1];
        mSeriesList[REVIEW_TYPE_MATURE_PLUS_1][t] = data[REVIEW_TYPE_LEARN_PLUS_1] + // Y-Axis: # Young
        data[REVIEW_TYPE_YOUNG_PLUS_1];
        // Y-Axis: # Learn
        mSeriesList[REVIEW_TYPE_RELEARN_PLUS_1][t] = data[REVIEW_TYPE_LEARN_PLUS_1];
        if (data[TIME] > mLastElement)
            // X-Axis: Max. value (only for TYPE_LIFE)
            mLastElement = data[TIME];
        if (data[TIME] == 0) {
            // Because we retrieve dues in the past and we should not cumulate them
            mZeroIndex = t;
        }
    }
    // # X values
    mMaxElements = dues.size() - 1;
    switch(type) {
        case TYPE_MONTH:
            // X-Axis: Max. value
            mLastElement = 31;
            break;
        case TYPE_YEAR:
            // X-Axis: Max. value
            mLastElement = 52;
            break;
        default:
    }
    // X-Axis: Min. value
    mFirstElement = 0;
    // Day starting at mZeroIndex, Cumulative # cards
    mCumulative = simuationResult.getNInState();
    mMcount = // Y-Axis: Max. cumulative value
    mCumulative[CARD_TYPE_NEW_PLUS_1][mCumulative[CARD_TYPE_NEW_PLUS_1].length - 1] + mCumulative[CARD_TYPE_YOUNG_PLUS_1][mCumulative[CARD_TYPE_YOUNG_PLUS_1].length - 1] + mCumulative[CARD_TYPE_MATURE_PLUS_1][mCumulative[CARD_TYPE_MATURE_PLUS_1].length - 1];
    // some adjustments to not crash the chartbuilding with empty data
    if (mMaxElements == 0) {
        mMaxElements = 10;
    }
    if (mMcount == 0) {
        mMcount = 10;
    }
    if (mFirstElement == mLastElement) {
        mFirstElement = 0;
        mLastElement = 6;
    }
    if (mMaxCards == 0)
        mMaxCards = 10;
    metaInfo.setmDynamicAxis(true);
    metaInfo.setmHasColoredCumulative(true);
    metaInfo.setmType(type);
    metaInfo.setmTitle(R.string.stats_forecast);
    metaInfo.setmBackwards(true);
    metaInfo.setmValueLabels(mValueLabels);
    metaInfo.setmColors(mColors);
    metaInfo.setmAxisTitles(mAxisTitles);
    metaInfo.setmMaxCards(mMaxCards);
    metaInfo.setmMaxElements(mMaxElements);
    metaInfo.setmFirstElement(mFirstElement);
    metaInfo.setmLastElement(mLastElement);
    metaInfo.setmZeroIndex(mZeroIndex);
    metaInfo.setmCumulative(mCumulative);
    metaInfo.setmMcount(mMcount);
    metaInfo.setmSeriesList(mSeriesList);
    metaInfo.setDataAvailable(dues.size() > 0);
    return metaInfo;
}
Also used : Collection(com.ichi2.libanki.Collection)

Example 54 with Deck

use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _deckNewLimitSingle.

/**
 * Maximal number of new card still to see today in deck g. It's computed as:
 * the number of new card to see by day according to the deck optinos
 * minus the number of new cards seen today in deck d or a descendant
 * plus the number of extra new cards to see today in deck d, a parent or a descendant.
 *
 * Limits of its ancestors are not applied, current card is not treated differently.
 */
public int _deckNewLimitSingle(@NonNull Deck g) {
    if (g.getInt("dyn") != 0) {
        return mDynReportLimit;
    }
    long did = g.getLong("id");
    @NonNull DeckConfig c = mCol.getDecks().confForDid(did);
    int lim = Math.max(0, c.getJSONObject("new").getInt("perDay") - g.getJSONArray("newToday").getInt(1));
    // So currentCard does not have to be taken into consideration in this method
    if (currentCardIsInQueueWithDeck(Consts.QUEUE_TYPE_NEW, did)) {
        lim--;
    }
    return lim;
}
Also used : NonNull(androidx.annotation.NonNull) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 55 with Deck

use of com.ichi2.libanki.Deck in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _updateCutoff.

/**
 * Daily cutoff ************************************************************* **********************************
 * This function uses GregorianCalendar so as to be sensitive to leap years, daylight savings, etc.
 */
/* Overriden: other way to count time*/
public void _updateCutoff() {
    Integer oldToday = mToday == null ? 0 : mToday;
    // days since col created
    mToday = _daysSinceCreation();
    // end of day cutoff
    mDayCutoff = _dayCutoff();
    if (oldToday != mToday) {
        mCol.log(mToday, mDayCutoff);
    }
    // instead
    for (Deck deck : mCol.getDecks().all()) {
        update(deck);
    }
    // unbury if the day has rolled over
    int unburied = mCol.getConf().optInt("lastUnburied", 0);
    if (unburied < mToday) {
        SyncStatus.ignoreDatabaseModification(this::unburyCards);
        mCol.getConf().put("lastUnburied", mToday);
    }
}
Also used : Deck(com.ichi2.libanki.Deck)

Aggregations

Deck (com.ichi2.libanki.Deck)100 Collection (com.ichi2.libanki.Collection)97 JSONObject (com.ichi2.utils.JSONObject)88 Test (org.junit.Test)80 JSONArray (com.ichi2.utils.JSONArray)55 Card (com.ichi2.libanki.Card)53 Note (com.ichi2.libanki.Note)50 ArrayList (java.util.ArrayList)47 RobolectricTest (com.ichi2.anki.RobolectricTest)44 DeckConfig (com.ichi2.libanki.DeckConfig)37 JSONException (com.ichi2.utils.JSONException)34 NonNull (androidx.annotation.NonNull)30 HashMap (java.util.HashMap)29 Model (com.ichi2.libanki.Model)23 Map (java.util.Map)22 Intent (android.content.Intent)21 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 SharedPreferences (android.content.SharedPreferences)17 Cursor (android.database.Cursor)17