App Data¶
Source: data/app_data.py
Catalog helpers, load/save for set CSVs (content cells kept as text), empty-set
construction, Home-tile progress (get_set_learn_progress), and the
in-memory AppData learning session. Storage layout is in
Data and storage. Queue rules and
answer transitions are in
Learning algorithm.
Catalog CRUD, set load/save helpers, and in-memory learning sessions.
Module-level functions manage files.csv and set CSVs on disk through
FilePathManager. AppData loads one set for a learn session, draws
practice groups from statistics columns, and persists answers with save_set.
AppData ¶
In-memory learning session over one set CSV.
Loads the set, draws practice index groups from statistics columns, and saves progress after each answer. Catalog and empty-set helpers remain module-level functions outside this class.
Attributes:
| Name | Type | Description |
|---|---|---|
last_group_of_indexes |
Class-level list of indexes from the last drawn
group when |
|
words |
Loaded set DataFrame. |
|
file_name |
Set path or basename used for load/save. |
|
kind |
|
Source code in src/learning_app/data/app_data.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 | |
draw_index_group ¶
Draw row indexes for the next practice group.
The group is capped by this set's queue size. An empty catalog cell
uses the Settings size for this kind. Word formations
(kind == "words") use 3–10 items, default 5. Definitions use
4–15 items, default 10. An already drawn group is left unchanged
until this method runs again.
Prefers word_to_learn rows, then fills from other statistics
combinations ordered by correct_answers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_indexes_in_class_art
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
int
|
Number of indexes in the new group, or |
int
|
available. |
Source code in src/learning_app/data/app_data.py
draw_new_row ¶
Advance to the next index in the current practice group.
get_current_row ¶
get_current_words_list ¶
colnames_in_WordFields ¶
Return content column names for the current row (no stats).
good_answer_at_current_row ¶
Record a correct answer, update statistics flags, and save the set.
Source code in src/learning_app/data/app_data.py
bad_answer_at_current_row ¶
Record an incorrect answer, mark the row to learn, and save the set.
Source code in src/learning_app/data/app_data.py
it_is_not_last_index_of_group ¶
number_of_known_words ¶
Count rows in the fully learned statistics state.
Source code in src/learning_app/data/app_data.py
number_of_learning_words ¶
Count rows that are actively in the learning queue.
Source code in src/learning_app/data/app_data.py
number_of_all_words ¶
are_all_words_learned ¶
Return whether every row is in the fully learned state.
refresh ¶
was_this_index_drawn
classmethod
¶
Return whether index was in the last saved practice group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Row index to look up in |
required |
Source code in src/learning_app/data/app_data.py
delete_last_group_of_indexes
classmethod
¶
colnames_with_nan ¶
Return content column names that are empty on the current words row.
Raises:
| Type | Description |
|---|---|
Exception
|
If the loaded set is not a words set. |
Source code in src/learning_app/data/app_data.py
create_data_file_words
staticmethod
¶
Create an empty set CSV and register it in the catalog.
Despite the historical name, file_name may be a words or
definitions set; the kind is taken from the suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Target basename ending in |
required |
title
|
str
|
Catalog title. |
required |
subtitle
|
str
|
Optional catalog subtitle. |
''
|
Source code in src/learning_app/data/app_data.py
read_catalog_csv ¶
Read files.csv, treating only blank cells as missing.
Pandas' default NA list would turn catalog text such as None,
null, or NA into missing values. Empty cells still become NA
so blank titles fail validation and blank subtitles stay empty.
Source code in src/learning_app/data/app_data.py
ensure_files_catalog_columns ¶
Ensure catalog DataFrame has usage/creation columns; optionally rewrite CSV.
Missing columns are added with defaults. Rows missing created_at get
stable timestamps in existing row order so creation sort matches historical
append order. Older catalogs without usage fields get empty last_used
and use_count of 0. Per-set setting columns are added empty so a
set keeps using the app defaults until someone stores an override.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame | None
|
Catalog table to migrate. When |
None
|
persist
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Catalog DataFrame with the full column set. |
Source code in src/learning_app/data/app_data.py
sort_catalog_entries ¶
sort_catalog_entries(
entries: list[dict], sort_mode: SetSortMode
) -> list[dict]
Return catalog entry dicts ordered by sort_mode.
Source code in src/learning_app/data/app_data.py
get_kind_of_file_and_validate ¶
Return "words" or "definitions" from a set file name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Path or basename ending in |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
If the name does not use a supported suffix. |
Source code in src/learning_app/data/app_data.py
read_set_csv ¶
Read a set CSV, treating only blank cells as missing.
Pandas' default NA list would turn user text such as nan, None,
or NA into missing values. Empty cells still become NA so unused
parts-of-speech fields stay empty. Statistics columns keep inferred
numeric/bool dtypes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path to the set CSV. |
required |
index_col
|
int | str | None
|
Passed to |
0
|
Source code in src/learning_app/data/app_data.py
stringify_content_columns ¶
Coerce learning-content cells to strings after CSV type inference.
Pandas reads a column of digits as int64/float64. Edit and learn
UIs then treat those cells as empty or call len/split on numbers.
Statistics columns are left unchanged; missing content stays NA.
Source code in src/learning_app/data/app_data.py
save_set ¶
Write a set DataFrame to the CSV directory, keeping the index column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Set table to persist. |
required |
file_name
|
str
|
Set basename or path resolved by |
required |
prune_tts
|
bool
|
When |
False
|
Source code in src/learning_app/data/app_data.py
load_set ¶
Load a set CSV with the first column as the DataFrame index.
Content columns are coerced to strings so numeric-looking cells (123)
stay text. Words that look like pandas NA sentinels (nan, None,
NA) stay as written. Missing content stays NA; statistics columns
keep inferred numeric/bool dtypes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path resolved by |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded set table. |
Source code in src/learning_app/data/app_data.py
set_file_exists ¶
Return whether the set CSV exists on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path resolved by |
required |
Source code in src/learning_app/data/app_data.py
sanitize_file_name ¶
Build a safe set basename with the given kind suffix.
Non-alphanumeric characters are stripped before _{kind}.csv is
appended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Raw title or stem supplied by the user. |
required |
kind
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
str
|
Basename such as |
Source code in src/learning_app/data/app_data.py
get_file_names_and_titles ¶
get_file_names_and_titles(
sort_mode: SetSortMode = LAST_USED,
) -> list[dict]
Return catalog entries with absolute CSV paths, titles, and metadata.
Creates an empty files.csv when the catalog is missing and migrates
older catalogs that lack creation/usage columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sort_mode
|
SetSortMode
|
Ordering applied before returning entries. |
LAST_USED
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of dicts with |
list[dict]
|
|
list[dict]
|
|
Source code in src/learning_app/data/app_data.py
get_file_names ¶
Return basenames listed in files.csv.
Creates an empty catalog when missing.
Returns:
| Type | Description |
|---|---|
list
|
List of set file basenames. |
Source code in src/learning_app/data/app_data.py
generate_empty_files_data ¶
Create an empty files.csv catalog with the expected columns.
Source code in src/learning_app/data/app_data.py
set_default_progress ¶
Reset learning statistics on an existing set without removing content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path to reload and save. |
required |
Source code in src/learning_app/data/app_data.py
get_set_learn_progress ¶
Return weighted learn progress without starting a learn session.
Matches the learn-menu bar: Known rows count as 1, rows still in the
learning mix (Learned / queued) count as 0.25, and unverified
0/0/0 rows count as 0. Values are stored in quarters so callers
can use units / max_units the same way WordListMenu does
(known * 4 + learning * 1 over total * 4).
Missing files or unreadable tables return (0, 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path resolved by |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
|
Source code in src/learning_app/data/app_data.py
delate_set ¶
Remove a set from the catalog and optionally delete its CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path whose basename is matched in the catalog. |
required |
file_not_exist
|
bool
|
When |
False
|
Source code in src/learning_app/data/app_data.py
add_new_file ¶
Append a row to files.csv for an existing set file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path; only the basename is stored. |
required |
title
|
str
|
Display title for tiles. |
required |
subtitle
|
str
|
Optional secondary text. |
''
|
Source code in src/learning_app/data/app_data.py
update_set_metadata ¶
Update display title and subtitle for a catalog entry in files.csv.
Does not rename the set file; only the tile metadata changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path whose basename is matched in the catalog. |
required |
title
|
str
|
New display title. |
required |
subtitle
|
str
|
New secondary text (may be empty). |
''
|
Source code in src/learning_app/data/app_data.py
record_set_use ¶
Increment use count and set last-used time for a catalog entry.
Called when the user opens a set's learn screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Set basename or path whose basename is matched in the catalog. |
required |
Source code in src/learning_app/data/app_data.py
create_empty_set ¶
Return an empty typed DataFrame for a new words or definitions set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Empty DataFrame with content and statistics columns. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |