edupsyadmin 10.3.0__tar.gz → 10.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/PKG-INFO +1 -1
  2. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/pyproject.toml +1 -1
  3. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/pyproject.toml.orig +1 -1
  4. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/__version__.py +1 -1
  5. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/flattening/pypdf_backend.py +1 -1
  6. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/taetigkeitsbericht_from_db.py +126 -71
  7. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/edupsyadmintui.py +1 -0
  8. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/README.md +0 -0
  9. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/__init__.py +0 -0
  10. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/__main__.py +0 -0
  11. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/README +0 -0
  12. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/env.py +0 -0
  13. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/script.py.mako +0 -0
  14. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_02_21_0453-4087c43f0c7c_initial_migration.py +0 -0
  15. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_03_02_1222-635a9d68fbe8_add_case_active_column_to_clients.py +0 -0
  16. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_03_13_0545-ea4c3f900604_encrypt_class_columns.py +0 -0
  17. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_03_13_0620-515a72d06f10_encrypt_derived_dates.py +0 -0
  18. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_03_16_0900-d7e8f9a0b1c2_add_metadata_table.py +0 -0
  19. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_03_23_1030-e2b4c6d8f0a1_encrypt_sensitive_text_fields.py +0 -0
  20. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_04_10_1200-f3a5b7c9d1e2_set_encrypted_text_fields_non_nullable.py +0 -0
  21. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_06_12_0509-0f1497df963e_add_class_int_override.py +0 -0
  22. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic/versions/2026_09_09_1057-91edbee23274_add_record_academic_year.py +0 -0
  23. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/alembic.ini +0 -0
  24. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/__init__.py +0 -0
  25. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/cft_report.py +0 -0
  26. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/client_view.py +0 -0
  27. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/display_client_details.py +0 -0
  28. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/exceptions.py +0 -0
  29. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/fill_form.py +0 -0
  30. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/flatten_pdf.py +0 -0
  31. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/flattening/__init__.py +0 -0
  32. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/flattening/api.py +0 -0
  33. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/flattening/base.py +0 -0
  34. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/lgvt.py +0 -0
  35. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/managers.py +0 -0
  36. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/migration.py +0 -0
  37. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/migration_fs.py +0 -0
  38. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/reports.py +0 -0
  39. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/setup_demo.py +0 -0
  40. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/api/types.py +0 -0
  41. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/__init__.py +0 -0
  42. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/__main__.py +0 -0
  43. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/check_shredding.py +0 -0
  44. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/copy_client.py +0 -0
  45. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/create_documentation.py +0 -0
  46. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/delete_client.py +0 -0
  47. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/edit_config.py +0 -0
  48. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/flatten_pdfs.py +0 -0
  49. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/get_clients.py +0 -0
  50. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/info.py +0 -0
  51. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/mk_report.py +0 -0
  52. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/new_client.py +0 -0
  53. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/rotate_key.py +0 -0
  54. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/set_client.py +0 -0
  55. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/setup_demo.py +0 -0
  56. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/taetigkeitsbericht.py +0 -0
  57. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/commands/tui.py +0 -0
  58. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/cli/utils.py +0 -0
  59. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/core/__init__.py +0 -0
  60. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/core/config.py +0 -0
  61. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/core/encrypt.py +0 -0
  62. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/core/enums.py +0 -0
  63. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/core/logger.py +0 -0
  64. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/core/paths.py +0 -0
  65. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/Faecher_BfsEV.txt +0 -0
  66. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/Faecher_BfsKi.txt +0 -0
  67. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/Faecher_Faks.txt +0 -0
  68. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/LiberationSans-Bold.ttf +0 -0
  69. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/LiberationSans-Regular.ttf +0 -0
  70. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/OFL.txt +0 -0
  71. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/sampleconfig.yml +0 -0
  72. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/data/taetigkeitsbericht_categories.csv +0 -0
  73. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/db/__init__.py +0 -0
  74. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/db/clients.py +0 -0
  75. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/db/column_types.py +0 -0
  76. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/db/converters.py +0 -0
  77. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/info.py +0 -0
  78. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/py.typed +0 -0
  79. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/__init__.py +0 -0
  80. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/clients_overview.py +0 -0
  81. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/clients_overview_app.py +0 -0
  82. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/dialogs.py +0 -0
  83. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/edit_client.py +0 -0
  84. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/edit_client_app.py +0 -0
  85. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/editconfig.py +0 -0
  86. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/editconfig.tcss +0 -0
  87. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/editconfig_app.py +0 -0
  88. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/edupsyadmintui.tcss +0 -0
  89. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/fill_form_app.py +0 -0
  90. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/fill_form_widget.py +0 -0
  91. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/tui/suggesters.py +0 -0
  92. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/__init__.py +0 -0
  93. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/academic_year.py +0 -0
  94. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/convert_measures.py +0 -0
  95. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/datediff.py +0 -0
  96. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/int_from_str.py +0 -0
  97. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/path_utils.py +0 -0
  98. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/python_type.py +0 -0
  99. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/rounding.py +0 -0
  100. {edupsyadmin-10.3.0 → edupsyadmin-10.3.1}/src/edupsyadmin/utils/taetigkeitsbericht_check_key.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edupsyadmin
