View Source AnkiConnect.Actions.Statistic (anki_connect v0.1.1)

Statistic actions.

All functions are delegated inside AnkiConnect module, so you should import them from there.

Link to this section Summary

Functions

Requests all card reviews for a specified deck after a certain time.

Gets the collection statistics report

Returns the unix time of the latest review for the given deck.

Gets the number of cards reviewed as a list of pairs of (dateString, number)

Gets the count of cards that have been reviewed in the current day (with day start time as configured by user in anki)

Requests all card reviews for each card ID.

Inserts the given reviews into the database.

Link to this section Functions

@spec card_reviews(%{deck: String.t(), start_id: integer()}) ::
  {:ok, [[any()]]} | {:error, any()}

Requests all card reviews for a specified deck after a certain time.

start_id is the latest unix time not included in the result.

Returns a list of 9-tuples (reviewTime, cardID, usn, buttonPressed, newInterval, previousInterval, newFactor, reviewDuration, reviewType)

sample-param

Sample param:

%{
  deck: "default",
  start_id: 1594194095740
}

sample-result

Sample result:

[
  [1594194095746, 1485369733217, -1, 3,   4, -60, 2500, 6157, 0],
  [1594201393292, 1485369902086, -1, 1, -60, -60,    0, 4846, 0]
]
Link to this function

get_collection_stats_html(map \\ %{whole_collection: true})

View Source
@spec get_collection_stats_html(%{whole_collection: boolean() | nil}) ::
  {:ok, String.t()} | {:error, any()}

Gets the collection statistics report

sample-param

Sample param:

%{
  whole_collection: true
}

sample-result

Sample result:

{:ok, "<html>...</html>"}
Link to this function

get_latest_review_id(map)

View Source
@spec get_latest_review_id(%{deck: String.t()}) :: {:ok, integer()} | {:error, any()}

Returns the unix time of the latest review for the given deck.

0 if no review has ever been made for the deck.

sample-param

Sample param:

%{
  deck: "default"
}

sample-result

Sample result:

{:ok, 1594194095746}
Link to this function

get_num_cards_reviewed_by_day()

View Source
@spec get_num_cards_reviewed_by_day() :: {:ok, [[any()]]} | {:error, any()}

Gets the number of cards reviewed as a list of pairs of (dateString, number)

sample-result

Sample result:

[
  ["2021-02-28", 124],
  ["2021-02-27", 261]
]
Link to this function

get_num_cards_reviewed_today()

View Source
@spec get_num_cards_reviewed_today() :: {:ok, integer()} | {:error, any()}

Gets the count of cards that have been reviewed in the current day (with day start time as configured by user in anki)

sample-result

Sample result:

{:ok, 0}
Link to this function

get_reviews_of_cards(map)

View Source
@spec get_reviews_of_cards(%{cards: [String.t()]}) :: {:ok, map()} | {:error, any()}

Requests all card reviews for each card ID.

Returns a dictionary mapping each card ID to a list of dictionaries of the format:

{
  "id": reviewTime,
  "usn": usn,
  "ease": buttonPressed,
  "ivl": newInterval,
  "lastIvl": previousInterval,
  "factor": newFactor,
  "time": reviewDuration,
  "type": reviewType,
}

The reason why these key values are used instead of the more descriptive counterparts is because these are the exact key values used in Anki’s database.

sample-param

Sample param:

%{
  cards: [
    "1653613948202"
  ]
}

sample-result

Sample result:

{
  "1653613948202": [
    {
      "id": 1653772912146,
      "usn": 1750,
      "ease": 1,
      "ivl": -20,
      "lastIvl": -20,
      "factor": 0,
      "time": 38192,
      "type": 0
    },
    {
      "id": 1653772965429,
      "usn": 1750,
      "ease": 3,
      "ivl": -45,
      "lastIvl": -20,
      "factor": 0,
      "time": 15337,
      "type": 0
    }
  ]
}
@spec insert_reviews(%{reviews: [[any()]]}) :: {:ok, nil} | {:error, any()}

Inserts the given reviews into the database.

Required format: list of 9-tuples (reviewTime, cardID, usn, buttonPressed, newInterval, previousInterval, newFactor, reviewDuration, reviewType)

sample-param

Sample param:

%{
  reviews: [
    [1594194095746, 1485369733217, -1, 3,   4, -60, 2500, 6157, 0],
    [1594201393292, 1485369902086, -1, 1, -60, -60,    0, 4846, 0]
  ]
}

sample-result

Sample result:

{:ok, nil}