Example #1
0
 private long getRevCard() {
   long id;
   try {
     id = AnkiDb.queryScalar("SELECT id " + "FROM " + revCardTable() + "LIMIT 1");
   } catch (Exception e) {
     return 0;
   }
   return id;
 }
Example #2
0
 private long latestUndoRow() {
   long result;
   try {
     result = AnkiDb.queryScalar("SELECT MAX(rowid) FROM undoLog");
   } catch (SQLException e) {
     result = 0;
   }
   return result;
 }
Example #3
0
 private long getCardId() {
   long id;
   // Failed card due?
   if ((delay0 != 0) && (failedNowCount != 0))
     return AnkiDb.queryScalar("SELECT id FROM failedCards LIMIT 1");
   // Failed card queue too big?
   if ((failedCardMax != 0) && (failedSoonCount >= failedCardMax))
     return AnkiDb.queryScalar("SELECT id FROM failedCards LIMIT 1");
   // Distribute new cards?
   if (timeForNewCard()) {
     id = maybeGetNewCard();
     if (id != 0) return id;
   }
   // Card due for review?
   if (revCount != 0) return getRevCard();
   // New cards left?
   id = maybeGetNewCard();
   if (id != 0) return id;
   // Review ahead?
   if (reviewEarly) {
     id = getCardIdAhead();
     if (id != 0) return id;
     else {
       resetAfterReviewEarly();
       checkDue();
     }
   }
   // Display failed cards early/last
   if (showFailedLast()) {
     try {
       id = AnkiDb.queryScalar("SELECT id FROM failedCards LIMIT 1");
     } catch (Exception e) {
       return 0;
     }
     return id;
   }
   return 0;
 }
Example #4
0
 private long getCardIdAhead() {
   long id = 0;
   try {
     id =
         AnkiDb.queryScalar(
             "SELECT id "
                 + "FROM cards "
                 + "WHERE type = 1 and "
                 + "isDue = 0 and "
                 + "priority in (1,2,3,4) "
                 + "ORDER BY combinedDue "
                 + "LIMIT 1");
   } catch (SQLException e) {
     return 0;
   }
   return id;
 }
Example #5
0
 private boolean timeForNewCard() {
   if (newCardSpacing == NEW_CARDS_LAST) return false;
   if (newCardSpacing == NEW_CARDS_FIRST) return true;
   // Force old if there are very high priority cards
   try {
     AnkiDb.queryScalar(
         "SELECT 1 "
             + "FROM cards "
             + "WHERE type = 1 and "
             + "isDue = 1 and "
             + "priority = 4 "
             + "LIMIT 1");
   } catch (Exception e) { // No result from query.
     if (newCardModulus == 0) return false;
     else return (dailyStats.reps % newCardModulus) == 0;
   }
   return false;
 }
Example #6
0
  private void rebuildCounts(boolean full) {
    Log.i(TAG, "rebuildCounts - Rebuilding global and due counts...");
    // Need to check due first, so new due cards are not added later
    checkDue();
    // Global counts
    if (full) {
      cardCount = (int) AnkiDb.queryScalar("SELECT count(id) FROM cards");
      factCount = (int) AnkiDb.queryScalar("SELECT count(id) FROM facts");
    }

    // Due counts
    failedSoonCount = (int) AnkiDb.queryScalar("SELECT count(id) FROM failedCards");
    failedNowCount =
        (int)
            AnkiDb.queryScalar(
                "SELECT count(id) "
                    + "FROM cards "
                    + "WHERE type = 0 and "
                    + "isDue = 1 and "
                    + "combinedDue <= "
                    + String.format(
                        ENGLISH_LOCALE, "%f", (double) (System.currentTimeMillis() / 1000.0)));
    revCount =
        (int)
            AnkiDb.queryScalar(
                "SELECT count(id) "
                    + "FROM cards "
                    + "WHERE type = 1 and "
                    + "priority in (1,2,3,4) and "
                    + "isDue = 1");
    newCount =
        (int)
            AnkiDb.queryScalar(
                "SELECT count(id) "
                    + "FROM cards "
                    + "WHERE type = 2 and "
                    + "priority in (1,2,3,4) and "
                    + "isDue = 1");
  }
Example #7
0
  /** Mark expired cards due and update counts. */
  private void checkDue() {
    Log.i(TAG, "Checking due cards...");
    checkDailyStats();

    // Failed cards
    ContentValues val = new ContentValues(1);
    val.put("isDue", 1);

    failedSoonCount +=
        AnkiDb.database.update(
            "cards",
            val,
            "type = 0 and "
                + "isDue = 0 and "
                + "priority in (1,2,3,4) and "
                + String.format(
                    ENGLISH_LOCALE,
                    "combinedDue <= %f",
                    (double) ((System.currentTimeMillis() / 1000.0) + delay0)),
            null);

    failedNowCount =
        (int)
            AnkiDb.queryScalar(
                "SELECT count(id) "
                    + "FROM cards "
                    + "WHERE type = 0 and "
                    + "isDue = 1 and "
                    + String.format(
                        ENGLISH_LOCALE,
                        "combinedDue <= %f",
                        (double) (System.currentTimeMillis() / 1000.0)));

    // Review
    val.clear();
    val.put("isDue", 1);
    revCount +=
        AnkiDb.database.update(
            "cards",
            val,
            "type = 1 and "
                + "isDue = 0 and "
                + "priority in (1,2,3,4) and "
                + String.format(
                    ENGLISH_LOCALE,
                    "combinedDue <= %f",
                    (double) (System.currentTimeMillis() / 1000.0)),
            null);

    // New
    val.clear();
    val.put("isDue", 1);
    newCount +=
        AnkiDb.database.update(
            "cards",
            val,
            "type = 2 and "
                + "isDue = 0 and "
                + "priority in (1,2,3,4) and "
                + String.format(
                    ENGLISH_LOCALE,
                    "combinedDue <= %f",
                    (double) (System.currentTimeMillis() / 1000.0)),
            null);

    newCountToday = Math.max(Math.min(newCount, newCardsPerDay - newCardsToday()), 0);
  }