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 | 8x 8x 13x 13x 3x 3x 3x 3x 3x 3x 3x 12x 12x 12x 11x 1x 7x 7x 7x 8x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module Generators/Strategies/MotionsStrategy
* @description Article strategy for the Motions article type.
* Fetches voting records, patterns, anomalies and parliamentary questions
* over a rolling 30-day window then renders a voting-behaviour overview.
*/
import type { EuropeanParliamentMCPClient } from '../../mcp/ep-mcp-client.js';
import { ArticleCategory } from '../../types/index.js';
import type {
LanguageCode,
VotingRecord,
VotingPattern,
VotingAnomaly,
MotionsQuestion,
} from '../../types/index.js';
import { MOTIONS_TITLES, getLocalizedString } from '../../constants/languages.js';
import { fetchMotionsData } from '../pipeline/fetch-stage.js';
import { generateMotionsContent, buildPoliticalAlignmentSection } from '../motions-content.js';
import type { ArticleStrategy, ArticleData, ArticleMetadata } from './article-strategy.js';
/** Keywords shared by all Motions articles */
const MOTIONS_KEYWORDS = [
'European Parliament',
'motions',
'voting records',
'party cohesion',
'parliamentary questions',
] as const;
/** Number of days to look back when fetching motions data */
const MOTIONS_LOOKBACK_DAYS = 30;
// ─── Data payload ─────────────────────────────────────────────────────────────
/** Data fetched and pre-processed by {@link MotionsStrategy} */
export interface MotionsArticleData extends ArticleData {
/** Start of the 30-day look-back window */
readonly dateFromStr: string;
/** Voting records for the period */
readonly votingRecords: readonly VotingRecord[];
/** Voting patterns for the period */
readonly votingPatterns: readonly VotingPattern[];
/** Voting anomalies detected in the period */
readonly anomalies: readonly VotingAnomaly[];
/** Parliamentary questions raised in the period */
readonly questions: readonly MotionsQuestion[];
}
// ─── Strategy implementation ──────────────────────────────────────────────────
/**
* Article strategy for {@link ArticleCategory.MOTIONS}.
* Aggregates voting data over a rolling 30-day window and surfaces
* patterns, anomalies and parliamentary questions.
*/
export class MotionsStrategy implements ArticleStrategy<MotionsArticleData> {
readonly type = ArticleCategory.MOTIONS;
readonly requiredMCPTools = [
'get_voting_records',
'analyze_voting_patterns',
'detect_voting_anomalies',
'get_parliamentary_questions',
] as const;
/**
* Fetch all motions data for the last 30 days.
*
* @param client - MCP client or null
* @param date - ISO 8601 publication date (end of the look-back window)
* @returns Populated motions data payload
*/
async fetchData(
client: EuropeanParliamentMCPClient | null,
date: string
): Promise<MotionsArticleData> {
const dateFrom = new Date(`${date}T00:00:00Z`);
dateFrom.setUTCDate(dateFrom.getUTCDate() - MOTIONS_LOOKBACK_DAYS);
const dateFromParts = dateFrom.toISOString().split('T');
Iif (!dateFromParts[0]) {
throw new Error('Invalid date format generated for motions look-back window');
}
const dateFromStr = dateFromParts[0];
const { votingRecords, votingPatterns, anomalies, questions } = await fetchMotionsData(
client,
dateFromStr,
date
);
return {
date,
dateFromStr,
votingRecords,
votingPatterns,
anomalies,
questions,
};
}
/**
* Build the motions HTML body for the specified language.
*
* @param data - Motions data payload
* @param lang - Target language code used for editorial strings
* @returns Article HTML body
*/
buildContent(data: MotionsArticleData, lang: LanguageCode): string {
const base = generateMotionsContent(
data.dateFromStr,
data.date,
[...data.votingRecords],
[...data.votingPatterns],
[...data.anomalies],
[...data.questions],
lang
);
const alignmentSection = buildPoliticalAlignmentSection([...data.votingRecords], [], lang);
// Inject at the explicit <!-- /article-content --> marker so the section
// stays inside the .article-content styling scope. The marker is always
// emitted by generateMotionsContent as the last child of that wrapper and
// is removed from the final HTML during this replacement.
if (alignmentSection) {
return base.replace('<!-- /article-content -->', `${alignmentSection}\n`);
}
return base.replace('<!-- /article-content -->', '');
}
/**
* Return language-specific metadata for the motions article.
*
* @param data - Motions data payload
* @param lang - Target language code
* @returns Localised metadata
*/
getMetadata(data: MotionsArticleData, lang: LanguageCode): ArticleMetadata {
const titleFn = getLocalizedString(MOTIONS_TITLES, lang);
const { title, subtitle } = titleFn(data.date);
return {
title,
subtitle,
keywords: [...MOTIONS_KEYWORDS],
category: ArticleCategory.MOTIONS,
sources: [],
};
}
}
/** Singleton instance for use by the strategy registry */
export const motionsStrategy = new MotionsStrategy();
|