// Descriptive durability aggregates. No combat conversion or target model is // applied: values are summarized and standardized only against this dataset. #import "creature_common_metrics.typ": ( average, common-creatures, extent, standard-deviation, ) #let phase-aggregate(creature, phase) = { let parts = creature.source.body-parts let phase-parts = parts.map(part => part.at(phase)) let thresholds = phase-parts.map(part => part.threshold.base) let protections = phase-parts.map(part => part.protection.base) let integrities = phase-parts.map(part => part.integrity) let lives = phase-parts.map(part => part.life) let threshold-range = extent(thresholds) let protection-range = extent(protections) ( threshold-average: average(thresholds), threshold-min: threshold-range.min, threshold-max: threshold-range.max, protection-average: average(protections), protection-min: protection-range.min, protection-max: protection-range.max, integrity-total: integrities.sum(), life-total: lives.sum(), ) } #let durability-creatures-base = common-creatures.map(creature => ( id: creature.id, name: creature.name, difficulty: creature.profile-hse, region: creature.region, parts: creature.source.body-parts.len(), p1: phase-aggregate(creature, "p1"), p2: phase-aggregate(creature, "p2"), source: creature, )) #let durability-fields = ( (key: "threshold-average", label: "Seuil moyen", profile: "Seuil"), ( key: "protection-average", label: "Protection moyenne", profile: "Protection", ), (key: "integrity-total", label: "Intégrité totale", profile: "Intégrité"), (key: "life-total", label: "PV totaux", profile: "PV"), ) #let phase-field-values(phase, key) = durability-creatures-base.map(item => item .at(phase) .at(key)) #let durability-summary(phase, field) = { let values = phase-field-values(phase, field.key) let limits = extent(values) ( phase: phase, key: field.key, label: field.label, profile: field.profile, average: average(values), deviation: standard-deviation(values), min: limits.min, max: limits.max, ) } #let durability-summaries = ( ("p1", "p2") .map(phase => ( durability-fields.map(field => durability-summary(phase, field)) )) .flatten() ) #let summary-for(phase, key) = durability-summaries.find(item => ( item.phase == phase and item.key == key )) #let durability-zscore(item, phase, key) = { let summary = summary-for(phase, key) if summary.deviation == none or summary.deviation == 0 { 0 } else { (item.at(phase).at(key) - summary.average) / summary.deviation } } #let durability-signature(item, phase) = { let scores = durability-fields .map(field => ( label: field.profile, z: durability-zscore(item, phase, field.key), )) .sorted(key: score => -score.z) let leader = scores.first() if leader.z < 0.75 { "Équilibré" } else { leader.label } } #let durability-creatures = durability-creatures-base.map(item => ( item + ( p1-signature: durability-signature(item, "p1"), p2-signature: durability-signature(item, "p2"), ) )) #let average-parts = average(durability-creatures.map(item => item.parts)) #let durability-outliers = ( ("p1", "p2") .map(phase => durability-fields.map(field => { let summary = summary-for(phase, field.key) let observations = durability-creatures.map(item => ( creature: item, value: item.at(phase).at(field.key), z: durability-zscore(item, phase, field.key), )) ( phase: phase, field: field, summary: summary, low: observations .filter(item => item.z <= -1.5) .sorted(key: item => item.z), high: observations .filter(item => item.z >= 1.5) .sorted(key: item => -item.z), ) })) .flatten() )