hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! Attendance reports: the event tallies, the lesson roll call per instance, |
| 2 | //! and the absence block a Turkish school actually reads — how many |
| 3 | //! *days* a student was away in each term, and whether that is over the |
| 4 | //! configured limit. |
| 5 | //! |
| 6 | //! The day counts are bucketed in the school's timezone |
| 7 | //! ([`Settings::get_timezone`](crate::domain::settings::Settings::get_timezone)), |
| 8 | //! because "a day of absence" is a calendar day at the school, not a UTC one: |
| 9 | //! a lesson at 00:30 local is the same school day as one at 23:00 the evening |
| 10 | //! before, and a UTC bucket would split it in two. |
| 11 | |
| 12 | use ; |
| 13 | |
| 14 | use crateState; |
| 15 | use Json; |
| 16 | use Path; |
| 17 | use Serialize; |
| 18 | use ToSchema; |
| 19 | use OpenApiRouter; |
| 20 | use routes; |
| 21 | |
| 22 | use crateDatabase; |
| 23 | use crateAttendanceStatus; |
| 24 | use crate; |
| 25 | use crate; |
| 26 | use crate; |
| 27 | use crateRole; |
| 28 | use crateSessionAttendance; |
| 29 | use crateTerm; |
| 30 | use crate; |
| 31 | use crate; |
| 32 | use cratecan_manage_instance; |
| 33 | use crateensure_can_observe; |
| 34 | use crateAppState; |
| 35 | |
| 36 | use ; |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | /// Per-status tallies over a set of attendance rows, plus the attendance rate. |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | /// `(present + late) / (present + absent + late)`; `None` when the denominator |
| 82 | /// is zero. |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | /// A user's roll-call tallies in one instance. |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | /// The configured per-term absence limits, or `null` per limit when the |
| 99 | /// school set none. |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | /// One term's absence: how many days the student was away, split the way |
| 107 | /// a Turkish school splits it. |
| 108 | /// |
| 109 | /// A *day* is a calendar day at the school on which at least one lesson was |
| 110 | /// missed — two absences in the same day count once, which is what the |
| 111 | /// regulation counts. `unexcused_days` is the `absent` count and |
| 112 | /// `excused_days` the `excused` one; a status the school added counts into |
| 113 | /// neither (its semantics are the school's own). |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | /// A user's full attendance report: generic events, lesson roll call overall, |
| 135 | /// the roll call broken down per instance, and the per-term absence breakdown. |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | /// The term an instant falls in: the containing term with the latest start, |
| 155 | /// or `None` when the calendar does not cover it. |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | /// Assemble the report: tally the user's event rows, then their session rows |
| 166 | /// grouped by the (denormalized) instance. A `viewer` narrows the per-instance |
| 167 | /// blocks — and the overall session tally, and the absence block — to the |
| 168 | /// instances that viewer runs (self-reports and manager+ reports pass `None`). |
| 169 | /// Event tallies are school-wide, not course data, so they stay in either case. |
| 170 | async |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | /// The absence block: for every term the visible rows reach, the count of |
| 262 | /// distinct school-days on which the student was `absent` (unexcused) and on |
| 263 | /// which they were `excused`. |
| 264 | /// |
| 265 | /// The day is the *lesson's* day (`course_session.starts_at`), never when the |
| 266 | /// teacher got round to marking: a roll call taken a week late must not move an |
| 267 | /// absence into another term. The lessons are read one instance at a time |
| 268 | /// (they are the same instances the blocks are built from), and the terms once. |
| 269 | async |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | /// The current user's attendance report: event tallies, lesson roll-call |
| 363 | /// tallies, a per-instance breakdown with attendance rates, and the per-term |
| 364 | /// absence breakdown. |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | async |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | /// Any user's attendance report. Requires teacher+, or a parent tied to the |
| 383 | /// target student. Managers, admins, and parents see every instance; a teacher |
| 384 | /// sees the event tallies plus only the roll-call blocks — and the absence |
| 385 | /// days — of the instances they run. |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | async |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | // The day-bucketing unit test moved with its arithmetic to |
| 417 | // `src/domain/calendar.rs` (`the_day_bucket_follows_the_school_zone`). |