diff --git a/balance_report.typ b/balance_report.typ index 705cf31..b88bc28 100644 --- a/balance_report.typ +++ b/balance_report.typ @@ -1,6 +1,7 @@ // Standalone balance-analysis PDF target. #import "/setup/theme/themes.typ" as themes #import "/setup/analysis/class_cost_report.typ": render-class-cost-report +#import "/setup/analysis/origin_report.typ": render-origin-report #let report-theme = themes.make-theme(theme-name: "steingrund") #let report-theme-var = themes.make-theme-variable(theme-name: "steingrund") @@ -48,13 +49,13 @@ #v(0.8em) #text(size: 14pt, tracking: 0.08em, fill: report-theme.heading-accent)[ - ÉCOLES DE COMBAT + ANALYSE DU SYSTÈME ] #v(1.8em) #text(size: 10pt, fill: report-theme.muted-ink)[ - Analyse des coûts en Sang et en Jauge + Écoles de combat, coûts, origines et capacités ] ] ] @@ -66,3 +67,5 @@ #pagebreak() #render-class-cost-report() + +#render-origin-report() diff --git a/setup/analysis/_info.md b/setup/analysis/_info.md index 35c6815..427f199 100644 --- a/setup/analysis/_info.md +++ b/setup/analysis/_info.md @@ -2,3 +2,7 @@ Analysis modules are split into reusable metric extraction and report-specific presentation. Keep TSV parsing out of report entry points so future balance sections can reuse the same normalized datasets. +- `class_costs.typ` and `class_cost_report.typ` analyze school costs. +- `origin_metrics.typ` and `origin_report.typ` analyze origin characteristics, + abilities, and heuristically detected resistance grants. +- `report_style.typ` contains presentation primitives shared by report sections. diff --git a/setup/analysis/class_cost_report.typ b/setup/analysis/class_cost_report.typ index 9e865ac..adf0fad 100644 --- a/setup/analysis/class_cost_report.typ +++ b/setup/analysis/class_cost_report.typ @@ -1,11 +1,9 @@ // Presentation layer for school cost analysis. #import "@preview/primaviz:0.6.0": bar-chart, grouped-bar-chart, horizontal-bar-chart #import "class_costs.typ": * -#import "../theme/themes.typ": make-theme +#import "report_style.typ": chart-theme, metric-card, report-theme, rounded #import "../theme/tables.typ" as tables -#let report-theme = make-theme(theme-name: "steingrund") - #let class-chart-labels = ( artilleur: "Art.", einerjar: "Ein.", @@ -19,49 +17,6 @@ sangremage: "Sang.", ) -#let chart-theme = ( - palette: ( - report-theme.blood, - report-theme.dark-gold, - report-theme.heading-accent, - ), - text-color: report-theme.ink, - text-color-light: report-theme.muted-ink, - axis-stroke: 0.65pt + report-theme.dark-gold, - grid-stroke: 0.5pt + report-theme.dark-gold.transparentize(55%), - marker-stroke: 0.5pt + report-theme.parchment-light, - background: none, - border: none, - show-grid: true, - legend-position: "bottom", - base-size: 7pt, - base-gap: 5pt, -) - -#let rounded(value, digits: 2) = if value == none { - [—] -} else { - str(calc.round(value, digits: digits)) -} - -#let metric-card(label, value, note: none) = block( - width: 100%, - fill: report-theme.parchment, - stroke: 0.6pt + report-theme.border, - inset: 9pt, - radius: 2pt, -)[ - #text(size: 7pt, tracking: 0.08em, weight: "bold", fill: report-theme.heading-subtle)[ - #upper(label) - ] - - #text(size: 18pt, weight: "bold", fill: report-theme.heading)[#value] - - #if note != none { - text(size: 7.5pt, fill: report-theme.muted-ink)[#note] - } -] - #let cost-series(metrics) = ( ( name: "Sang", diff --git a/setup/analysis/origin_metrics.typ b/setup/analysis/origin_metrics.typ new file mode 100644 index 0000000..4a46c5b --- /dev/null +++ b/setup/analysis/origin_metrics.typ @@ -0,0 +1,183 @@ +// Structured and heuristic metrics extracted from origin YAML files. +#let origin-families = ( + (section: "Abyssal", slug: "abyssal"), + (section: "Baloth", slug: "baloth"), + (section: "Béhémoth", slug: "behemoth"), + (section: "Célestial", slug: "celestial"), + (section: "Djieien", slug: "djieien"), + (section: "Dragon", slug: "dragon"), + (section: "Fenrir", slug: "fenrir"), + (section: "Guivre", slug: "guivre"), + (section: "Kraken", slug: "kraken"), + (section: "Léviathan", slug: "leviathan"), + (section: "Röc", slug: "roc"), + (section: "Tréant", slug: "treant"), + (section: "Yénuï", slug: "yenui"), +) + +#let origin-sources = origin-families.map(family => range(1, 3).map(index => ( + family: family.section, + source: "/data/src/origines/" + family.slug + "_" + str(index) + ".yaml", +))).flatten() + +#let resistance-labels = ( + abyssal: "Abyssal", + celestial: "Céleste", + fire: "Feu", + lightning: "Foudre", + pierce: "Perçant", + slash: "Tranchant", + water: "Eau", + wind: "Vent", +) + +#let resistance-type(clause) = { + let lowered = lower(clause) + let element = lowered.match(regex("@el_([a-z_]+)")) + let alteration = lowered.match(regex("@al_([a-z_]+)")) + + if element != none { + let key = element.captures.first() + resistance-labels.at(key, default: key) + } else if alteration != none { + "Seuil inexistence" + } else if "transcendantale" in lowered { + "Transcendantale" + } else if "élémentaire" in lowered { + "Élémentaire" + } else if "physique" in lowered { + "Physique" + } else if "fatigue" in lowered { + "Fatigue" + } else if "mentale" in lowered { + "Mentale" + } else if "horreur" in lowered { + "Horreur" + } else if "perçant" in lowered { + "Perçant" + } else { + "Non classée" + } +} + +#let resistance-value(clause) = { + let resist = clause.match(regex("#resist\((-?\d+)\)")) + let difficulty = clause.match(regex("#ddlvl\s*\(?(-?\d+)\)?")) + let signed = clause.match(regex("(?:^|\s)\+(-?\d+)")) + if resist != none { + int(resist.captures.first()) + } else if difficulty != none { + int(difficulty.captures.first()) + } else if signed != none { + int(signed.captures.first()) + } else { + none + } +} + +#let resistance-grants(description, profile, family, stage) = { + let grants = () + for clause in description.split(",") { + let lowered = lower(clause) + if "résist" in lowered or "resist" in lowered { + grants.push(( + profile: profile, + family: family, + stage: stage, + type: resistance-type(clause), + value: resistance-value(clause), + raw: clause.trim(), + )) + } + } + grants +} + +#let analyze-origin(source-data) = { + let data = yaml(source-data.source) + let at-seven = () + let at-five = () + for (stat, value) in data.stats.max { + if value == 7 { at-seven.push(stat) } + if value == 5 { at-five.push(stat) } + } + + let active = 0 + let passive = 0 + let by-stage = range(1, 4).map(stage => (stage: stage, active: 0, passive: 0)) + let resistances = () + + for stage in data.stades { + for ability in stage.abilities { + let index = stage.number - 1 + if ability.type == "named" { + active += 1 + by-stage.at(index).active += 1 + } else if ability.type == "passive" { + passive += 1 + by-stage.at(index).passive += 1 + let description = ability.at("description", default: "") + resistances += resistance-grants( + description, + data.name, + source-data.family, + stage.number, + ) + } + } + } + + ( + family: source-data.family, + name: data.name, + source: source-data.source, + stats-seven: at-seven, + stats-five: at-five, + active: active, + passive: passive, + by-stage: by-stage, + resistances: resistances, + ) +} + +#let all-origin-metrics = origin-sources.map(analyze-origin) + +#let count-values(items) = { + let counts = (:) + for item in items { + counts.insert(item, counts.at(item, default: 0) + 1) + } + counts +} + +#let characteristic-counts(origins: all-origin-metrics, value: 7) = count-values( + origins.map(origin => if value == 7 { origin.stats-seven } else { origin.stats-five }).flatten(), +) + +#let ability-totals(origins: all-origin-metrics) = ( + active: origins.map(origin => origin.active).sum(), + passive: origins.map(origin => origin.passive).sum(), +) + +#let abilities-by-stage(origins: all-origin-metrics) = range(3).map(index => ( + stage: index + 1, + active: origins.map(origin => origin.by-stage.at(index).active).sum(), + passive: origins.map(origin => origin.by-stage.at(index).passive).sum(), +)) + +#let abilities-by-family(origins: all-origin-metrics) = origin-families.map(family => { + let members = origins.filter(origin => origin.family == family.section) + ( + family: family.section, + active: members.map(origin => origin.active).sum(), + passive: members.map(origin => origin.passive).sum(), + ) +}) + +#let all-resistance-grants(origins: all-origin-metrics) = origins.map( + origin => origin.resistances, +).flatten() + +#let resistance-counts(origins: all-origin-metrics) = count-values( + all-resistance-grants(origins: origins).map(grant => grant.type), +) diff --git a/setup/analysis/origin_report.typ b/setup/analysis/origin_report.typ new file mode 100644 index 0000000..fb09edd --- /dev/null +++ b/setup/analysis/origin_report.typ @@ -0,0 +1,167 @@ +// Origin analysis report: structured characteristics and abilities, plus +// heuristic extraction of explicit resistance grants from passive text. +#import "@preview/primaviz:0.6.0": grouped-bar-chart, horizontal-bar-chart +#import "origin_metrics.typ": * +#import "report_style.typ": chart-theme, metric-card, report-theme, rounded +#import "../theme/tables.typ" as tables + +#let dictionary-chart(data, title, height: 165pt) = horizontal-bar-chart( + ( + labels: data.keys(), + values: data.values(), + ), + width: 100%, + height: height, + title: title, + show-values: true, + theme: chart-theme, +) + +#let origin-summary(origins: all-origin-metrics) = { + let abilities = ability-totals(origins: origins) + let resistances = all-resistance-grants(origins: origins) + let seven = characteristic-counts(origins: origins, value: 7) + let five = characteristic-counts(origins: origins, value: 5) + + pagebreak() + heading(level: 1)[Origines — synthèse] + + grid( + columns: (1fr, 1fr, 1fr, 1fr), + column-gutter: 8pt, + metric-card("Profils", origins.len()), + metric-card("Capacités actives", abilities.active), + metric-card("Passifs", abilities.passive), + metric-card("Résistances", resistances.len(), note: [mentions explicites]), + ) + + heading(level: 2)[Caractéristiques maximum] + + grid( + columns: (1fr, 1fr), + column-gutter: 12pt, + dictionary-chart(seven, [Occurrences à 7]), + dictionary-chart(five, [Occurrences à 5]), + ) + + heading(level: 2)[Actifs et passifs par stade] + + let stages = abilities-by-stage(origins: origins) + grouped-bar-chart( + ( + labels: stages.map(stage => "Stade " + str(stage.stage)), + series: ( + (name: "Actifs", values: stages.map(stage => stage.active)), + (name: "Passifs", values: stages.map(stage => stage.passive)), + ), + ), + width: 100%, + height: 170pt, + theme: chart-theme, + ) + + heading(level: 2)[Types de résistances accordées] + + dictionary-chart( + resistance-counts(origins: origins), + [Occurrences dans les passifs], + height: 190pt, + ) +} + +#let characteristic-audit(origins: all-origin-metrics) = { + heading(level: 1)[Origines — détail des caractéristiques] + let rows = () + for origin in origins { + rows.push(( + origin.family, + origin.name, + origin.stats-seven.join(" + "), + origin.stats-five.join(" + "), + str(origin.active), + str(origin.passive), + )) + } + tables.set-table-style( + table( + columns: (0.8fr, 1.65fr, 0.65fr, 0.55fr, 0.5fr, 0.5fr), + table.header([Origine], [Profil], [À 7], [À 5], [Actifs], [Passifs]), + ..rows.flatten(), + ), + table-theme: "steingrund", + text-size: 7.5pt, + ) +} + +#let ability-audit(origins: all-origin-metrics) = { + pagebreak(weak: true) + heading(level: 1)[Origines — capacités par famille] + let families = abilities-by-family(origins: origins) + + grouped-bar-chart( + ( + labels: families.map(item => item.family), + series: ( + (name: "Actifs", values: families.map(item => item.active)), + (name: "Passifs", values: families.map(item => item.passive)), + ), + ), + width: 100%, + height: 190pt, + theme: chart-theme, + ) + + let rows = families.map(item => ( + item.family, + str(item.active), + str(item.passive), + rounded(item.active / item.passive), + )) + tables.set-table-style( + table( + columns: (1.4fr, 0.7fr, 0.7fr, 0.8fr), + table.header([Origine], [Actifs], [Passifs], [Ratio A/P]), + ..rows.flatten(), + ), + table-theme: "steingrund", + text-size: 8pt, + ) +} + +#let resistance-audit(origins: all-origin-metrics) = { + pagebreak(weak: true) + heading(level: 1)[Origines — audit des résistances] + + [Cette extraction est heuristique. Elle analyse uniquement les descriptions + de capacités `passive` et retient les segments contenant « résistance » ou + une macro apparentée. Les futurs champs YAML structurés pourront remplacer + cette étape sans modifier la présentation du rapport.] + + let grants = all-resistance-grants(origins: origins) + let rows = grants.map(grant => ( + grant.family, + grant.profile, + str(grant.stage), + grant.type, + rounded(grant.value, digits: 0), + grant.raw, + )) + tables.set-table-style( + table( + columns: (0.75fr, 1.35fr, 0.42fr, 0.85fr, 0.42fr, 2fr), + table.header([Origine], [Profil], [St.], [Type], [Val.], [Source détectée]), + ..rows.flatten(), + ), + table-theme: "steingrund", + text-size: 6.8pt, + ) +} + +#let render-origin-report(origins: all-origin-metrics) = { + origin-summary(origins: origins) + pagebreak() + characteristic-audit(origins: origins) + ability-audit(origins: origins) + resistance-audit(origins: origins) +} + diff --git a/setup/analysis/report_style.typ b/setup/analysis/report_style.typ new file mode 100644 index 0000000..1af0b4e --- /dev/null +++ b/setup/analysis/report_style.typ @@ -0,0 +1,48 @@ +// Shared Steingrund presentation primitives for standalone analysis reports. +#import "../theme/themes.typ": make-theme + +#let report-theme = make-theme(theme-name: "steingrund") + +#let chart-theme = ( + palette: ( + report-theme.blood, + report-theme.dark-gold, + report-theme.heading-accent, + ), + text-color: report-theme.ink, + text-color-light: report-theme.muted-ink, + axis-stroke: 0.65pt + report-theme.dark-gold, + grid-stroke: 0.5pt + report-theme.dark-gold.transparentize(55%), + marker-stroke: 0.5pt + report-theme.parchment-light, + background: none, + border: none, + show-grid: true, + legend-position: "bottom", + base-size: 7pt, + base-gap: 5pt, +) + +#let rounded(value, digits: 2) = if value == none { + [—] +} else { + str(calc.round(value, digits: digits)) +} + +#let metric-card(label, value, note: none) = block( + width: 100%, + fill: report-theme.parchment, + stroke: 0.6pt + report-theme.border, + inset: 9pt, + radius: 2pt, +)[ + #text(size: 7pt, tracking: 0.08em, weight: "bold", fill: report-theme.heading-subtle)[ + #upper(label) + ] + + #text(size: 18pt, weight: "bold", fill: report-theme.heading)[#value] + + #if note != none { + text(size: 7.5pt, fill: report-theme.muted-ink)[#note] + } +] +