Commit graph

66 commits

Author SHA1 Message Date
Al Ali
64e2ff3cc5 Add streak display to overview window 2025-06-16 18:22:18 +02:00
David Culley
283a23a310 refactor: use not in and is not as recommended (#3351)
- https://docs.astral.sh/ruff/rules/not-is-test/
- https://docs.astral.sh/ruff/rules/not-in-test/
2024-08-10 17:55:26 +07:00
David Culley
8ba6b28970 Improve exception handling (#3290)
* fix: except only non-system-exiting exceptions

see https://youtu.be/zrVfY9SuO64

* chore: add myself to CONTRIBUTORS file

* refactor: explicitly specify possible exceptions

If an exception is not an Exception, there are only three options left.
see https://docs.python.org/3/library/exceptions.html#exception-hierarchy

* refactor: use BaseException for fallback

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* chore: add myself to contributors
2024-08-04 20:51:13 +07:00
David Culley
5be8f423f2 Update type annotation syntax (#3283)
* chore: add myself to CONTRIBUTORS file

* refactor: use newer type hints for Union/Optional

* refactor: fix deprecated type annotations

use collections.abc rather than typing

* refactor: use lower letter type annotations

* style: reformat with black

* refactor: remove unused imports

* refactor: add missing imports for type hints

* fixup! refactor: use newer type hints for Union/Optional

* fix: add missing imports for type annotations

* fixup! refactor: use newer type hints for Union/Optional

* fixup! style: reformat with black

* refactor: fix remaining imports re: type hints
2024-07-21 14:00:52 +07:00
Damien Elmes
74d7397a6e Bump Python deps
A few tweaks were required for PyLint
2024-07-06 18:40:37 +07:00
user1823
a834aedae9 Ignore rescheduled cards in old stats page (#2863)
* Ignore rescheduled cards in old stats page

Rescheduled cards are not actual reviews. So, including them in Cards Studied Today is inappropriate.

* Simplify SQL query

* Fix Answer Buttons graph

* Fix error

* Potentially fix error
2023-12-05 09:55:33 +10:00
Abdo
10966394fd Remove v1/v2 support from the backend (#2727)
* Remove v1/v2 support from deck list

* Remove v1/v2 support from most routines and show error

* Remove scheduler_version from preferences

* Fix formatting

* Remove v1/v2 conditionals from Python code

* Fix legacy importer

* Remove legacy hooks

* Add missing scheduler checks

* Remove V2 logic from deck options screen

* Remove the review_did_undo hook

* Restore ability to open old options with shift (dae)
2023-10-14 10:50:59 +10:00
Damien Elmes
76daff6b6d Update Python deps
- Black's formatting has changed
- Pylint has introduced a new lint
2023-03-31 14:04:05 +10:00
Matthias Metelka
ffa3e1e0b3 Fix some more RTL issues (#2244)
* Swap flag and mark indicator position in RTL mode

* Make buttons of bottom toolbar align to edge of screen in RTL mode

* Use start instead of left and end instead of right
2022-12-08 22:29:56 +10:00
Damien Elmes
511ba5ebe4 Add back support for custom mountpoint in card stats
The move to separate .html files broke our legacy card stats routine.

Related: 1c5077ab45
2022-04-15 15:30:05 +10:00
Damien Elmes
f4a220e73b update mypy and mypy-protobuf
- The way mypy gathers site packages has changed slightly, so we had to
update extendsitepkgs.py to work with it.
- Not sure if there's a way to avoid the ignore in
operations/__init__.py. mypy is still ensuring a provided argument has
a .changes attribute, so thankfully we don't seem to have lost much here.
2022-01-15 16:04:04 +10:00
RumovZ
e37ccfdfa3 PEP8 pylib (#1443)
* PEP8 scheduler/base.py

* PEP8 _backend/__init__.py

* PEP8 _backend/genbackend.py

* PEP8 _backend/genfluent.py

* PEP8 scheduler/__init__.py

* PEP8 __init__.py

* PEP8 _legacy.py

* PEP8 syncserver/__init__.py

- Make 'ip' a good name
- Overrule `global col` being identified as a constant

* PEP8 syncserver/__main__.py

* PEP8 buildinfo.py

* Implement `DeprecatedNamesMixin` for modules

* PEP8 browser.py

* PEP8 config.py

* PEP8 consts.py

* PEP8 db.py

* Format

* Improve AttributeError for DeprecatedNamesMixin

* print the line that imported/referenced the legacy module attr (dae)

* DeprecatedNamesMixinStandalone -> ...ForModule
2021-10-22 20:39:49 +10:00
RumovZ
d0859fa665 Format 2021-10-18 09:01:25 +02:00
RumovZ
f0512de406 Fix _legacy_card_stats() 2021-10-18 09:01:25 +02:00
RumovZ
ea9fc3730e Switch CardInfoDialog to ts page (#1414)
* Only collect card stats on the backend ...

... instead of rendering an HTML string using askama.

* Add ts page Card Info

* Update test for new `col.card_stats()`

* Remove obsolete CardStats code

* Use new ts page in `CardInfoDialog`

* Align start and end instead of left and right

Curiously, `text-align: start` does not work for `th` tags if assigned
via classes.

* Adopt ts refactorings after rebase

#1405 and #1409

* Clean up `ts/card-info/BUILD.bazel`

* Port card info logic from Rust to TS

* Move repeated field to the top

https://github.com/ankitects/anki/pull/1414#discussion_r725402730

* Convert pseudo classes to interfaces

* CardInfoPage -> CardInfo

* Make revlog in card info optional

* Add legacy support for old card stats

* Check for undefined instead of falsy

* Make Revlog separate component

* drop askama dependency (dae)

* Fix nightmode for legacy card stats
2021-10-14 19:22:47 +10:00
Damien Elmes
3c1729e91b run pyupgrade over codebase [python upgrade required]
This adds Python 3.9 and 3.10 typing syntax to files that import
attributions from __future___. Python 3.9 should be able to cope with
the 3.10 syntax, but Python 3.8 will no longer work.

On Windows/Mac, install the latest Python 3.9 version from python.org.
There are currently no orjson wheels for Python 3.10 on Windows/Mac,
which will break the build unless you have Rust installed separately.

On Linux, modern distros should have Python 3.9 available already. If
you're on an older distro, you'll need to build Python from source first.
2021-10-04 15:05:48 +10:00
Damien Elmes
e86e0a64ea move proto files into separate py_library in same namespace
Will allow importing the Protobuf without pulling in the rest of
the library. This is not a full PEP420 namespace, and the wheel still
bundles everything - it just makes things easier in a Bazel workspace.
I originally tried with PEP420, but it required more invasive changes,
and I ran into issues with mypy.
2021-07-11 14:51:25 +10:00
Damien Elmes
f9560586cb PEP8 collection.py 2021-06-27 15:12:22 +10:00
Damien Elmes
b912b2d145 enable some pylint convention tests in pylib 2021-06-26 10:11:05 +10:00
Damien Elmes
0e50259e6b update TR references with args in *.ts; fix average answer time 2021-03-26 19:10:39 +10:00
Damien Elmes
3d0e5248aa update TR references that crossed multiple lines 2021-03-26 14:38:15 +10:00
Damien Elmes
5d164bea7f update TR references that contain arguments 2021-03-26 14:21:04 +10:00
Damien Elmes
40a4b29214 use top level defs for protobuf enum cases
While mypy can understand nested references like ConfigBool.Key.COLLAPSE_RECENT,
PyCharm doesn't understand the metaclass syntax, and shows the definitions
as invalid.
2021-02-05 19:26:13 +10:00
Damien Elmes
5114fde01c add more typing, and enable checks for missing types for most of pylib 2021-01-31 21:38:36 +10:00
Damien Elmes
01fb95719f make backend instance on col private 2021-01-31 18:56:16 +10:00
Damien Elmes
a6be0f493b start work on more clearly defining backend/protobuf boundaries
- anki._backend stores the protobuf files and rsbackend.py code
- pylib modules import protobuf messages directly from the
_pb2 files, and explicitly export any will be returned or consumed
by public pylib functions, so that calling code can import from pylib
- the "rsbackend" no longer imports and re-exports protobuf messages
- pylib can just consume them directly.
- move errors to errors.py

Still todo:

- rsbridge
- finishing the work on rsbackend, and check what we need to add
back to the original file location to avoid breaking add-ons
2021-01-31 18:55:45 +10:00
Damien Elmes
346ec6880e drop i18n references in old stats 2020-11-18 09:12:03 +10:00
Damien Elmes
366c5c4774 log manual reschedule, but ignore the log entry in the stats 2020-09-02 17:56:23 +10:00
Damien Elmes
0f6840596b fix night mode on old graphs 2020-09-02 17:56:12 +10:00
Damien Elmes
8729edffbb update to latest black 2020-08-31 13:29:28 +10:00
Damien Elmes
39272c436e force old graphs to use ltr
otherwise the axis labels are way off

https://forums.ankiweb.net/t/anki-2-1-29-beta/1220/8
2020-07-22 14:30:56 +10:00
Damien Elmes
f5694a7e4a migrate card stats to backend
Currently this renders the HTML directly like the previous Python
implementation - doing it in JS would probably make more sense in the
future.
2020-06-15 17:22:16 +10:00
Damien Elmes
e9fea26d1c use keyword args for calls with more than one argument 2020-05-24 09:12:47 +10:00
Damien Elmes
bbcc566e6d migrate the remaining methods 2020-05-24 08:36:50 +10:00
Damien Elmes
99462e39b8 fix deck age being used instead of collection
https://anki.tenderapp.com/discussions/ankidesktop/41637-bug-in-statistics
2020-05-20 19:46:01 +10:00
Damien Elmes
068cc43095 storage->collection 2020-05-20 17:58:28 +10:00
Damien Elmes
245a31a432 tweak code for mypy 2020-03-26 17:47:53 +10:00
Damien Elmes
9e67ea736a drop named sql arguments 2020-03-20 21:15:23 +10:00
Damien Elmes
9a9265f113 don't error when an add-on passes None to CardStats
https://anki.tenderapp.com/discussions/beta-testing/1842-syncing-message
2020-03-11 15:18:28 +10:00
Damien Elmes
0dc4886558 add col.weakref() and fix more reference cycles in pylib 2020-03-05 09:47:47 +10:00
Alan Du
c74ccbe245 Monkeytype pylib/anki/stats.py 2020-02-27 00:07:19 -05:00
Damien Elmes
5d09981667 add self.col.tr() shortcut 2020-02-27 12:33:15 +10:00
Damien Elmes
93c2e04267 FString -> TR 2020-02-27 12:25:19 +10:00
Damien Elmes
59328d9ade tweak rounding
- avoid rounding minutes
- round the seconds taken in the card info screen
- provide different precise and imprecise modes, since we need
to display seconds to multiple decimals in some areas
2020-02-25 17:29:06 +10:00
Damien Elmes
70ae99778f remove old fmtTimeSpan() and associated strings 2020-02-23 18:47:16 +10:00
Damien Elmes
0d1a30c6d8 rework Fluent handling
- all .ftl files for a language are concatenated into a single file
at build time
- all languages are included in the binary
- external ftl files placed in the ftl folder can override the
built-in definitions
- constants are automatically generated for each string key
- dropped the separate StringsGroup enum
2020-02-23 13:22:50 +10:00
Damien Elmes
e5fa1759b3 formatting fix 2020-02-21 21:21:36 +10:00
Damien Elmes
abc260b7c3 reviews 2020-02-21 20:36:22 +10:00
Damien Elmes
3a83d9844a add studied_today(), move to statistics.ftl 2020-02-21 18:01:15 +10:00
Damien Elmes
e3e376036f add average-answer-time to Fluent
drop the 0.1 special case; we're using two decimals now
2020-02-21 17:42:55 +10:00