3
- Version: 10.3.0
3
+ Version: 10.3.1
4
4
  Summary: edupsyadmin provides tools to help school psychologists with their documentation
5
5
  Author: Lukas Liebermann
6
6
  License: MIT
@@ -4,7 +4,7 @@ requires = ["uv-build>=0.13.6,<0.14"]
4
4
 
5
5
  [project]
6
6
  name = "edupsyadmin"
7
- version = "10.3.0"
7
+ version = "10.3.1"
8
8
  description = "edupsyadmin provides tools to help school psychologists with their documentation"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.15"
@@ -4,7 +4,7 @@ requires = [ "uv-build>=0.13.6,<0.14" ]
4
4
 
5
5
  [project]
6
6
  name = "edupsyadmin"
7
- version = "10.3.0"
7
+ version = "10.3.1"
8
8
  description = "edupsyadmin provides tools to help school psychologists with their documentation"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -18,4 +18,4 @@ and backwards compatibility is not guaranteed for minor versions.
18
18
 
19
19
  __all__ = ["__version__"]
20
20
 
21
- __version__ = "10.3.0"
21
+ __version__ = "10.3.1"
@@ -274,7 +274,7 @@ def _ap_stream_bytes_and_resources(
274
274
  return None
275
275
 
276
276
  try: # because of the checks above, I know that n_obj is a stream object
277
- data = n_obj.get_data() # ty: ignore[unresolved-attribute]
277
+ data = n_obj.get_data() # ty: ignore[missing-attribute]
278
278
  except PyPdfError, TypeError, ValueError, KeyError, AttributeError:
279
279
  return None
280
280
 
@@ -1,3 +1,4 @@
1
+ import math
1
2
  from dataclasses import dataclass, field
2
3
  from datetime import date
3
4
  from pathlib import Path
@@ -8,13 +9,27 @@ import pandas as pd
8
9
  from edupsyadmin.api.managers import ClientsManager
9
10
  from edupsyadmin.api.reports import TaetigkeitsberichtReport
10
11
  from edupsyadmin.core.config import config
12
+ from edupsyadmin.core.logger import logger
11
13
 
12
14
  SESSION_BRACKET_HIGH: Final[int] = 3
13
15
  SESSION_BRACKET_LOW: Final[int] = 2
16
+ # working days/year for a 5-day week, before vacation
17
+ WORKING_DAYS_BASE: Final[int] = 251
18
+ _CLIENT_COLUMNS: Final[list[str]] = [
19
+ "school",
20
+ "keyword_taet_encr",
21
+ "min_sessions",
22
+ "n_sessions",
23
+ ]
14
24
 
15
25
  pd.set_option("display.precision", 1)
16
26
 
17
27
 
28
+ def _out_path(basename: Path, suffix: str) -> Path:
29
+ """Build ``<basename>_<suffix>`` next to ``basename``."""
30
+ return basename.with_name(f"{basename.name}_{suffix}")
31
+
32
+
18
33
  def get_subcategories(category_key: str) -> list[str]:
19
34
  """
20
35
  Extract all hierarchical subcategories from a dot-separated category key.
@@ -33,42 +48,45 @@ def add_categories_to_df(
33
48
  Process hierarchical categories and generate summary statistics.
34
49
  """
35
50
  # Identify all unique categories and their superordinate parents
36
- all_categories = set()
37
- for key in df[category_colnm].unique():
38
- if pd.notna(key):
39
- all_categories.update(get_subcategories(str(key)))
40
-
51
+ keys = df[category_colnm].astype("string").str.strip().replace("", pd.NA)
52
+ all_categories = {
53
+ sub for key in keys.dropna().unique() for sub in get_subcategories(key)
54
+ }
41
55
  sorted_categories = sorted(all_categories)
56
+ # A row matches a category if its specific key starts with that category
57
+ # (and is followed by a dot or is the exact key)
58
+ membership = pd.DataFrame(
59
+ {
60
+ cat: (keys == cat).fillna(False) | keys.str.startswith(f"{cat}.", na=False)
61
+ for cat in sorted_categories
62
+ },
63
+ index=df.index,
64
+ ).astype(bool)
42
65
 
43
66
  # For each category, create a column containing h_sessions if the row matches
44
- for cat in sorted_categories:
45
- # A row matches a category if its specific key starts with that category
46
- # (and is followed by a dot or is the exact key)
47
- mask = df[category_colnm].apply(
48
- lambda k, cat=cat: str(k) == cat or str(k).startswith(f"{cat}."),
49
- )
50
- df.loc[mask, cat] = df.loc[mask, "h_sessions"]
51
-
52
- categories_df = df[sorted_categories]
67
+ h_sessions = df["h_sessions"]
68
+ categories_df = pd.DataFrame(
69
+ {cat: h_sessions.where(membership[cat]) for cat in sorted_categories},
70
+ )
53
71
 
54
72
  # Create summary DataFrame
55
73
  summary = categories_df.describe()
56
- summary.loc["sum", :] = categories_df.sum()
74
+ summary.loc["sum"] = categories_df.sum()
57
75
 
58
76
  # Add counts for session brackets
59
- for cat in sorted_categories:
60
- mask = df[cat].notna()
61
- cat_sessions = df.loc[mask, "n_sessions"]
62
-
63
- summary.loc["count_mt3_sessions", cat] = (
64
- cat_sessions > SESSION_BRACKET_HIGH
65
- ).sum()
66
- summary.loc["count_2to3_sessions", cat] = cat_sessions.between(
77
+ n_sessions = pd.to_numeric(df["n_sessions"], errors="coerce")
78
+ brackets = {
79
+ "count_mt3_sessions": n_sessions > SESSION_BRACKET_HIGH,
80
+ "count_2to3_sessions": n_sessions.between(
67
81
  SESSION_BRACKET_LOW, SESSION_BRACKET_HIGH
68
- ).sum()
69
- summary.loc["count_1_session", cat] = (cat_sessions == 1).sum()
82
+ ),
83
+ "count_1_session": n_sessions == 1,
84
+ }
85
+ for label, flag in brackets.items():
86
+ # Count members regardless of whether minutes are recorded.
87
+ summary.loc[label] = membership.loc[flag].sum()
70
88
 
71
- return df, summary
89
+ return df.join(categories_df), summary
72
90
 
73
91
 
74
92
  def summary_statistics_h_sessions(df: pd.DataFrame) -> pd.DataFrame:
@@ -81,22 +99,47 @@ def summary_statistics_h_sessions(df: pd.DataFrame) -> pd.DataFrame:
81
99
  return h_sessions
82
100
 
83
101
 
84
- @dataclass
102
+ @dataclass(frozen=True)
85
103
  class ActivitySummary:
86
- """Encapsulates all calculations for activity report statistics."""
104
+ """Encapsulates all calculations for activity report statistics.
105
+
106
+ :param wstd_spsy: Anrechnungsstunden Schulpsychologie (Wochenstunden,
107
+ fractional values allowed).
108
+ :param wstd_total: Total Wochenstunden of a full position.
109
+ :param days_per_week: Working days per week.
110
+ :param vacation_days: Vacation days per year.
111
+ :param hours_per_week_std: Standard working hours per week.
112
+ :param school_students: Number of students per school name.
113
+ :param zstd_spsy_year_actual: Recorded hours per year, if known.
114
+ :raises ValueError: If a parameter is outside its valid range.
115
+ """
87
116
 
88
- wstd_spsy: int
89
- wstd_total: int = 23
117
+ wstd_spsy: float
118
+ wstd_total: float = 23.0
90
119
  days_per_week: int = 5
91
120
  vacation_days: int = 30
92
121
  hours_per_week_std: float = 40.0
93
122
  school_students: dict[str, int] = field(default_factory=dict)
94
123
  zstd_spsy_year_actual: float | None = None
95
124
 
125
+ def __post_init__(self) -> None:
126
+ """Validate inputs so that derived properties never divide by zero."""
127
+ if self.days_per_week <= 0:
128
+ raise ValueError("days_per_week must be positive")
129
+ if not math.isfinite(self.wstd_total) or self.wstd_total <= 0:
130
+ raise ValueError("wstd_total must be a positive, finite number")
131
+ if not math.isfinite(self.wstd_spsy) or self.wstd_spsy < 0:
132
+ raise ValueError("wstd_spsy must be a non-negative, finite number")
133
+ if not 0 <= self.vacation_days < WORKING_DAYS_BASE:
134
+ raise ValueError(
135
+ f"vacation_days must be in [0, {WORKING_DAYS_BASE}), "
136
+ f"got {self.vacation_days}"
137
+ )
138
+
96
139
  @property
97
140
  def work_days_per_year(self) -> int:
98
141
  """Total work days in a year after deducting vacation."""
99
- return 251 - self.vacation_days
142
+ return WORKING_DAYS_BASE - self.vacation_days
100
143
 
101
144
  @property
102
145
  def work_weeks_per_year(self) -> float:
@@ -116,9 +159,7 @@ class ActivitySummary:
116
159
  @property
117
160
  def hours_per_wstd(self) -> float:
118
161
  """Hours per year corresponding to one 'Wochenstunde'."""
119
- return (
120
- self.hours_per_year_total / self.wstd_total if self.wstd_total > 0 else 0.0
121
- )
162
+ return self.hours_per_year_total / self.wstd_total
122
163
 
123
164
  @property
124
165
  def target_hours_year(self) -> float:
@@ -137,8 +178,10 @@ class ActivitySummary:
137
178
 
138
179
  @property
139
180
  def ratio_nstudents_wstd_spsy(self) -> float:
140
- """Ratio of total students to school psychology hours."""
141
- return self.n_students_all / self.wstd_spsy if self.wstd_spsy > 0 else 0.0
181
+ """Ratio of students per Wochenstunde; ``nan`` if ``wstd_spsy`` is 0."""
182
+ if self.wstd_spsy == 0:
183
+ return float("nan")
184
+ return self.n_students_all / self.wstd_spsy
142
185
 
143
186
  @property
144
187
  def zstd_spsy_week_actual(self) -> float | None:
@@ -155,12 +198,15 @@ class ActivitySummary:
155
198
  return (self.zstd_spsy_year_actual / self.target_hours_year) * 100
156
199
 
157
200
  def to_dataframe(self) -> pd.DataFrame:
158
- """Convert the summary to a DataFrame for report generation."""
201
+ """Convert the summary to a DataFrame for report generation.
202
+
203
+ :return: Frame indexed by key with columns ``value`` and ``description``.
204
+ """
159
205
  stats_data: dict[str, list[Any]] = {
160
206
  "wd_week": [self.days_per_week, "Arbeitstage/Woche"],
161
207
  "wd_year": [
162
208
  self.work_days_per_year,
163
- "Arbeitstage/Jahr (abzgl. 30 Tage Urlaub)",
209
+ f"Arbeitstage/Jahr (abzgl. {self.vacation_days} Tage Urlaub)",
164
210
  ],
165
211
  "ww_year": [self.work_weeks_per_year, "Arbeitswochen/Jahr"],
166
212
  "zstd_week": [self.hours_per_week_std, "h/Woche"],
@@ -170,10 +216,7 @@ class ActivitySummary:
170
216
  self.wstd_total,
171
217
  "Wstdn gesamt (Anrechn. + Unterr.)",
172
218
  ],
173
- "wstd_spsy": [
174
- self.wstd_spsy,
175
- "Wstdn Schulps. (Anrechn.)",
176
- ],
219
+ "wstd_spsy": [self.wstd_spsy, "Wstdn Schulps. (Anrechn.)"],
177
220
  "zstd_spsy_1wstd_target": [
178
221
  self.hours_per_wstd,
179
222
  "h Arbeit/Jahr pro Wstd (Soll)",
@@ -187,13 +230,15 @@ class ActivitySummary:
187
230
  "h Arbeit/Woche für Wstd Schulps. (Soll)",
188
231
  ],
189
232
  "nstudents_all": [self.n_students_all, ""],
190
- "ratio_nstudens_wstd_spsy": [self.ratio_nstudents_wstd_spsy, ""],
233
+ "ratio_nstudents_wstd_spsy": [self.ratio_nstudents_wstd_spsy, ""],
191
234
  }
