Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | 32x 4x 35x 41x 41x 32x 32x 32x 41x 41x 26x 41x 26x 41x 15x 29x 27x 33x 33x 27x 27x 25x 23x 23x 23x 23x 25x 25x 22x 1x 22x 23x 23x 25x 25x 25x 25x 25x 26x 26x 28x 25x 21x 24x 25x 24x 24x 24x 32x 8x 21x 24x 24x 21x 5x 4x 4x 4x 8x 8x 4x 4x 4x 5x 5x 5x 5x 5x 8x 5x 5x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module Generators/Builders/CommitteeBuilders
* @description Deep analysis, SWOT, dashboard, mindmap and multi-dimensional SWOT
* builders for committee report articles.
*/
import type {
DeepAnalysis,
CommitteeData,
LanguageCode,
SwotAnalysis,
DashboardConfig,
SwotBuilderStrings,
DashboardBuilderStrings,
IntelligenceMindmap,
MindmapNode,
ActorNode,
PolicyConnection,
StakeholderPerspective,
MultiDimensionalSwot,
TemporalSwotAssessment,
StakeholderType,
MindmapBranchColor,
} from '../../types/index.js';
import {
getLocalizedString,
COMMITTEE_ANALYSIS_CONTENT_STRINGS,
SWOT_BUILDER_STRINGS,
DASHBOARD_BUILDER_STRINGS,
} from '../../constants/languages.js';
import { isPlaceholderCommitteeData } from '../committee-helpers.js';
import { buildDefaultStakeholderPerspectives } from '../../utils/intelligence-analysis.js';
import { AI_MARKER } from '../../constants/analysis-constants.js';
import {
buildOutcomeMatrix,
buildCategoryDistributionPanel,
makeDimension,
} from './shared-builders.js';
// ─── Constant ─────────────────────────────────────────────────────────────────
/**
* Build multi-stakeholder perspectives for a committee reports analysis.
*
* @param activePct - Percentage of committees with documents (0-100)
* @param totalDocs - Total document count
* @param topic - Primary topic string for context
* @returns Array of stakeholder perspectives
*/
function buildCommitteeStakeholderPerspectives(
activePct: number,
totalDocs: number,
topic: string
): StakeholderPerspective[] {
return buildDefaultStakeholderPerspectives(topic, {
political_groups: activePct > 70 ? 0.8 : 0.5,
civil_society: totalDocs > 5 ? 0.6 : 0.4,
industry: totalDocs > 5 ? 0.7 : 0.4,
national_govts: activePct > 70 ? 0.7 : 0.4,
citizens: totalDocs > 5 ? 0.5 : 0.3,
eu_institutions: 0.8,
});
}
/**
* Build stakeholder views for committee multi-dimensional SWOT.
*
* @param active - Active committees
* @param committees - All committees
* @param totalDocs - Total document count
* @param inactiveCount - Number of inactive committees
* @param s - Localized SWOT builder strings
* @returns Stakeholder views map
*/
function buildCommitteeMDStakeholders(
active: readonly CommitteeData[],
committees: readonly CommitteeData[],
totalDocs: number,
inactiveCount: number,
s: SwotBuilderStrings
): Partial<Record<StakeholderType, SwotAnalysis>> {
return {
mep: {
strengths:
active.length > 0
? [
{
text: s.committeeActive(active.length, committees.length),
severity: 'high' as const,
},
]
: [],
weaknesses:
inactiveCount > 0
? [{ text: s.committeeInactive(inactiveCount), severity: 'medium' as const }]
: [],
opportunities: [{ text: s.committeeHearings, severity: 'medium' as const }],
threats: [{ text: s.committeeCompetingPriorities, severity: 'medium' as const }],
},
ngo: {
strengths:
totalDocs > 0
? [{ text: s.committeeDocuments(totalDocs), severity: 'medium' as const }]
: [],
weaknesses:
inactiveCount > committees.length * 0.3
? [{ text: s.committeeLowActivity, severity: 'high' as const }]
: [],
opportunities: [{ text: s.committeeCrossCollaboration, severity: 'medium' as const }],
threats: [],
},
};
}
/**
* Build deep analysis for committee reports articles.
*
* @param committees - Committee data list
* @param date - Publication date
* @param lang - Target language code for localized content
* @returns Deep analysis object, or `null` when all committee data is placeholder
*/
export function buildCommitteeAnalysis(
committees: readonly CommitteeData[],
date: string,
lang: LanguageCode = 'en'
): DeepAnalysis | null {
if (isPlaceholderCommitteeData(committees)) return null;
const totalDocs = committees.reduce((sum, c) => sum + c.documents.length, 0);
const activeCommittees = committees.filter((c) => c.documents.length > 0);
const s = getLocalizedString(COMMITTEE_ANALYSIS_CONTENT_STRINGS, lang);
const activePct = (activeCommittees.length / Math.max(committees.length, 1)) * 100;
return {
what:
totalDocs === 0
? s.whatNoData.replace('{date}', date).replace('{total}', String(committees.length))
: s.what
.replace('{date}', date)
.replace('{total}', String(committees.length))
.replace('{docs}', String(totalDocs))
.replace('{active}', String(activeCommittees.length)),
who: committees.map(
(c) =>
`${c.name} (${c.abbreviation}) — ${s.chairLabel} ${c.chair}, ${c.members} ${s.membersLabel}`
),
when: [
`${s.reportDateLabel} ${date}`,
...committees
.slice(0, 3)
.flatMap((c) =>
c.documents
.slice(0, 1)
.map((d) => `${c.abbreviation}: ${d.title}${d.date ? ` (${d.date})` : ''}`)
),
],
why: AI_MARKER,
stakeholderOutcomes: committees.slice(0, 4).map((c) => ({
actor: `${c.name} (${c.abbreviation})`,
outcome: (c.documents.length > 2
? 'winner'
: c.documents.length > 0
? 'neutral'
: 'loser') as 'winner' | 'loser' | 'neutral',
reason: AI_MARKER,
})),
impactAssessment: {
political: AI_MARKER,
economic: AI_MARKER,
social: AI_MARKER,
legal: AI_MARKER,
geopolitical: AI_MARKER,
},
actionConsequences: activeCommittees.slice(0, 3).map((c) => ({
action: s.actionProcessed
.replace('{abbr}', c.abbreviation)
.replace('{n}', String(c.documents.length)),
consequence: AI_MARKER,
severity: (c.documents.length > 3 ? 'high' : 'medium') as 'high' | 'medium',
})),
mistakes: committees
.filter((c) => c.documents.length === 0)
.slice(0, 2)
.map((c) => ({
actor: `${c.name} (${c.abbreviation})`,
description: `${c.name} (${c.abbreviation}) produced no documents in this period despite having ${c.members} members.`,
alternative: AI_MARKER,
})),
outlook: AI_MARKER,
stakeholderPerspectives: buildCommitteeStakeholderPerspectives(
activePct,
totalDocs,
committees[0]?.name ?? 'EP committees'
),
stakeholderOutcomeMatrix: buildOutcomeMatrix([
{
action: `Committee activity as of ${date} (${activeCommittees.length}/${committees.length} active)`,
scores: {
political_groups: activePct > 70 ? 0.8 : 0.5,
civil_society: totalDocs > 5 ? 0.6 : 0.4,
industry: totalDocs > 5 ? 0.7 : 0.4,
national_govts: activePct > 70 ? 0.7 : 0.4,
citizens: totalDocs > 5 ? 0.5 : 0.3,
eu_institutions: 0.8,
},
confidence: committees.length > 0 ? 'high' : 'low',
},
]),
};
}
/**
* Build SWOT analysis for committee reports articles.
*
* @param committees - Committee data list
* @param lang - Target language code
* @returns SWOT analysis data, or `null` when all committee data is placeholder
*/
export function buildCommitteeSwot(
committees: readonly CommitteeData[],
lang: LanguageCode = 'en'
): SwotAnalysis | null {
if (isPlaceholderCommitteeData(committees)) return null;
const s: SwotBuilderStrings = getLocalizedString(SWOT_BUILDER_STRINGS, lang);
const activeCommittees = committees.filter((c) => c.documents.length > 0);
const totalDocs = committees.reduce((sum, c) => sum + c.documents.length, 0);
const inactiveCount = committees.length - activeCommittees.length;
return {
strengths: [
...(activeCommittees.length > 0
? [
{
text: s.committeeActive(activeCommittees.length, committees.length),
severity:
activeCommittees.length >= committees.length * 0.7
? ('high' as const)
: ('medium' as const),
},
]
: []),
...(totalDocs > 0
? [
{
text: s.committeeDocuments(totalDocs),
severity: 'medium' as const,
},
]
: []),
],
weaknesses: [
...(inactiveCount > 0
? [
{
text: s.committeeInactive(inactiveCount),
severity:
inactiveCount > committees.length * 0.3 ? ('high' as const) : ('medium' as const),
},
]
: []),
],
opportunities: [
{
text: s.committeeCrossCollaboration,
severity: 'medium' as const,
},
...(committees.length > 0
? [
{
text: s.committeeHearings,
severity: 'medium' as const,
},
]
: []),
],
threats: [
...(inactiveCount > committees.length * 0.3
? [
{
text: s.committeeLowActivity,
severity: 'high' as const,
},
]
: []),
{
text: s.committeeCompetingPriorities,
severity: 'medium' as const,
},
],
};
}
/**
* Build dashboard for committee reports articles.
* Includes document trend analytics alongside committee activity metrics.
*
* @param committees - Committee data list
* @param lang - Target language code
* @returns Dashboard configuration, or `null` when all committee data is placeholder
*/
export function buildCommitteeDashboard(
committees: readonly CommitteeData[],
lang: LanguageCode = 'en'
): DashboardConfig | null {
if (isPlaceholderCommitteeData(committees)) return null;
const d: DashboardBuilderStrings = getLocalizedString(DASHBOARD_BUILDER_STRINGS, lang);
const activeCommittees = committees.filter((c) => c.documents.length > 0);
const totalDocs = committees.reduce((sum, c) => sum + c.documents.length, 0);
const activePct =
committees.length > 0 ? ((activeCommittees.length / committees.length) * 100).toFixed(0) : '0';
const overviewPanel = {
title: d.committeeOverview,
metrics: [
{ label: d.totalCommittees, value: String(committees.length) },
{
label: d.activeCommittees,
value: String(activeCommittees.length),
trend:
activeCommittees.length >= committees.length * 0.7 ? ('up' as const) : ('down' as const),
},
{ label: d.activityRate, value: `${activePct}%` },
{ label: d.documentsProduced, value: String(totalDocs) },
],
};
const chartPanel =
committees.length > 0
? (() => {
const topCommittees = [...committees]
.sort((a, b) => b.documents.length - a.documents.length)
.slice(0, 6);
return {
title: d.documentOutputByCommittee,
chart: {
type: 'bar' as const,
title: d.documentsPerCommittee,
data: {
labels: topCommittees.map((c) => c.abbreviation),
datasets: [
{
label: d.documents,
data: topCommittees.map((c) => c.documents.length),
},
],
},
},
};
})()
: null;
// Category distribution — shows document counts per committee (not a time-series trend)
const docCounts = committees.slice(0, 6).map((c) => c.documents.length);
const committeeLabels = committees.slice(0, 6).map((c) => c.abbreviation);
const trendPanel = buildCategoryDistributionPanel(
d,
committeeLabels,
docCounts,
d.documents,
d.documentsProduced
);
const panels = [
overviewPanel,
...(chartPanel ? [chartPanel] : []),
...(trendPanel ? [trendPanel] : []),
];
return { panels };
}
/**
* Build intelligence mindmap for committee reports articles.
*
* Maps committee activity as policy domain nodes with document output
* and inter-committee relationship indicators.
*
* @param committees - Committee data list
* @param _lang - Reserved for future localisation (default: 'en')
* @returns Intelligence mindmap data, or null when all data is placeholder
*/
export function buildCommitteeMindmap(
committees: readonly CommitteeData[],
_lang: LanguageCode = 'en'
): IntelligenceMindmap | null {
void _lang;
if (isPlaceholderCommitteeData(committees)) return null;
const activeCommittees = committees.filter((c) => c.documents.length > 0);
if (activeCommittees.length === 0) return null;
const domainNodes: MindmapNode[] = activeCommittees.slice(0, 8).map((c, i) => {
const influence = Math.min(1, c.documents.length / 10);
const children: MindmapNode[] = c.documents.slice(0, 3).map((doc, di) => ({
id: `doc-${i}-${di}`,
label: doc.title ? doc.title.slice(0, 50) : 'Committee document',
category: 'action' as const,
influence: 0.6,
color: 'blue' as const,
children: [],
metadata: { committee: c.abbreviation, documentRef: doc.title?.slice(0, 30) },
}));
const colors: readonly MindmapBranchColor[] = [
'green',
'cyan',
'blue',
'purple',
'orange',
'yellow',
'magenta',
'red',
];
return {
id: `committee-${c.abbreviation}`,
label: c.abbreviation,
category: 'policy_domain' as const,
influence,
color: colors[i % colors.length] ?? 'cyan',
children,
metadata: { committee: c.abbreviation },
};
});
const actorNetwork: ActorNode[] = activeCommittees.slice(0, 6).map((c, i) => ({
id: `committee-actor-${i}`,
name: c.abbreviation,
type: 'committee' as const,
influence: Math.min(1, c.documents.length / 10),
connections: domainNodes
.filter((n) => n.id !== `committee-${c.abbreviation}`)
.slice(0, 2)
.map((n) => n.id),
}));
const connections: PolicyConnection[] = activeCommittees.slice(0, 3).flatMap((c, i) =>
activeCommittees.slice(i + 1, i + 2).map((c2) => ({
from: `committee-${c.abbreviation}`,
to: `committee-${c2.abbreviation}`,
strength: 'moderate' as const,
type: 'thematic' as const,
evidence: `Inter-committee collaboration between ${c.abbreviation} and ${c2.abbreviation}`,
}))
);
const totalDocs = committees.reduce((sum, c) => sum + c.documents.length, 0);
return {
centralTopic: 'Committee Intelligence Network',
layers: [{ depth: 1, nodes: domainNodes }],
connections,
actorNetwork,
stakeholderGroups: ['MEPs', 'Political Groups', 'Secretariat', 'External Experts'],
summary: `${activeCommittees.length} active committees producing ${totalDocs} documents.`,
};
}
/**
* Build multi-dimensional SWOT analysis for committee reports articles.
*
* @param committees - Committee data list
* @param lang - Target language code
* @returns Multi-dimensional SWOT data, or `null` when all committee data is placeholder
*/
export function buildCommitteeMultiDimensionalSwot(
committees: readonly CommitteeData[],
lang: LanguageCode = 'en'
): MultiDimensionalSwot | null {
if (isPlaceholderCommitteeData(committees)) return null;
const s: SwotBuilderStrings = getLocalizedString(SWOT_BUILDER_STRINGS, lang);
const base = buildCommitteeSwot(committees, lang);
Iif (!base) return null;
const active = committees.filter((c) => c.documents.length > 0);
const totalDocs = committees.reduce((sum, c) => sum + c.documents.length, 0);
const inactiveCount = committees.length - active.length;
const highActivity = active.length >= committees.length * 0.7;
const political = makeDimension(
'political',
active.length > 0
? [
{
text: s.committeeActive(active.length, committees.length),
severity: highActivity ? ('high' as const) : ('medium' as const),
},
]
: [],
inactiveCount > committees.length * 0.3
? [{ text: s.committeeInactive(inactiveCount), severity: 'high' as const }]
: [],
[{ text: s.committeeCrossCollaboration, severity: 'medium' as const }],
inactiveCount > committees.length * 0.3
? [{ text: s.committeeLowActivity, severity: 'high' as const }]
: [{ text: s.committeeCompetingPriorities, severity: 'medium' as const }]
);
const economic = makeDimension(
'economic',
totalDocs > 0 ? [{ text: s.committeeDocuments(totalDocs), severity: 'medium' as const }] : [],
inactiveCount > 0
? [{ text: s.committeeInactive(inactiveCount), severity: 'medium' as const }]
: [],
committees.length > 0 ? [{ text: s.committeeHearings, severity: 'medium' as const }] : [],
[{ text: s.committeeCompetingPriorities, severity: 'medium' as const }]
);
const social = makeDimension(
'social',
active.length > 0
? [{ text: s.committeeActive(active.length, committees.length), severity: 'medium' as const }]
: [],
[],
[{ text: s.committeeCrossCollaboration, severity: 'medium' as const }],
[]
);
const legal = makeDimension(
'legal',
totalDocs > 0 ? [{ text: s.committeeDocuments(totalDocs), severity: 'high' as const }] : [],
inactiveCount > committees.length * 0.3
? [{ text: s.committeeInactive(inactiveCount), severity: 'high' as const }]
: [],
committees.length > 0 ? [{ text: s.committeeHearings, severity: 'medium' as const }] : [],
inactiveCount > committees.length * 0.3
? [{ text: s.committeeLowActivity, severity: 'high' as const }]
: []
);
const geopolitical = makeDimension(
'geopolitical',
[],
[],
[{ text: s.committeeCrossCollaboration, severity: 'medium' as const }],
[{ text: s.committeeCompetingPriorities, severity: 'medium' as const }]
);
const temporal: TemporalSwotAssessment = {
shortTerm: base,
mediumTerm: {
strengths: base.strengths.filter((i) => i.severity === 'high'),
weaknesses: base.weaknesses,
opportunities: base.opportunities,
threats: base.threats,
},
};
const stakeholderViews = buildCommitteeMDStakeholders(
active,
committees,
totalDocs,
inactiveCount,
s
);
return {
dimensions: [political, economic, social, legal, geopolitical],
temporal,
stakeholderViews,
};
}
|