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 | 8x 1x 1x 1x 1x 1x 1x 1x 9x 9x 1x 1x 1x 1x 3x 2x 2x 2x 8x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module Generators/Strategies/WeeklyReviewStrategy
* @description Article strategy for the Week In Review article type.
* Fetches voting records, voting patterns, voting anomalies, and parliamentary
* questions from the past 7 days, then renders a retrospective analysis article.
*/
import type { EuropeanParliamentMCPClient } from '../../mcp/ep-mcp-client.js';
import { ArticleCategory } from '../../types/index.js';
import type {
LanguageCode,
DateRange,
VotingRecord,
VotingPattern,
VotingAnomaly,
MotionsQuestion,
} from '../../types/index.js';
import { WEEKLY_REVIEW_TITLES, getLocalizedString } from '../../constants/languages.js';
import {
fetchVotingRecords,
fetchVotingPatterns,
fetchMotionsAnomalies,
fetchParliamentaryQuestionsForMotions,
} from '../pipeline/fetch-stage.js';
import { generateMotionsContent } from '../motions-content.js';
import type { ArticleStrategy, ArticleData, ArticleMetadata } from './article-strategy.js';
// ─── Data payload ─────────────────────────────────────────────────────────────
/** Data fetched and pre-processed by {@link WeeklyReviewStrategy} */
export interface WeeklyReviewArticleData extends ArticleData {
/** Review period date range */
readonly dateRange: DateRange;
/** Voting records from the review period */
readonly votingRecords: readonly VotingRecord[];
/** Voting patterns analysis */
readonly votingPatterns: readonly VotingPattern[];
/** Detected voting anomalies */
readonly anomalies: readonly VotingAnomaly[];
/** Parliamentary questions from the period */
readonly questions: readonly MotionsQuestion[];
/** Start date string for display */
readonly dateFromStr: string;
}
/** Keywords shared by all Weekly Review articles */
const WEEKLY_REVIEW_KEYWORDS = [
'European Parliament',
'weekly review',
'voting records',
'parliamentary activity',
] as const;
// ─── Date-range helper ────────────────────────────────────────────────────────
/**
* Compute the review period covering the 7 days ending on `baseDate`.
*
* @param baseDate - ISO 8601 publication date (YYYY-MM-DD)
* @returns Date range covering the past 7 days
*/
function computeWeeklyReviewDateRange(baseDate: string): DateRange {
const end = new Date(`${baseDate}T00:00:00Z`);
const start = new Date(end);
start.setUTCDate(end.getUTCDate() - 7);
const startParts = start.toISOString().split('T');
const endParts = end.toISOString().split('T');
Iif (!startParts[0] || !endParts[0]) {
throw new Error('Invalid date format generated in computeWeeklyReviewDateRange');
}
return {
start: startParts[0],
end: endParts[0],
};
}
// ─── Strategy implementation ──────────────────────────────────────────────────
/**
* Article strategy for {@link ArticleCategory.WEEK_IN_REVIEW}.
* Fetches voting records, anomalies, patterns, and questions for the
* past 7 days and builds a retrospective analysis article.
*/
export class WeeklyReviewStrategy implements ArticleStrategy<WeeklyReviewArticleData> {
readonly type = ArticleCategory.WEEK_IN_REVIEW;
readonly requiredMCPTools = [
'get_voting_records',
'analyze_voting_patterns',
'detect_voting_anomalies',
'get_parliamentary_questions',
] as const;
/**
* Fetch weekly review data from MCP.
*
* @param client - MCP client or null
* @param date - ISO 8601 publication date
* @returns Populated weekly review data payload
*/
async fetchData(
client: EuropeanParliamentMCPClient | null,
date: string
): Promise<WeeklyReviewArticleData> {
const dateRange = computeWeeklyReviewDateRange(date);
console.log(` 📊 Weekly review range: ${dateRange.start} to ${dateRange.end}`);
const [votingRecords, votingPatterns, anomalies, questions] = await Promise.all([
fetchVotingRecords(client, dateRange.start, dateRange.end),
fetchVotingPatterns(client, dateRange.start, dateRange.end),
fetchMotionsAnomalies(client, dateRange.start, dateRange.end),
fetchParliamentaryQuestionsForMotions(client, dateRange.start, dateRange.end),
]);
return {
date,
dateRange,
dateFromStr: dateRange.start,
votingRecords,
votingPatterns,
anomalies,
questions,
};
}
/**
* Build the weekly review HTML body for the specified language.
*
* @param data - Weekly review data payload
* @param lang - Target language code used for editorial strings
* @returns Article HTML body
*/
buildContent(data: WeeklyReviewArticleData, lang: LanguageCode): string {
return generateMotionsContent(
data.dateRange.start,
data.dateRange.end,
[...data.votingRecords],
[...data.votingPatterns],
[...data.anomalies],
[...data.questions],
lang
);
}
/**
* Return language-specific metadata for the weekly review article.
*
* @param data - Weekly review data payload
* @param lang - Target language code
* @returns Localised metadata
*/
getMetadata(data: WeeklyReviewArticleData, lang: LanguageCode): ArticleMetadata {
const titleFn = getLocalizedString(WEEKLY_REVIEW_TITLES, lang);
const { title, subtitle } = titleFn(data.dateRange.start, data.dateRange.end);
return {
title,
subtitle,
keywords: [...WEEKLY_REVIEW_KEYWORDS],
category: ArticleCategory.WEEK_IN_REVIEW,
sources: [],
};
}
}
/** Singleton instance for use by the strategy registry */
export const weeklyReviewStrategy = new WeeklyReviewStrategy();
|