Hello,
I am learning Japanese and flag all words where I know all kanji as purple, all words that don’t contain kanji as blue and the rest are unflagged. I would really like to add another pie diagram to the statistics of the deck that would have unseen, seen but unflagged, purple and blue as metrics. I tried to include a new config file into a new folder in addons21, but then startup fails.
Code of the new config file:
from aqt import mw
from aqt.gui_hooks import stats_did_load
def get_counts(did):
db = mw.col.db
new_count = db.scalar(
"SELECT COUNT() FROM cards WHERE did=? AND type=0 AND flags=0", did
) or 0
flag1 = db.scalar(
"SELECT COUNT() FROM cards WHERE did=? AND flags=1", did
) or 0
flag2 = db.scalar(
"SELECT COUNT() FROM cards WHERE did=? AND flags=2", did
) or 0
flag3 = db.scalar(
"SELECT COUNT() FROM cards WHERE did=? AND flags=3", did
) or 0
flag4 = db.scalar(
"SELECT COUNT() FROM cards WHERE did=? AND flags=4", did
) or 0
return new_count, flag1, flag2, flag3, flag4
def on_stats_loaded(web_content, context):
if not hasattr(context, “deck_id”):
return
did = context.deck_id
new_count, f1, f2, f3, f4 = get_counts(did)
html = f"""
<h2>Custom Flag Pie Chart</h2>
<canvas id="flagChart" width="300" height="300"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const data = {{
labels: ["Not Seen", "Flag 1", "Flag 2", "Flag 3", "Flag 4"],
datasets: [{{
data: [{new_count}, {f1}, {f2}, {f3}, {f4}],
backgroundColor: ["gray", "red", "orange", "green", "blue"]
}}]
}};
new Chart(document.getElementById("flagChart"), {{
type: "pie",
data: data
}});
</script>
"""
web_content.body += html
stats_did_load.append(on_stats_loaded)