192
235
 
193
236
  # Sort school students by name for deterministic report layout
194
- for school_name in sorted(self.school_students.keys()):
195
- student_count = self.school_students[school_name]
196
- stats_data[f"nstudents_{school_name}"] = [student_count, ""]
237
+ for school_name in sorted(self.school_students):
238
+ stats_data[f"nstudents_{school_name}"] = [
239
+ self.school_students[school_name],
240
+ "",
241
+ ]
197
242
 
198
243
  if self.zstd_spsy_year_actual is not None:
199
244
  stats_data["zstd_spsy_year_actual"] = [self.zstd_spsy_year_actual, ""]
@@ -207,7 +252,7 @@ class ActivitySummary:
207
252
  )
208
253
 
209
254
 
210
- def wstd_in_zstd(wstd_spsy: int, wstd_total: int = 23) -> pd.DataFrame:
255
+ def wstd_in_zstd(wstd_spsy: float, wstd_total: float = 23.0) -> pd.DataFrame:
211
256
  """
212
257
  Create a dataframe of Wochenstunden and Zeitstunden for school psychology.
213
258
  """
@@ -215,8 +260,8 @@ def wstd_in_zstd(wstd_spsy: int, wstd_total: int = 23) -> pd.DataFrame:
215
260
 
216
261
 
