// ============================================================================= // BEFFROI REPORT MODEL // ============================================================================= // // Generic corporate report renderer. // // Expected use: // // typst compile \ // --input report=reports/report.yaml \ // report.typ report.pdf // // ============================================================================= // ----------------------------------------------------------------------------- // ----- Helpers // ----------------------------------------------------------------------------- #import "/visual/elements.typ": dict-get, as-content, theme-color, severity-color, badge, metadata-line, section-title, subsection-title, callout, code-block #let report-type-label(value, t) = { let value = lower(str(value)) if value == "technical" { t("Technical report") } else if value == "briefing" { t("Stakeholder briefing") } else { str(value) } } // ----------------------------------------------------------------------------- // ----- Generic content renderer // ----------------------------------------------------------------------------- #let render-block(theme, block-data, t) = { let kind = dict-get(block-data, "type", "text") if kind == "text" { par[ #as-content(dict-get(block-data, "text", "")) ] } else if kind == "bullets" { let items = dict-get(block-data, "items", ()) list( tight: true, ..items.map(item => [#as-content(item)]), ) } else if kind == "steps" { let items = dict-get(block-data, "items", ()) enum( tight: false, ..items.map(item => [#as-content(item)]), ) } else if kind == "callout" { callout( theme, [#as-content(dict-get(block-data, "text", ""))], title: dict-get(block-data, "title", none), kind: dict-get(block-data, "kind", "info"), ) } else if kind == "code" { code-block( theme, as-content(dict-get(block-data, "text", "")), ) } else if kind == "subsection" { subsection-title( theme, as-content(dict-get(block-data, "title", "")), ) for child in dict-get(block-data, "content", ()) { render-block(theme, child, t) v(0.4em) } } else { callout( theme, [ #t("Unknown report block type:") #raw(str(kind)) ], title: t("Renderer warning"), kind: "warning", ) } } // ----------------------------------------------------------------------------- // ----- Findings // ----------------------------------------------------------------------------- #let render-findings(theme, findings, t) = { for finding in findings { let title = dict-get(finding, "title", t("Finding")) let severity = dict-get(finding, "severity", "info") let status = dict-get(finding, "status", none) let evidence = dict-get(finding, "evidence", none) let assessment = dict-get(finding, "assessment", none) block( width: 100%, breakable: false, inset: 8pt, stroke: 0.5pt + theme-color(theme, "line"), radius: 2pt, )[ #grid( columns: (1fr, auto, auto), gutter: 5pt, align: (left, center, center), text( weight: "bold", size: 10pt, fill: theme-color(theme, "ink"), )[#title], badge( t(severity), color: severity-color(theme, severity), ), if status != none { badge( t(status), color: severity-color(theme, status), ) } else { [] }, ) #if evidence != none { v(5pt) text( size: 8pt, weight: "bold", fill: theme-color(theme, "muted"), )[#t("EVIDENCE")] v(2pt) text( size: 9pt, fill: theme-color(theme, "ink"), )[#as-content(evidence)] } #if assessment != none { v(5pt) text( size: 8pt, weight: "bold", fill: theme-color(theme, "muted"), )[#t("ASSESSMENT")] v(2pt) text( size: 9pt, fill: theme-color(theme, "ink"), )[#as-content(assessment)] } ] v(6pt) } } // ----------------------------------------------------------------------------- // ----- Timeline // ----------------------------------------------------------------------------- #let render-timeline(theme, entries, t) = { let rows = ( ( table.header( [#t("Time")], [#t("Event")], [#t("Notes")], ), ) ) for entry in entries { let time = str(dict-get(entry, "time", "")) rows.push( ( [#text(size: 8pt)[#time]], [#as-content(dict-get(entry, "event", ""))], [#as-content(dict-get(entry, "notes", ""))], ), ) } table( columns: (31mm, 1.1fr, 2fr), inset: 5pt, stroke: 0.45pt + theme-color(theme, "line"), fill: (x, y) => { if y == 0 { theme-color(theme, "paper_soft") } else { none } }, align: (left, left, left), ..rows.flatten(), ) } // ----------------------------------------------------------------------------- // ----- Diagnostic hypotheses // ----------------------------------------------------------------------------- #let confidence-bar(theme, value) = { let value = int(value) let color = if value >= 80 { theme-color(theme, "critical") } else if value >= 50 { theme-color(theme, "warning") } else { theme-color(theme, "info") } grid( columns: (1fr, 12mm), gutter: 6pt, align: (left + horizon, right + horizon), block( width: 100%, height: 5pt, radius: 2.5pt, fill: theme-color(theme, "paper_soft"), stroke: 0.4pt + theme-color(theme, "line"), )[ #block( width: value * 1%, height: 100%, radius: 2.5pt, fill: color, ) ], text(size: 8pt, weight: "bold", fill: color)[#(str(value) + "%")], ) } #let diagnostic-list(theme, title, items) = { if items.len() > 0 { text(size: 7.5pt, weight: "bold", fill: theme-color(theme, "muted"))[#title] v(2pt) list( tight: true, ..items.map(item => text(size: 8.5pt)[#as-content(item)]), ) } } #let render-diagnostics(theme, diagnostics, t) = { let scale = dict-get(diagnostics, "confidence_scale", (:)) let interpretation = dict-get(scale, "interpretation", none) let hypotheses = dict-get(diagnostics, "hypotheses", ()) let leading = dict-get(diagnostics, "current_leading_assessment", (:)) let unsupported = dict-get(diagnostics, "not_yet_supported", ()) if interpretation != none { callout( theme, [#as-content(interpretation)], title: t("How to read confidence"), kind: "info", ) v(7pt) } for hypothesis in hypotheses { let id = dict-get(hypothesis, "id", "Dx") let diagnosis = dict-get(hypothesis, "diagnosis", t("Diagnostic hypothesis")) let confidence = dict-get(hypothesis, "confidence_percent", 0) let status = dict-get(hypothesis, "status", none) let scope = dict-get(hypothesis, "scope", none) let evidence-for = dict-get(hypothesis, "evidence_for", ()) let evidence-against = dict-get(hypothesis, "evidence_against", ()) let hypothesis-interpretation = dict-get(hypothesis, "interpretation", none) let tests = dict-get(hypothesis, "tests_to_confirm", ()) block( width: 100%, breakable: false, inset: 8pt, stroke: 0.5pt + theme-color(theme, "line"), radius: 2pt, )[ #grid( columns: (auto, 1fr, auto), gutter: 6pt, align: (left + horizon, left + horizon, right + horizon), badge(id, color: theme-color(theme, "accent")), text(size: 10pt, weight: "bold")[#diagnosis], if status != none { badge(t(status), color: severity-color(theme, status)) } else { [] }, ) #v(5pt) #confidence-bar(theme, confidence) #if scope != none { v(3pt) text(size: 7.5pt, fill: theme-color(theme, "muted"))[ #t("SCOPE"): #upper(str(scope)) ] } #if evidence-for.len() > 0 { v(6pt) diagnostic-list(theme, t("EVIDENCE FOR"), evidence-for) } #if evidence-against.len() > 0 { v(5pt) diagnostic-list(theme, t("EVIDENCE AGAINST / LIMITATIONS"), evidence-against) } #if hypothesis-interpretation != none { v(5pt) text(size: 7.5pt, weight: "bold", fill: theme-color(theme, "muted"))[#t("INTERPRETATION")] v(2pt) text(size: 8.5pt)[#as-content(hypothesis-interpretation)] } #if tests.len() > 0 { v(5pt) diagnostic-list(theme, t("TESTS TO CONFIRM / REFUTE"), tests) } ] v(6pt) } if leading.len() > 0 { let statement = dict-get(leading, "statement", none) let confidence = dict-get(leading, "confidence_percent", none) callout( theme, [ #if confidence != none { confidence-bar(theme, confidence) v(5pt) } #as-content(statement) ], title: t("Current leading assessment"), kind: "warning", ) } if unsupported.len() > 0 { v(7pt) diagnostic-list(theme, t("NOT YET SUPPORTED"), unsupported) } } // ----------------------------------------------------------------------------- // ----- Action plan // ----------------------------------------------------------------------------- #let render-actions(theme, actions, t) = { for (index, action) in actions.enumerate() { let title = dict-get(action, "title", t("Action")) let status = dict-get(action, "status", "pending") let body = dict-get(action, "text", none) let commands = dict-get(action, "commands", ()) grid( columns: (8mm, 1fr, auto), gutter: 5pt, align: (center, left, center), box( width: 6mm, height: 6mm, radius: 50%, fill: theme-color(theme, "accent"), align(center + horizon)[ #text( size: 7pt, weight: "bold", fill: white, )[ #(index + 1) ] ], ), text( size: 10pt, weight: "bold", fill: theme-color(theme, "ink"), )[ #title ], badge( t(status), color: severity-color(theme, status), ), ) if body != none { block( above: 2pt, inset: (left: 13mm), )[ #text( size: 9pt, fill: theme-color(theme, "ink"), )[ #as-content(body) ] ] } for command in commands { block( inset: (left: 13mm, top: 4pt), )[ #code-block(theme, as-content(command)) ] } v(8pt) } } // ----------------------------------------------------------------------------- // ----- Header / Footer // ----------------------------------------------------------------------------- #let report-header(theme, report, logo, t) = { let organization = dict-get(report, "organization", "Beffroi") let report-type = dict-get(report, "report_type", none) let descriptor = if report-type == none { t("Report") } else { report-type-label(report-type, t) } grid( columns: (1fr, auto), align: (left, right + horizon), [ #text( size: 7.5pt, weight: "bold", fill: theme-color(theme, "muted"), )[ #organization — #descriptor ] ], image( logo, height: 8mm, fit: "contain", ), ) v(3pt) line( length: 100%, stroke: 0.5pt + theme-color(theme, "line"), ) } #let report-footer(theme, report, t) = { let id = dict-get(report, "id", none) grid( columns: (1fr, auto), align: (left, right), text( size: 7pt, fill: theme-color(theme, "muted"), )[ #if id != none { [#t("Report") #id] } ], text( size: 7pt, fill: theme-color(theme, "muted"), )[ #t("Page") #context counter(page).display() ], ) } // ----------------------------------------------------------------------------- // ----- Main model // ----------------------------------------------------------------------------- #let report-model( report: (:), theme: (:), logo: "/assets/beffroi.png", language: "en", t: value => value, body, ) = { set page( paper: "a4", margin: ( top: 20mm, bottom: 18mm, left: 20mm, right: 20mm, ), header: context report-header(theme, report, logo, t), footer: context report-footer(theme, report, t), ) set text( font: dict-get(theme, "font", "DejaVu Sans"), size: 9.5pt, fill: theme-color(theme, "ink"), lang: language, ) set par( justify: false, leading: 0.58em, spacing: 0.55em, ) // --------------------------------------------------------------------------- // Title block // --------------------------------------------------------------------------- let title = dict-get(report, "title", t("Report")) let subtitle = dict-get(report, "subtitle", none) let report-type = dict-get(report, "report_type", none) let status = dict-get(report, "status", none) let severity = dict-get(report, "severity", none) block( width: 100%, below: 12pt, )[ #text( size: 22pt, weight: "bold", fill: theme-color(theme, "accent"), )[ #title ] #if subtitle != none { v(3pt) text( size: 11pt, fill: theme-color(theme, "muted"), )[ #subtitle ] } #if report-type != none or status != none or severity != none { v(7pt) if report-type != none { badge( report-type-label(report-type, t), color: theme-color(theme, "accent"), ) h(4pt) } if status != none { badge( t(status), color: severity-color(theme, status), ) } if status != none and severity != none { h(4pt) } if severity != none { badge( t(severity), color: severity-color(theme, severity), ) } } ] // --------------------------------------------------------------------------- // Metadata // --------------------------------------------------------------------------- let metadata = dict-get(report, "metadata", (:)) if metadata.len() > 0 { block( width: 100%, below: 7pt, inset: 8pt, fill: theme-color(theme, "paper_soft"), stroke: 0.5pt + theme-color(theme, "line"), radius: 2pt, )[ #grid( columns: (1fr, 1fr), row-gutter: 6pt, column-gutter: 10pt, ..metadata .pairs() .map(pair => metadata-line( theme, t(pair.at(0)), pair.at(1), )) ) ] } // --------------------------------------------------------------------------- // Executive summary // --------------------------------------------------------------------------- let summary = dict-get(report, "summary", none) if summary != none { section-title(theme, t("Executive summary")) callout( theme, [#as-content(summary)], kind: dict-get(report, "severity", "info"), ) } // --------------------------------------------------------------------------- // Timeline // --------------------------------------------------------------------------- let timeline = dict-get(report, "timeline", ()) if timeline.len() > 0 { section-title(theme, t("Timeline")) render-timeline(theme, timeline, t) } // --------------------------------------------------------------------------- // Findings // --------------------------------------------------------------------------- let findings = dict-get(report, "findings", ()) if findings.len() > 0 { section-title(theme, t("Findings")) render-findings(theme, findings, t) } // --------------------------------------------------------------------------- // Diagnostic hypotheses // --------------------------------------------------------------------------- let diagnostics = dict-get(report, "diagnostics", (:)) let hypotheses = dict-get(diagnostics, "hypotheses", ()) if hypotheses.len() > 0 { section-title(theme, t("Diagnostic hypotheses")) render-diagnostics(theme, diagnostics, t) } // --------------------------------------------------------------------------- // Arbitrary sections // --------------------------------------------------------------------------- let sections = dict-get(report, "sections", ()) for section in sections { section-title( theme, as-content( dict-get(section, "title", t("Section")), ), ) for block-data in dict-get(section, "content", ()) { render-block(theme, block-data, t) v(0.45em) } } // --------------------------------------------------------------------------- // Action plan // --------------------------------------------------------------------------- let actions = dict-get(report, "actions", ()) if actions.len() > 0 { section-title( theme, dict-get(report, "actions_title", t("Action plan")), ) render-actions(theme, actions, t) } // --------------------------------------------------------------------------- // Closing state // --------------------------------------------------------------------------- let closing = dict-get(report, "closing", none) if closing != none { section-title(theme, t("Current state")) callout( theme, [#as-content(closing)], title: t("Stopping point"), kind: dict-get(report, "severity", "info"), breakable: false, ) } }