trevorld / Hanzi_Stats

Anki plugin which calculates number of Hanzi you have learned so far.
GNU General Public License v3.0
15 stars 4 forks source link

Add option to look for hanzi in a custom field #6

Closed Karl0912 closed 6 years ago

Karl0912 commented 6 years ago

First of all, great work! I love your modification and the Plugin! I found your just released 2.1 version of that fine work. As you described, it only looks in field 1. Could you either add an option to look in a different field, or point me to the area of code I have to change to only look at field 2 for example. Thank you very much! Again, great work!

trevorld commented 6 years ago

It won't be a priority for me to update the code to use Anki 2.1's new user's' plugin configuration system to determine what field to look in for Hanzi. I'd probably accept a patch that implements such an option assuming that the default behaviour for a user who does no configuration at all is to keep doing what it currently does now (i.e. look in the first field).

It would probably be least work for you to fork the plugin, tweak the code slightly, and manually install your fork to your Anki plugins folder.

The code that grabs the Hanzi to analyze is the function genHanziSets

It uses SQL statements to the Anki database, I don't understand Anki's SQL database all that well but maybe you can figure out how to grab a different field. The current version essentially copies the code that the Chinese Support Plugin uses to identify characters you have added/know. Previously the plugin used the code that was written by Ben and/or Damien and looks for characters in ALL fields. That may be too greedy for you though. Look at this version of the plugin for example of the previous version of the function:

https://github.com/trevorld/Hanzi_Stats/blob/b93f1f29909333e2ec7bf6e6aa4a7e666bc31808/Hanzi_Stats.py

infernalis commented 6 years ago

To add to this, the current implementation doesn't actually go by the 'first' field, it is checking the Sort Field. So, without any code changes you can go to Browse -> Fields, select the field you want and check the "Sort by this field in the browser" and it will generate the statistics using that field.

If you're impatient, you can grab the plugin from #8 that adds the ability to configure this.

trevorld commented 6 years ago

@infernalis 's Pull Request has been merged in which fixes this issue.