217
262
  def summary_statistics_wstd(
218
- wstd_spsy: int,
219
- wstd_total: int,
263
+ wstd_spsy: float,
264
+ wstd_total: float,
220
265
  zstd_spsy_year_actual: float,
221
266
  school_students: dict[str, int],
222
267
  ) -> pd.DataFrame:
@@ -248,9 +293,9 @@ def create_taetigkeitsbericht_report(
248
293
 
249
294
  def taetigkeitsbericht(
250
295
  database_url: str,
251
- wstd_psy: int,
296
+ wstd_psy: float,
252
297
  out_basename: Path = Path("Taetigkeitsbericht_Out"),
253
- wstd_total: int = 23,
298
+ wstd_total: float = 23.0,
254
299
  name: str = "Schulpsychologie",
255
300
  report_date: date | None = None,
256
301
  academic_year: str | None = None,
@@ -260,10 +305,10 @@ def taetigkeitsbericht(
260
305
  has the columns 'school', 'keyword_taet_encr', 'min_sessions' and 'n_sessions'
261
306
  and reads nstudents from the config.
262
307
 
263
- param wstd_psy [int]: Anrechnungsstunden in Wochenstunden
308
+ param wstd_psy [float]: Anrechnungsstunden in Wochenstunden
264
309
  param out_basename [Path]: base name for the output files.
265
310
  Defaults to "Taetigkeitsbericht_Out".
266
- param wstd_total [int]: total Wochstunden (depends on your school).
311
+ param wstd_total [float]: total Wochstunden (depends on your school).
267
312
  Defaults to 23.
268
313
  param name [str]: name for the header of the pdf report.
269
314
  Defaults to "Schulpsychologie".
@@ -274,30 +319,40 @@ def taetigkeitsbericht(
274
319
  """
275
320
 
276
321
  # Only fetch required columns
277
- academic_years = [academic_year] if academic_year else None
278
- data = ClientsManager(
279
- database_url=database_url,
280
- ).get_clients_overview(
281
- columns=["school", "keyword_taet_encr", "min_sessions", "n_sessions"],
282
- academic_years=academic_years,
322
+ data = ClientsManager(database_url=database_url).get_clients_overview(
323
+ columns=_CLIENT_COLUMNS,
324
+ academic_years=[academic_year] if academic_year else None,
283
325
  )
284
- df = pd.DataFrame(data)
326
+ df = pd.DataFrame(data, columns=_CLIENT_COLUMNS)
327
+ if df.empty:
328
+ raise ValueError(f"No clients found (academic_year={academic_year!r}).")
329
+
330
+ df["min_sessions"] = pd.to_numeric(df["min_sessions"], errors="coerce")
285
331
  df["h_sessions"] = df["min_sessions"] / 60.0
286
332
 
287
333
  df, summary_categories = add_categories_to_df(df, "keyword_taet_encr")
288
- df.to_csv(out_basename.with_name(f"{out_basename.name}_df.csv"))
289
- print(df)
290
- summary_categories.to_csv(
291
- out_basename.with_name(f"{out_basename.name}_categories.csv")
334
+ n_uncategorized = int(
335
+ df["keyword_taet_encr"]
336
+ .astype("string")
337
+ .str.strip()
338
+ .replace("", pd.NA)
339
+ .isna()
340
+ .sum()
292
341
  )
293
- print(summary_categories)
342
+ if n_uncategorized:
343
+ logger.info(
344
+ "%d of %d clients have no keyword_taet_encr (counted in totals only).",
345
+ n_uncategorized,
346
+ len(df),
347
+ )
348
+
349
+ summary_categories.to_csv(_out_path(out_basename, "categories.csv"))
350
+ logger.info("Category summary:\n%s", summary_categories)
294
351
 
295
352
  # Summary statistics for h_sessions
296
353
  summarystats_h_sessions = summary_statistics_h_sessions(df)
297
- summarystats_h_sessions.to_csv(
298
- out_basename.with_name(f"{out_basename.name}_h_sessions.csv")
299
- )
300
- print(summarystats_h_sessions)
354
+ summarystats_h_sessions.to_csv(_out_path(out_basename, "h_sessions.csv"))
355
+ logger.info("Hours summary:\n%s", summarystats_h_sessions)
301
356
 
302
357
  zstd_spsy_year_actual = pd.to_numeric(summarystats_h_sessions.loc["all", "sum"])
303
358
 
@@ -313,8 +368,8 @@ def taetigkeitsbericht(
313
368
  zstd_spsy_year_actual,
314
369
  school_students_dict,
315
370
  )
316
- summarystats_wstd.to_csv(out_basename.with_name(f"{out_basename.name}_wstd.csv"))
317
- print(summarystats_wstd)
371
+ summarystats_wstd.to_csv(_out_path(out_basename, "wstd.csv"))
372
+ logger.info("WSTD summary:\n%s", summarystats_wstd)
318
373
 
319
374
  create_taetigkeitsbericht_report(
320
375
  out_basename,
@@ -77,6 +77,7 @@ class EdupsyadminTui(App[None]):
77
77
  schools=self.schools,
78
78
  columns=self.columns,
79
79
  academic_years=self.academic_years,
80
+ active=self.active,
80
81
  )
81
82
  yield EditClient()
82
83
  yield Footer()
File without changes