V2.0 五大核心增强: 锚点定位/原生图表/插件架构/WebSocket/LLM智能

This commit is contained in:
2026-05-29 14:14:53 +08:00
parent 5546e5fca1
commit 8618867f92
51 changed files with 3368 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from plugins.base_generator import BaseGenerator
import pandas as pd
import numpy as np
from typing import Dict, Any
class GDPGenerator(BaseGenerator):
generator_id = "gdp_chart"
generator_name = "GDP趋势图表生成器"
description = "生成GDP季度增长率折线图原生数据"
version = "2.0.0"
params_schema = {
'year': {'type': 'int', 'default': 2026, 'description': '年份'},
'quarter': {'type': 'str', 'default': 'Q2', 'description': '季度'}
}
def fetch_data(self, params: Dict[str, Any] = None) -> bool:
p = {**self.params, **(params or {})}
year = p.get('year', 2026)
quarters = [f"{year-1}Q3", f"{year-1}Q4", f"{year}Q1", f"{year}Q2"]
self._data = pd.DataFrame({
'quarter': quarters,
'GDP同比': [5.2, 4.8, 5.0 + np.random.randn() * 0.3, 5.1 + np.random.randn() * 0.3],
'GDP环比': [1.6, 1.4, 1.2 + np.random.randn() * 0.2, 1.3 + np.random.randn() * 0.2]
})
self.logger.info(f"GDP数据获取成功{len(self._data)} 条记录")
return True
def render(self) -> Dict[str, Any]:
if self._data is None:
self.fetch_data()
categories = self._data['quarter'].tolist()
series = {
'GDP同比增长(%)': self._data['GDP同比'].round(2).tolist(),
'GDP环比增长(%)': self._data['GDP环比'].round(2).tolist()
}
return {
'chart_type': 'line',
'categories': categories,
'series': series,
'dataframe': self._data,
'anchor': 'chart_gdp',
'title': 'GDP增长趋势'
}