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 | 8x 11x 53x 53x 53x 55x 55x 51x 51x 51x 51x 55x 20x 17x 25x 25x 25x 25x 17x 20x 7x 13x 7x 22x 20x 20x 20x 20x 20x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module Generators/MotionsContent
* @description Pure functions for building motions article HTML and
* generating placeholder/fallback data when MCP is unavailable.
*/
import { escapeHTML } from '../utils/file-utils.js';
import { getLocalizedString, EDITORIAL_STRINGS, MOTIONS_STRINGS } from '../constants/languages.js';
import type {
VotingRecord,
VotingPattern,
VotingAnomaly,
MotionsQuestion,
CoalitionIntelligence,
} from '../types/index.js';
/** Marker string used in all fallback/placeholder data to indicate MCP data is unavailable */
export const PLACEHOLDER_MARKER = 'DATA_UNAVAILABLE (placeholder)';
/**
* Get fallback data for motions article
*
* @param dateStr - Current date string
* @param dateFromStr - Start date string
* @returns Object with all fallback data arrays
*/
export function getMotionsFallbackData(
dateStr: string,
dateFromStr: string
): {
votingRecords: VotingRecord[];
votingPatterns: VotingPattern[];
anomalies: VotingAnomaly[];
questions: MotionsQuestion[];
} {
return {
votingRecords: [
{
title: 'Example motion (placeholder – data unavailable)',
date: dateStr,
result: PLACEHOLDER_MARKER,
votes: { for: 0, against: 0, abstain: 0 },
},
{
title: 'Example amendment (placeholder – data unavailable)',
date: dateFromStr,
result: PLACEHOLDER_MARKER,
votes: { for: 0, against: 0, abstain: 0 },
},
],
votingPatterns: [
{
group: 'Example group A (placeholder)',
cohesion: 0.0,
participation: 0.0,
},
{
group: 'Example group B (placeholder)',
cohesion: 0.0,
participation: 0.0,
},
],
anomalies: [
{
type: 'Placeholder example',
description:
'No real anomaly data available from MCP – this is illustrative placeholder content only.',
severity: 'LOW',
},
],
questions: [
{
author: 'Placeholder MEP 1',
topic: 'Placeholder parliamentary question on energy security (MCP data unavailable)',
date: dateStr,
status: PLACEHOLDER_MARKER,
},
{
author: 'Placeholder MEP 2',
topic: 'Placeholder parliamentary question on migration policy (MCP data unavailable)',
date: dateFromStr,
status: PLACEHOLDER_MARKER,
},
],
};
}
/**
* Generate HTML content for motions article
*
* @param dateFromStr - Start date
* @param dateStr - End date
* @param votingRecords - Voting records data
* @param votingPatterns - Voting patterns data
* @param anomalies - Anomalies data
* @param questions - Questions data
* @param lang - Language code for editorial strings (default: 'en')
* @returns HTML content string
*/
export function generateMotionsContent(
dateFromStr: string,
dateStr: string,
votingRecords: VotingRecord[],
votingPatterns: VotingPattern[],
anomalies: VotingAnomaly[],
questions: MotionsQuestion[],
lang = 'en'
): string {
const editorial = getLocalizedString(EDITORIAL_STRINGS, lang);
const strings = getLocalizedString(MOTIONS_STRINGS, lang);
return `
<div class="article-content">
<section class="lede">
<p>${escapeHTML(strings.lede)} ${escapeHTML(editorial.sourceAttribution)}, analysis of voting records from ${escapeHTML(dateFromStr)} to ${escapeHTML(dateStr)} provides insights into legislative decision-making and party discipline.</p>
</section>
<section class="voting-results">
<h2>${escapeHTML(strings.votingRecordsHeading)}</h2>
${votingRecords
.map(
(record) => `
<div class="vote-item">
<h3>${escapeHTML(record.title)}</h3>
<p class="vote-date">${escapeHTML(strings.dateLabel)}: ${escapeHTML(record.date)}</p>
<p class="vote-result"><strong>${escapeHTML(strings.resultLabel)}:</strong> ${escapeHTML(record.result)}</p>
<div class="vote-breakdown">
<span class="vote-for">${escapeHTML(strings.forLabel)}: ${escapeHTML(String(record.votes.for))}</span>
<span class="vote-against">${escapeHTML(strings.againstLabel)}: ${escapeHTML(String(record.votes.against))}</span>
<span class="vote-abstain">${escapeHTML(strings.abstainLabel)}: ${escapeHTML(String(record.votes.abstain))}</span>
</div>
</div>
`
)
.join('')}
</section>
<section class="voting-patterns">
<h2>${escapeHTML(strings.partyCohesionHeading)}</h2>
<p>${escapeHTML(editorial.parliamentaryContext)}: Analysis of voting behavior reveals varying levels of party discipline across political groups:</p>
${votingPatterns
.map(
(pattern) => `
<div class="pattern-item">
<h3>${escapeHTML(pattern.group)}</h3>
<p><strong>${escapeHTML(strings.cohesionLabel)}:</strong> ${escapeHTML(String((pattern.cohesion * 100).toFixed(1)))}%</p>
<p><strong>${escapeHTML(strings.participationLabel)}:</strong> ${escapeHTML(String((pattern.participation * 100).toFixed(1)))}%</p>
</div>
`
)
.join('')}
</section>
<section class="anomalies">
<h2>${escapeHTML(strings.anomaliesHeading)}</h2>
<p>${escapeHTML(editorial.analysisNote)}: Unusual voting patterns that deviate from typical party lines:</p>
${anomalies
.map((anomaly) => {
const rawSeverity = anomaly.severity ?? 'unknown';
const severityDisplay =
typeof rawSeverity === 'string' ? rawSeverity : String(rawSeverity);
const severityClass = severityDisplay.toLowerCase();
return `
<div class="anomaly-item severity-${escapeHTML(severityClass)}">
<h3>${escapeHTML(anomaly.type)}</h3>
<p>${escapeHTML(anomaly.description)}</p>
<p class="severity">${escapeHTML(strings.severityLabel)}: ${escapeHTML(severityDisplay)}</p>
</div>
`;
})
.join('')}
</section>
<section class="questions">
<h2>${escapeHTML(strings.questionsHeading)}</h2>
${questions
.map(
(question) => `
<div class="question-item">
<p class="question-author">${escapeHTML(question.author)}</p>
<p class="question-topic"><strong>${escapeHTML(question.topic)}</strong></p>
<p class="question-meta">${escapeHTML(strings.dateLabel)}: ${escapeHTML(question.date)} | ${escapeHTML(strings.statusLabel)}: ${escapeHTML(question.status)}</p>
</div>
`
)
.join('')}
</section>
<section class="why-this-matters">
<h2>${escapeHTML(editorial.whyThisMatters)}</h2>
<p>${escapeHTML(editorial.keyTakeaway)}: ${escapeHTML(strings.keyTakeawayText)}</p>
</section>
<!-- /article-content -->
</div>
`;
}
// ─── Political Alignment section ──────────────────────────────────────────────
/**
* Build HTML list items for voting record alignment rows
*
* @param records - Voting records to render
* @returns HTML list items string
*/
function buildVoteAlignmentHtml(records: VotingRecord[]): string {
if (records.length === 0) return '';
const items = records
.map((r) => {
const forVotes = escapeHTML(String(r.votes.for));
const againstVotes = escapeHTML(String(r.votes.against));
const abstainVotes = escapeHTML(String(r.votes.abstain));
return (
`<li class="alignment-vote">` +
`<strong>${escapeHTML(r.title)}</strong> — ` +
`${escapeHTML(r.result)} ` +
`(${forVotes}+ / ${againstVotes}− / ${abstainVotes} abstain)` +
`</li>`
);
})
.join('\n ');
return `<ul class="alignment-votes">\n ${items}\n </ul>`;
}
/**
* Build HTML list items for coalition alignment rows
*
* @param coalitions - Coalition intelligence items to render
* @returns HTML list items string
*/
function buildCoalitionAlignmentHtml(coalitions: CoalitionIntelligence[]): string {
if (coalitions.length === 0) return '';
const items = coalitions
.map(
(c) =>
`<li class="alignment-coalition alignment-${escapeHTML(c.riskLevel)}">` +
`${escapeHTML(c.groups.join(', '))} — ` +
`cohesion: ${escapeHTML(String(Math.round(c.cohesionScore * 100)))}% ` +
`(${escapeHTML(c.alignmentTrend)})</li>`
)
.join('\n ');
return `<ul class="alignment-coalitions">\n ${items}\n </ul>`;
}
/**
* Build political alignment analysis section for motions, showing how
* voting records map to coalition cohesion and cross-party dynamics.
* Returns an empty string when both input arrays are empty or yield no items.
*
* @param votingRecords - Voting records to analyse
* @param coalitions - Coalition intelligence data from MCP
* @param language - BCP 47 language code used as the section lang attribute
* @returns HTML string for the political alignment section
*/
export function buildPoliticalAlignmentSection(
votingRecords: VotingRecord[],
coalitions: CoalitionIntelligence[],
language: string
): string {
if (votingRecords.length === 0 && coalitions.length === 0) return '';
const recordsHtml = buildVoteAlignmentHtml(votingRecords);
const coalitionsHtml = buildCoalitionAlignmentHtml(coalitions);
Iif (!recordsHtml && !coalitionsHtml) return '';
const strings = getLocalizedString(MOTIONS_STRINGS, language);
return `
<section class="political-alignment" lang="${escapeHTML(language)}">
<h2>${escapeHTML(strings.politicalAlignmentHeading)}</h2>
${recordsHtml}
${coalitionsHtml}
</section>`;
}
|