Skip to content

Teacher reported today: card per lesson taught, per-lesson hour, fix missing-girls total - #204

Merged
buzz-code merged 6 commits into
mainfrom
claude/teacher-reported-today-per-lesson
Oct 7, 2026
Merged

buzz-code merged 6 commits into
mainfrom
claude/teacher-reported-today-per-lesson

Conversation

@buzz-code

@buzz-code buzz-code commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Replaces #202. Built on #203 (merged). server/shared is bumped to nra-server main, which includes buzz-code/nra-server#63 (merged).

Summary

Fixes in the "מורות שדיווחו" (teacher_reported_today) card view:

  • Missing-girls total bug. missingGirlsCount comes from MySQL COUNT (BIGINT) as a string, so the card total concatenated (0 + "1" + "2" → חסרו 012). It's now cast to Number. The same string made a 0 badge show on lessons with no absences; that badge is hidden now.

  • One card per lesson taught. The view now has one row per lesson. Reports of the same teacher + lesson + klass + date become separate lessons when more than 15 minutes pass between consecutive reports. Consecutive gaps are measured, not the time since the first report, so this works for every source:

    • phone saves the whole lesson at once
    • the web form saves each student a few seconds apart
    • Excel saves the whole file at once

    The same subject at 09:00 and 11:30 → two cards. Two different subjects → two cards, as before.

  • Per-lesson report hour. reportHour is the first report time of that lesson. Before, it was shared across all of a teacher's lessons in the klass that day.

  • New index att_user_report_date_idx on att_reports (user_id, report_date). The view (and other date-range screens) filter by user + date, but only a user_id index existed.

The view is a raw SQL expression with window functions (LAG → new-lesson flag, running SUM → lesson number). The gap comparison uses the shared getAddMinutesExpression helper for the MySQL/SQLite difference; on SQLite it keeps milliseconds. The id uses getConcatExpression. Migrations:

  • SplitTeacherReportedTodayByLesson1791306863767 (view)
  • AddAttReportUserReportDateIndex1791317504779 (index)

Both were generated by TypeORM.

Performance

Local MySQL 8.0.46, 1M att_reports rows (10 users × 250 days). Query shaped like the client's: one userId, a date range, ORDER BY reportHour LIMIT 1000.

Range Old view New view New view + index
1 day (default filter) 3 ms 6 ms 6 ms
36 days 1.32 s 1.91 s 195 ms
  • The userId/reportDate filter is pushed down to att_reports in both views, so the view is never fully materialized.
  • The new view costs about 1.5–3.5× the old one because of two window passes.
  • The index cuts long ranges about 10×.

Testing

Local MySQL 8 + NestJS + Vite with seeded reports:

Case Result
Same lesson at 09:00 and 11:30 2 cards
Rows 7 min apart over 21 min (web-form style) 1 card
Gap of exactly 15 min Same lesson
Gap of 16 min New lesson
Card totals and badges Correct
  • Both migrations run → revert → run OK. migration:generate --dryrun reports no drift.
  • Server jest: 1171/1171. Client jest: 214/214.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld

claude added 2 commits October 6, 2026 17:13
teacher_reported_today view column order and attendance_cleanup_rules
lesson_id/klass_id nullability + active column type, so
migration:generate reports no drift.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld
…missing-girls total

- missingGirlsCount comes from MySQL COUNT as a string; cast to Number so the
  card total sums instead of concatenating ("012") and a zero badge is hidden.
- View now has one row per lesson taught: reports of the same
  teacher+lesson+klass+date are split into separate lessons when more than
  15 minutes pass between consecutive reports. Works for phone, web form
  and Excel reports alike.
- reportHour is the first report time of that lesson.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

SQLite gap comparison drops milliseconds, merging reports beyond 15-minute boundary.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates teacher-report cards to show separate lessons with correct report times and absence counts.

Changes:

  • Splits reports when consecutive gaps exceed 15 minutes.
  • Uses each lesson’s first report time.
  • Fixes numeric absence totals and hides zero badges.
File Description
server/​src/​migrations/​1791306863767-SplitTeacherReportedTodayByLesson.ts Applies lesson-splitting view and rollback.
server/​src/​db/​view-entities/​TeacherReportedToday.entity.ts Defines gap-based grouping and per-lesson times.
client/​src/​entities/​teacher-reported-today.jsx Shows separate lesson cards and numeric absence counts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

claude added 3 commits October 6, 2026 20:15
…rt_date) index

- teacher_reported_today: replace local sqlite check with shared helper
  (MySQL SQL unchanged). Bumps server/shared to nra-server
  claude/add-minutes-expression (buzz-code/nra-server#63); re-point to
  merged main before merging.
- att_user_report_date_idx: the view and other date-range reports filter
  by user + report_date; only a user_id index existed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld
@buzz-code
buzz-code changed the base branch from claude/align-db-typeorm to main October 6, 2026 21:12
@buzz-code
buzz-code merged commit a2b37ab into main Oct 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants