diff --git a/lib/pipeline.py b/lib/pipeline.py index 30f6250..d82b6e1 100644 --- a/lib/pipeline.py +++ b/lib/pipeline.py @@ -143,7 +143,7 @@ def create_default_pipeline(workspace_root: Path) -> Pipeline: pipeline.add_stage(Stage( name="Generate HTML Reports", description="Create standalone HTML reports for groups and classes", - module_name="stage_generate_reports_html" + module_name="stage_generate_reports_html_jinja" )) return pipeline diff --git a/lib/stage_generate_reports_html_jinja.py b/lib/stage_generate_reports_html_jinja.py index ac8c826..6524112 100644 --- a/lib/stage_generate_reports_html_jinja.py +++ b/lib/stage_generate_reports_html_jinja.py @@ -163,43 +163,58 @@ def _format_percent(value: int, total: int) -> str: return f"{value} ({round(value * 100 / total)}%)" -def _build_week_chart(weeks: List[Dict[str, Any]]) -> str: - if not weeks: - return "
Нет данных.
" +def _normalize_day_codes(day: Dict[str, Any]) -> List[str]: + raw = day.get("codes") + if raw is None: + raw = day.get("lessons", "") + codes = list(str(raw or ""))[:8] + while len(codes) < 8: + codes.append("0") + return codes - width = max(720, len(weeks) * 92) - height = 280 - bar_width = 42 - max_value = max( - max(int(w.get("conducted", 0)), int(w.get("missed", 0)), int(w.get("other", 0))) - for w in weeks - ) or 1 - def bar_height(value: int) -> int: - return max(2, round((value / max_value) * 180)) if value else 0 - - pieces = [ - f"" - ] - baseline = 210 - for index, week in enumerate(weeks): - x = 70 + index * 92 - current_bottom = baseline - pieces.append( - f"{week.get('short')}" +def _normalize_week_data(week: Dict[str, Any]) -> Dict[str, Any]: + normalized_days: List[Dict[str, Any]] = [] + for day in week.get("days", []) or []: + normalized_days.append( + { + "date": day.get("date"), + "weekday": day.get("weekday"), + "codes": _normalize_day_codes(day), + } ) - for cls_name, value in [("code-1", int(week.get("missed", 0))), ("code-2", int(week.get("other", 0))), ("code-3", int(week.get("conducted", 0)))]: - h = bar_height(value) - if h: - pieces.append( - f"" - ) - current_bottom -= h - pieces.append( - f"{int(week.get('total_pairs', 0))}" - ) - pieces.append("") - return "".join(pieces) + + code_counts = {"0": 0, "1": 0, "2": 0, "3": 0} + for code, count in (week.get("code_counts", {}) or {}).items(): + key = str(code) + if key in code_counts: + code_counts[key] += int(count) + + if sum(code_counts.values()) == 0 and normalized_days: + for day in normalized_days: + for code in day["codes"]: + if code not in code_counts: + code_counts[code] = 0 + code_counts[code] += 1 + + total_pairs = int(week.get("total_pairs", 0)) + if total_pairs <= 0: + total_pairs = sum(int(v) for v in code_counts.values()) + + conducted = int(week.get("conducted", code_counts.get("3", 0))) + missed = int(week.get("missed", code_counts.get("1", 0))) + other = int(week.get("other", code_counts.get("2", 0))) + + return { + **week, + "days": normalized_days, + "daily_summary": ["".join(day["codes"]) for day in normalized_days], + "code_counts": code_counts, + "total_pairs": total_pairs, + "conducted": conducted, + "missed": missed, + "other": other, + } def _build_scheme_table(week: Dict[str, Any]) -> str: @@ -215,16 +230,15 @@ def _build_scheme_table(week: Dict[str, Any]) -> str: rows.append(f"{day.get('weekday')}{cells}") return ( - "" - + "".join(f"" for i in range(1, 9)) - + "" + "
День{i}
" + "".join(rows) + "
" ) def _build_class_block(item: Dict[str, Any]) -> Dict[str, Any]: - weeks = item.get("weeks", []) or [] + raw_weeks = item.get("weeks", []) or [] + weeks = [_normalize_week_data(week) for week in raw_weeks] for week in weeks: total = int(week.get("total_pairs", 0)) week["conducted_display"] = _format_percent(int(week.get("conducted", 0)), total) @@ -233,7 +247,12 @@ def _build_class_block(item: Dict[str, Any]) -> Dict[str, Any]: week["scheme_html"] = _build_scheme_table(week) item["weeks"] = weeks - item["chart_svg"] = _build_week_chart(weeks) + item["chart_data"] = { + "labels": [str(week.get("short") or week.get("long") or "") for week in weeks], + "missed": [int(week.get("missed", 0)) for week in weeks], + "other": [int(week.get("other", 0)) for week in weeks], + "conducted": [int(week.get("conducted", 0)) for week in weeks], + } return item @@ -270,18 +289,18 @@ def _build_class_report_model(workspace_root: Path, context: Dict[str, Any] | No sections: List[Dict[str, Any]] = [] for part in ordered_parts: - section_items: List[Dict[str, Any]] = [] + entries: List[Dict[str, Any]] = [] if part == "Факультеты": faculty_sources = [raw_by_id[g] for g in ["fe", "kl", "km", "lv", "mk", "mu"] if g in raw_by_id] if faculty_sources: - section_items.append(_aggregate_item(faculty_sources, "before_804", "до 8.04", part)) + entries.append(_aggregate_item(faculty_sources, "before_804", "до 8.04", part)) for raw in raw_items: group_id = str(raw.get("group_id") or "") if _part_name(classes_df, group_id) != part: continue - section_items.append( + entries.append( _build_class_block( { "id": group_id, @@ -296,12 +315,12 @@ def _build_class_report_model(workspace_root: Path, context: Dict[str, Any] | No ) ) - section_items.sort(key=lambda item: (0 if item.get("is_aggregate") else 1, item.get("order", 9999), item.get("label", ""))) - if section_items: - sections.append({"id": part, "title": part, "items": section_items}) + entries.sort(key=lambda item: (0 if item.get("is_aggregate") else 1, item.get("order", 9999), item.get("label", ""))) + if entries: + sections.append({"id": part, "title": part, "entries": entries}) active_section = sections[0]["id"] if sections else "" - active_class = sections[0]["items"][0]["id"] if sections and sections[0]["items"] else "" + active_class = sections[0]["entries"][0]["id"] if sections and sections[0]["entries"] else "" report = { "title": "Отчёт по классам", @@ -341,8 +360,8 @@ def run_stage(workspace_root: Path, context: Dict[str, Any] | None = None) -> Di """Generate standalone HTML reports from Jinja templates.""" template_dir = workspace_root / "template" required = [ - template_dir / "report_class.html", - template_dir / "report_group.html", + template_dir / "report_class.jinja", + template_dir / "report_group.jinja", template_dir / "report.css", template_dir / "report_class.js", template_dir / "report_group.js", @@ -359,7 +378,7 @@ def run_stage(workspace_root: Path, context: Dict[str, Any] | None = None) -> Di group_report = _build_group_report_model(workspace_root) class_html = _render_jinja( - template_dir / "report_class.html", + template_dir / "report_class.jinja", { "title": class_report["title"], "hint": f"Период: {class_report['period']['start']} — {class_report['period']['end']}", @@ -370,7 +389,7 @@ def run_stage(workspace_root: Path, context: Dict[str, Any] | None = None) -> Di }, ) group_html = _render_jinja( - template_dir / "report_group.html", + template_dir / "report_group.jinja", { "title": group_report["title"], "hint": group_report["note"], @@ -386,7 +405,7 @@ def run_stage(workspace_root: Path, context: Dict[str, Any] | None = None) -> Di out_group.write_text(group_html, encoding="utf-8") out_class.write_text(class_html, encoding="utf-8") - print("✓ HTML reports generated") + print("[OK] HTML reports generated") print(f" - {out_group.name}") print(f" - {out_class.name}") diff --git a/template/report.css b/template/report.css index c7f0e29..664f12f 100644 --- a/template/report.css +++ b/template/report.css @@ -1,233 +1,245 @@ :root { - color-scheme: light; - --bg: #f7f8fb; - --panel: #ffffff; - --text: #1b1f2a; - --muted: #667085; - --line: #d9e0ea; - --accent: #2563eb; - --accent-2: #0f766e; - --shadow: 0 8px 24px rgba(15, 23, 42, 0.08); - --bad: #ef4444; - --warn: #f59e0b; - --good: #22c55e; - --empty: #e5e7eb; + color-scheme: light; + --bg: #f7f8fb; + --panel: #ffffff; + --text: #1b1f2a; + --muted: #667085; + --line: #d9e0ea; + --accent: #2563eb; + --accent-2: #0f766e; + --shadow: 0 8px 24px rgba(15, 23, 42, 0.08); + --bad: #ef4444; + --warn: #f59e0b; + --good: #22c55e; + --empty: #e5e7eb; } -* { box-sizing: border-box; } +* { + box-sizing: border-box; +} body { - margin: 0; - font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; - color: var(--text); - background: var(--bg); + margin: 0; + font-family: + Inter, + system-ui, + -apple-system, + BlinkMacSystemFont, + "Segoe UI", + sans-serif; + color: var(--text); + background: var(--bg); } .page { - max-width: 1440px; - margin: 0 auto; - padding: 24px; + max-width: 1440px; + margin: 0 auto; + padding: 24px; } .header { - display: flex; - justify-content: space-between; - gap: 16px; - align-items: flex-start; - margin-bottom: 18px; + display: flex; + justify-content: space-between; + gap: 16px; + align-items: flex-start; + margin-bottom: 18px; } .title h1 { - margin: 0 0 8px; - font-size: 30px; + margin: 0 0 8px; + font-size: 30px; } .title p { - margin: 0; - color: var(--muted); + margin: 0; + color: var(--muted); } .actions { - display: flex; - gap: 12px; - flex-wrap: wrap; + display: flex; + gap: 12px; + flex-wrap: wrap; } .btn { - border: 1px solid var(--line); - background: var(--panel); - border-radius: 12px; - padding: 10px 14px; - cursor: pointer; - box-shadow: var(--shadow); + border: 1px solid var(--line); + background: var(--panel); + border-radius: 12px; + padding: 10px 14px; + cursor: pointer; + box-shadow: var(--shadow); } .btn.primary { - background: linear-gradient(135deg, var(--accent), #4f46e5); - color: white; - border-color: transparent; + background: linear-gradient(135deg, var(--accent), #4f46e5); + color: white; + border-color: transparent; } .section, .class-block, .screen-nav, .print-nav { - background: var(--panel); - border: 1px solid var(--line); - border-radius: 18px; - box-shadow: var(--shadow); + background: var(--panel); + border: 1px solid var(--line); + border-radius: 18px; + box-shadow: var(--shadow); } .section { - padding: 20px; + padding: 20px; } .section h2, .print-nav h2 { - margin: 0 0 16px; - font-size: 22px; + margin: 0 0 16px; + font-size: 22px; } .cards { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); - gap: 14px; - margin-bottom: 18px; + display: grid; + grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); + gap: 14px; + margin-bottom: 18px; } .card { - border: 1px solid var(--line); - border-radius: 16px; - padding: 16px; - background: linear-gradient(180deg, #fff, #fbfcff); + border: 1px solid var(--line); + border-radius: 16px; + padding: 16px; + background: linear-gradient(180deg, #fff, #fbfcff); } .card-value { - font-size: 26px; - font-weight: 700; - line-height: 1.1; + font-size: 26px; + font-weight: 700; + line-height: 1.1; } .card-label { - color: var(--muted); - margin-top: 6px; + color: var(--muted); + margin-top: 6px; } -.muted { color: var(--muted); } +.muted { + color: var(--muted); +} .screen-nav { - padding: 14px; - margin-bottom: 20px; + padding: 14px; + margin-bottom: 20px; } .section-nav, .class-nav-group { - display: flex; - gap: 10px; - flex-wrap: wrap; + display: flex; + gap: 10px; + flex-wrap: wrap; } .class-nav { - margin-top: 12px; + margin-top: 12px; } -.class-nav-group { display: none; } -.class-nav-group.active { display: flex; } +.class-nav-group { + display: none; +} +.class-nav-group.active { + display: flex; +} .nav-btn { - border: 1px solid var(--line); - background: #fff; - color: var(--text); - border-radius: 999px; - padding: 10px 14px; - cursor: pointer; - transition: 0.15s ease; + border: 1px solid var(--line); + background: #fff; + color: var(--text); + border-radius: 999px; + padding: 10px 14px; + cursor: pointer; + transition: 0.15s ease; } -.nav-btn:hover { border-color: var(--accent); } +.nav-btn:hover { + border-color: var(--accent); +} .nav-btn.active { - background: var(--accent); - border-color: var(--accent); - color: #fff; + background: var(--accent); + border-color: var(--accent); + color: #fff; } .print-nav { - display: none; - padding: 18px 20px; - margin-bottom: 20px; + display: none; + padding: 18px 20px; + margin-bottom: 20px; } -.print-nav-section + .print-nav-section { margin-top: 14px; } -.print-nav-section h3 { margin: 0 0 8px; } -.print-nav-section ul { margin: 0; padding-left: 18px; } +.print-nav-section + .print-nav-section { + margin-top: 14px; +} +.print-nav-section h3 { + margin: 0 0 8px; +} +.print-nav-section ul { + margin: 0; + padding-left: 18px; +} -.report-section { margin-bottom: 26px; } +.report-section { + margin-bottom: 26px; +} .class-block { - display: none; - padding: 20px; - margin-bottom: 18px; + display: none; + padding: 20px; + margin-bottom: 18px; } -.class-block.active { display: block; } +.class-block.active { + display: block; +} .class-head { - display: flex; - justify-content: space-between; - gap: 12px; - align-items: flex-start; - margin-bottom: 14px; + display: flex; + justify-content: space-between; + gap: 12px; + align-items: flex-start; + margin-bottom: 14px; } .class-kicker { - color: var(--muted); - font-size: 12px; - text-transform: uppercase; - letter-spacing: 0.06em; - margin-bottom: 4px; + color: var(--muted); + font-size: 12px; + text-transform: uppercase; + letter-spacing: 0.06em; + margin-bottom: 4px; } .class-head h3 { - margin: 0; - font-size: 24px; + margin: 0; + font-size: 24px; } .class-note { - margin-top: 6px; - color: var(--muted); - font-size: 13px; + margin-top: 6px; + color: var(--muted); + font-size: 13px; } .class-chart { - overflow-x: auto; - margin-bottom: 16px; + position: relative; + min-height: 320px; + margin-bottom: 16px; } .week-chart { - width: 100%; - height: auto; - min-width: 720px; + width: 100%; + height: 320px; } -.chart-week-label { - font-size: 12px; - fill: var(--text); -} - -.chart-count { - font-size: 12px; - fill: var(--text); - font-weight: 600; -} - -.week-bar.code-1 { fill: var(--bad); } -.week-bar.code-2 { fill: var(--warn); } -.week-bar.code-3 { fill: var(--good); } - .class-table, .scheme-table, .table { - width: 100%; - border-collapse: collapse; + width: 100%; + border-collapse: collapse; } .class-table th, @@ -236,263 +248,141 @@ body { .scheme-table td, .table th, .table td { - border-bottom: 1px solid var(--line); - padding: 10px 12px; - vertical-align: top; - text-align: left; + border-bottom: 1px solid var(--line); + padding: 10px 12px; + vertical-align: top; + text-align: left; } .class-table th, .scheme-table th, .table th { - font-size: 13px; - color: var(--muted); - text-transform: uppercase; - letter-spacing: 0.04em; - background: #f8fafc; + font-size: 13px; + color: var(--muted); + text-transform: uppercase; + letter-spacing: 0.04em; + background: #f8fafc; } -.week-label { white-space: nowrap; } -.num { white-space: nowrap; } +.week-label { + white-space: nowrap; +} +.num { + white-space: nowrap; +} -.scheme-cell-wrap { min-width: 420px; } +.scheme-cell-wrap { + min-width: 420px; +} .scheme-table { - width: 100%; - min-width: 420px; - border: 1px solid var(--line); - border-radius: 12px; - overflow: hidden; + width: 100%; + min-width: 420px; + border: 1px solid var(--line); + border-radius: 12px; + overflow: hidden; } .scheme-table th, .scheme-table td { - padding: 6px; - text-align: center; + padding: 6px; + text-align: center; } .scheme-table thead th:first-child, .scheme-table tbody th { - text-align: left; - white-space: nowrap; + text-align: left; + white-space: nowrap; } .scheme-cell { - display: inline-block; - width: 18px; - height: 18px; - border-radius: 4px; - background: var(--empty); - border: 1px solid rgba(0, 0, 0, 0.06); + display: inline-block; + width: 18px; + height: 18px; + border-radius: 4px; + background: var(--empty); + border: 1px solid rgba(0, 0, 0, 0.06); } -.scheme-cell.code-0 { background: var(--empty); } -.scheme-cell.code-1 { background: var(--bad); } -.scheme-cell.code-2 { background: var(--warn); } -.scheme-cell.code-3 { background: var(--good); } - -.code-1 { color: var(--bad); } -.code-2 { color: var(--warn); } -.code-3 { color: var(--good); } - -@media print { - body { background: #fff; } - .page { max-width: none; padding: 0; } - .screen-nav, - .actions { display: none !important; } - .print-nav { display: block; } - .class-block { display: block !important; box-shadow: none; break-inside: avoid; page-break-inside: avoid; } - .section, .class-block, .print-nav { box-shadow: none; } - .table th, .class-table th { position: static; } +.scheme-cell.code-0 { + background: var(--empty); } -:root { - color-scheme: light; - --bg: #f7f8fb; - --panel: #ffffff; - --text: #1b1f2a; - --muted: #667085; - --line: #d9e0ea; - --accent: #2563eb; - --accent-2: #0f766e; - --shadow: 0 8px 24px rgba(15, 23, 42, 0.08); +.scheme-cell.code-1 { + background: var(--bad); +} +.scheme-cell.code-2 { + background: var(--warn); +} +.scheme-cell.code-3 { + background: var(--good); } -* { box-sizing: border-box; } -body { - margin: 0; - font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; - color: var(--text); - background: var(--bg); +.code-1 { + color: var(--bad); +} +.code-2 { + color: var(--warn); +} +.code-3 { + color: var(--good); } -.page { - max-width: 1400px; - margin: 0 auto; - padding: 24px; -} - -.header { - display: flex; - justify-content: space-between; - gap: 16px; - align-items: flex-start; - margin-bottom: 20px; -} - -.title h1 { - margin: 0 0 8px; - font-size: 30px; -} - -.title p { - margin: 0; - color: var(--muted); -} - -.actions { - display: flex; - gap: 12px; - flex-wrap: wrap; -} - -.btn { - border: 1px solid var(--line); - background: var(--panel); - border-radius: 12px; - padding: 10px 14px; - cursor: pointer; - box-shadow: var(--shadow); -} - -.btn.primary { - background: linear-gradient(135deg, var(--accent), #4f46e5); - color: white; - border-color: transparent; -} - -.section { - background: var(--panel); - border: 1px solid var(--line); - border-radius: 18px; - padding: 20px; - margin-bottom: 20px; - box-shadow: var(--shadow); -} - -.section h2 { - margin: 0 0 16px; - font-size: 22px; -} - -.cards { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); - gap: 14px; -} - -.card { - border: 1px solid var(--line); - border-radius: 16px; - padding: 16px; - background: linear-gradient(180deg, #fff, #fbfcff); -} - -.card-value { - font-size: 26px; - font-weight: 700; - line-height: 1.1; -} - -.card-label { - color: var(--muted); - margin-top: 6px; -} - -.table { - width: 100%; - border-collapse: collapse; -} - -.table th, -.table td { - border-bottom: 1px solid var(--line); - padding: 10px 12px; - vertical-align: top; - text-align: left; -} - -.table th { - font-size: 13px; - color: var(--muted); - text-transform: uppercase; - letter-spacing: 0.04em; - background: #f8fafc; - position: sticky; - top: 0; - z-index: 1; -} - -.muted { color: var(--muted); } - -.pill { - display: inline-block; - padding: 4px 8px; - border-radius: 999px; - background: #e8eefb; - color: #274a8a; - font-size: 12px; - font-weight: 600; +.note { + padding: 14px 16px; + border-left: 4px solid var(--accent); + background: #eff6ff; + border-radius: 12px; + margin-bottom: 18px; } .grid-2 { - display: grid; - grid-template-columns: 1.3fr 1fr; - gap: 16px; + display: grid; + grid-template-columns: 1.3fr 1fr; + gap: 16px; } -.chart-wrap { - min-height: 80px; - overflow-x: auto; +.pill { + display: inline-block; + padding: 4px 8px; + border-radius: 999px; + background: #e8eefb; + color: #274a8a; + font-size: 12px; + font-weight: 600; } -.bar-chart { - width: 100%; - height: auto; - overflow: visible; +.nowrap { + white-space: nowrap; } -.chart-label { - font-size: 12px; - fill: #1b1f2a; - dominant-baseline: middle; -} - -.chart-value { - font-size: 12px; - fill: #334155; - dominant-baseline: middle; - font-weight: 600; -} - -.chart-track { fill: #e8edf5; } -.chart-bar { fill: var(--accent); } -.chart-bar.secondary { fill: var(--accent-2); } - -.note { - padding: 14px 16px; - border-left: 4px solid var(--accent); - background: #eff6ff; - border-radius: 12px; - margin-bottom: 18px; -} - -.nowrap { white-space: nowrap; } - @media print { - body { background: white; } - .page { max-width: none; padding: 0; } - .actions { display: none; } - .section, .card { box-shadow: none; } - .section { break-inside: avoid; } - .table th { position: static; } + body { + background: #fff; + } + .page { + max-width: none; + padding: 0; + } + .screen-nav, + .actions { + display: none !important; + } + .print-nav { + display: block; + } + .class-block { + display: block !important; + box-shadow: none; + break-inside: avoid; + page-break-inside: avoid; + } + .section, + .class-block, + .print-nav { + box-shadow: none; + } + .table th, + .class-table th { + position: static; + } } diff --git a/template/report_class.html b/template/report_class.html deleted file mode 100644 index e6bfc74..0000000 --- a/template/report_class.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - {{ title }} - - - -
-
-
-

{{ title }}

-

{{ hint }}

-
-
- -
-
- -
-
- {% for section in report.sections %} - - {% endfor %} -
- -
- {% for section in report.sections %} -
- {% for item in section.items %} - - {% endfor %} -
- {% endfor %} -
-
- - - -
- {% for section in report.sections %} -
- {% for item in section.items %} -
-
-
-
{{ section.title }}
-

{{ item.label }}

- {% if item.source_labels %} -
{{ item.source_labels | join(', ') }}
- {% endif %} -
-
- -
-{{ item.chart_svg | safe }} -
- -
- - - - - - - - - - - - - {% for week in item.weeks %} - - - - - - - - - {% endfor %} - -
НеделяВсего парПар проведеноПар пропущеноИные парыСхема
{{ week.long }}{{ week.total_pairs }}{{ week.conducted_display }}{{ week.missed_display }}{{ week.other_display }}{{ week.scheme_html | safe }}
-
-
- {% endfor %} -
- {% endfor %} -
-
- - - - - - - - - - - {{TITLE}} - {{STYLE_TAG}} - - -
-
-
-

{{TITLE}}

-

{{HINT}}

-
-
- -
-
- {{CONTENT}} -
- {{SCRIPT_TAG}} - - diff --git a/template/report_class.jinja b/template/report_class.jinja new file mode 100644 index 0000000..2d79f23 --- /dev/null +++ b/template/report_class.jinja @@ -0,0 +1,129 @@ + + + + + + {{ title }} + + + + +
+
+
+

{{ title }}

+

{{ hint }}

+
+
+ +
+
+ +
+
+ {% for section in report.sections %} + + {% endfor %} +
+
+ {% for section in report.sections %} +
+ {% for item in section.entries %} + + {% endfor %} +
+ {% endfor %} +
+
+ + + +
+ {% for section in report.sections %} +
+ {% for item in section.entries %} +
+
+
+
{{ section.title }}
+

{{ item.label }}

+ {% if item.source_labels %} +
+ {{ item.source_labels | join(', ') }} +
+ {% endif %} +
+
+
+ +
+
+ + + {% for week in item.weeks %} + + + + + + + + + {% endfor %} + +
{{ week.long }}{{ week.total_pairs }}{{ week.conducted_display }}{{ week.missed_display }}{{ week.other_display }} + {{ week.scheme_html | safe }} +
+
+
+ {% endfor %} +
+ {% endfor %} +
+
+ + + + + diff --git a/template/report_class.js b/template/report_class.js index d5036ee..4a992a9 100644 --- a/template/report_class.js +++ b/template/report_class.js @@ -1,73 +1,168 @@ (function () { - function qs(selector, root) { - return (root || document).querySelector(selector); - } + const chartStore = new Map(); - function qsa(selector, root) { - return Array.from((root || document).querySelectorAll(selector)); - } + function qs(selector, root) { + return (root || document).querySelector(selector); + } - function setActiveSection(sectionId) { - qsa('.section-nav .nav-btn[data-section]').forEach((btn) => { - btn.classList.toggle('active', btn.dataset.section === sectionId); - }); + function qsa(selector, root) { + return Array.from((root || document).querySelectorAll(selector)); + } - qsa('.class-nav-group').forEach((group) => { - group.classList.toggle('active', group.dataset.section === sectionId); - }); + function buildChartForClass(classId, report) { + if (!classId || chartStore.has(classId) || typeof Chart === "undefined") { + return; + } - const firstButton = qs(`.class-nav-group.active .class-btn[data-class-id]`); - if (firstButton) { - setActiveClass(firstButton.dataset.classId, false); - } - } + const sections = Array.isArray(report.sections) ? report.sections : []; + const entry = sections + .flatMap((section) => section.entries || []) + .find((item) => item.id === classId); + if (!entry) { + return; + } - function setActiveClass(classId, scrollIntoView) { - qsa('.class-btn[data-class-id]').forEach((btn) => { - btn.classList.toggle('active', btn.dataset.classId === classId); - }); + const canvas = qs(`.week-chart[data-chart-for="${classId}"]`); + if (!canvas) { + return; + } - qsa('.class-block[data-class-id]').forEach((block) => { - const active = block.dataset.classId === classId; - block.classList.toggle('active', active); - if (active && scrollIntoView) { - block.scrollIntoView({ behavior: 'smooth', block: 'start' }); - } - }); - } + const chartData = entry.chart_data || {}; + const labels = Array.isArray(chartData.labels) ? chartData.labels : []; + const missed = Array.isArray(chartData.missed) ? chartData.missed : []; + const other = Array.isArray(chartData.other) ? chartData.other : []; + const conducted = Array.isArray(chartData.conducted) + ? chartData.conducted + : []; - function init() { - const report = window.__CLASS_REPORT__ || {}; - const activeSection = report.active_section || ''; - const activeClass = report.active_class || ''; + if (!labels.length) { + const container = canvas.parentElement; + if (container) { + container.innerHTML = "
Нет данных.
"; + } + return; + } - qsa('.section-nav .nav-btn[data-section]').forEach((btn) => { - btn.addEventListener('click', () => setActiveSection(btn.dataset.section)); - }); + const chart = new Chart(canvas, { + type: "bar", + data: { + labels, + datasets: [ + { + label: "Пропущено", + data: missed, + backgroundColor: "#ef4444", + stack: "pairs", + borderRadius: 4, + }, + { + label: "Иное", + data: other, + backgroundColor: "#f59e0b", + stack: "pairs", + borderRadius: 4, + }, + { + label: "Проведено", + data: conducted, + backgroundColor: "#22c55e", + stack: "pairs", + borderRadius: 4, + }, + ], + }, + options: { + responsive: true, + maintainAspectRatio: false, + interaction: { + mode: "index", + intersect: false, + }, + scales: { + x: { + stacked: true, + grid: { + display: false, + }, + }, + y: { + stacked: true, + beginAtZero: true, + ticks: { + precision: 0, + }, + }, + }, + }, + }); - qsa('.class-btn[data-class-id]').forEach((btn) => { - btn.addEventListener('click', () => setActiveClass(btn.dataset.classId, true)); - }); + chartStore.set(classId, chart); + } - if (activeSection) { - setActiveSection(activeSection); - } + function setActiveSection(sectionId, report) { + qsa(".section-nav .nav-btn[data-section]").forEach((btn) => { + btn.classList.toggle("active", btn.dataset.section === sectionId); + }); - if (activeClass) { - setActiveClass(activeClass, false); - } - } + qsa(".class-nav-group").forEach((group) => { + group.classList.toggle("active", group.dataset.section === sectionId); + }); - window.printReport = function printReport() { - window.print(); - }; + const firstButton = qs(`.class-nav-group.active .class-btn[data-class-id]`); + if (firstButton) { + setActiveClass(firstButton.dataset.classId, false, report); + } + } - if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', init); - } else { - init(); - } + function setActiveClass(classId, scrollIntoView, report) { + qsa(".class-btn[data-class-id]").forEach((btn) => { + btn.classList.toggle("active", btn.dataset.classId === classId); + }); + + qsa(".class-block[data-class-id]").forEach((block) => { + const active = block.dataset.classId === classId; + block.classList.toggle("active", active); + if (active && scrollIntoView) { + block.scrollIntoView({ behavior: "smooth", block: "start" }); + } + }); + + buildChartForClass(classId, report); + } + + function init() { + const report = window.__CLASS_REPORT__ || {}; + const activeSection = report.active_section || ""; + const activeClass = report.active_class || ""; + + qsa(".section-nav .nav-btn[data-section]").forEach((btn) => { + btn.addEventListener("click", () => + setActiveSection(btn.dataset.section, report), + ); + }); + + qsa(".class-btn[data-class-id]").forEach((btn) => { + btn.addEventListener("click", () => + setActiveClass(btn.dataset.classId, true, report), + ); + }); + + if (activeSection) { + setActiveSection(activeSection, report); + } + + if (activeClass) { + setActiveClass(activeClass, false, report); + } + } + + window.printReport = function printReport() { + window.print(); + }; + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", init); + } else { + init(); + } })(); -function printReport() { - window.print(); -} diff --git a/template/report_group.html b/template/report_group.html deleted file mode 100644 index 429b9ef..0000000 --- a/template/report_group.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - {{ title }} - - - -
-
-
-

{{ title }}

-

{{ hint }}

-
-
- -
-
- -
-

Шаблон пар

- {% if report.lesson_windows %} - - - - - - {% for item in report.lesson_windows %} - - - - - - {% endfor %} - -
ПараНачалоОкончание
{{ item.lesson }}{{ item.start }}{{ item.end }}
- {% else %} -
Нет данных.
- {% endif %} -
-
- - - - - - - - - - - {{TITLE}} - {{STYLE_TAG}} - - -
-
-
-

{{TITLE}}

-

{{HINT}}

-
-
- -
-
- {{CONTENT}} -
- {{SCRIPT_TAG}} - - diff --git a/template/report_group.jinja b/template/report_group.jinja new file mode 100644 index 0000000..83d7ceb --- /dev/null +++ b/template/report_group.jinja @@ -0,0 +1,49 @@ + + + + + + {{ title }} + + + +
+
+
+

{{ title }}

+

{{ hint }}

+
+
+ +
+
+ +
+

Шаблон пар

+ {% if report.lesson_windows %} + + + + + + {% for item in report.lesson_windows %} + + + + + + {% endfor %} + +
ПараНачалоОкончание
{{ item.lesson }}{{ item.start }}{{ item.end }}
+ {% else %} +
Нет данных.
+ {% endif %} +
+
+ + + + + diff --git a/template/report_group.js b/template/report_group.js index 67a519a..8273ffc 100644 --- a/template/report_group.js +++ b/template/report_group.js @@ -1,6 +1,3 @@ window.printReport = function printReport() { - window.print(); + window.print(); }; -function printReport() { - window.print(); -}