feat: 添加相关股票模块

This commit is contained in:
zdl
2025-11-01 12:19:47 +08:00
parent 571d5e68bc
commit 3b8b749eb1
6 changed files with 663 additions and 15 deletions

View File

@@ -747,6 +747,33 @@ export function generateMockEvents(params = {}) {
const relatedAvgChg = (Math.random() * 20 - 5).toFixed(2); // -5% 到 15%
const relatedMaxChg = (Math.random() * 30).toFixed(2); // 0% 到 30%
// 生成价格走势数据(前一天、当天、后一天)
const generatePriceTrend = (seed) => {
const basePrice = 10 + (seed % 90); // 基础价格 10-100
const trend = [];
// 前一天5个数据点
let price = basePrice;
for (let i = 0; i < 5; i++) {
price = price + (Math.random() - 0.5) * 0.5;
trend.push(parseFloat(price.toFixed(2)));
}
// 当天5个数据点
for (let i = 0; i < 5; i++) {
price = price + (Math.random() - 0.4) * 0.8; // 轻微上涨趋势
trend.push(parseFloat(price.toFixed(2)));
}
// 后一天5个数据点
for (let i = 0; i < 5; i++) {
price = price + (Math.random() - 0.45) * 1.0;
trend.push(parseFloat(price.toFixed(2)));
}
return trend;
};
// 为每个事件随机选择2-5个相关股票
const relatedStockCount = 2 + (i % 4); // 2-5个股票
const relatedStocks = [];
@@ -758,10 +785,16 @@ export function generateMockEvents(params = {}) {
for (let j = 0; j < Math.min(relatedStockCount, industryStocks.length); j++) {
const stock = industryStocks[j % industryStocks.length];
if (!addedStockCodes.has(stock.stock_code)) {
const dailyChange = (Math.random() * 6 - 2).toFixed(2); // -2% ~ +4%
const weekChange = (Math.random() * 10 - 3).toFixed(2); // -3% ~ +7%
relatedStocks.push({
stock_name: stock.stock_name,
stock_code: stock.stock_code,
relation_desc: relationDescTemplates[(i + j) % relationDescTemplates.length]
relation_desc: relationDescTemplates[(i + j) % relationDescTemplates.length],
daily_change: dailyChange,
week_change: weekChange,
price_trend: generatePriceTrend(i * 100 + j)
});
addedStockCodes.add(stock.stock_code);
}
@@ -773,10 +806,16 @@ export function generateMockEvents(params = {}) {
while (relatedStocks.length < relatedStockCount && poolIndex < stockPool.length) {
const randomStock = stockPool[poolIndex % stockPool.length];
if (!addedStockCodes.has(randomStock.stock_code)) {
const dailyChange = (Math.random() * 6 - 2).toFixed(2); // -2% ~ +4%
const weekChange = (Math.random() * 10 - 3).toFixed(2); // -3% ~ +7%
relatedStocks.push({
stock_name: randomStock.stock_name,
stock_code: randomStock.stock_code,
relation_desc: relationDescTemplates[(i + poolIndex) % relationDescTemplates.length]
relation_desc: relationDescTemplates[(i + poolIndex) % relationDescTemplates.length],
daily_change: dailyChange,
week_change: weekChange,
price_trend: generatePriceTrend(i * 100 + poolIndex)
});
addedStockCodes.add(randomStock.stock_code);
}