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,62 @@
import pandas as pd
import numpy as np
from pathlib import Path
from loguru import logger
import matplotlib.pyplot as plt
def generate(output_dir):
logger.info("开始生成就业数据表")
categories = ['城镇调查失业率', '青年失业率', '制造业PMI', '服务业PMI']
current = [5.1, 15.3, 49.8, 53.2]
previous = [5.2, 15.6, 49.5, 53.0]
change = [c - p for c, p in zip(current, previous)]
data = pd.DataFrame({
'指标': categories,
'当前值': current,
'上期值': previous,
'变动': change
})
fig, ax = plt.subplots(figsize=(10, 6))
ax.axis('tight')
ax.axis('off')
table_data = []
for _, row in data.iterrows():
change_color = '#4CAF50' if row['变动'] >= 0 else '#F44336'
table_data.append([
row['指标'],
f"{row['当前值']:.1f}",
f"{row['上期值']:.1f}",
f"{row['变动']:+.1f}"
])
table = ax.table(
cellText=table_data,
colLabels=['指标', '当前值', '上期值', '变动'],
cellLoc='center',
loc='center',
colColours=['#4A90E2'] * 4
)
table.auto_set_font_size(False)
table.set_fontsize(12)
table.scale(1, 2)
for key, cell in table.get_celld().items():
if key[0] > 0 and key[1] == 3:
cell.set_text_props(color='green' if '+' in cell.get_text().get_text() else 'red')
ax.set_title('就业与PMI数据摘要', fontsize=16, fontweight='bold', pad=20)
output_path = Path(output_dir) / 'employment_table.png'
plt.savefig(str(output_path), dpi=150, bbox_inches='tight')
plt.close()
logger.info(f"就业数据表已生成: {output_path}")
return str(output_path)
if __name__ == "__main__":
generate(Path.cwd())

View File

@@ -0,0 +1,32 @@
import pandas as pd
import numpy as np
from pathlib import Path
from loguru import logger
def generate(output_dir):
logger.info("开始生成GDP趋势图表")
quarters = ['2024Q1', '2024Q2', '2024Q3', '2024Q4', '2025Q1', '2025Q2']
gdp_growth = [5.2, 4.8, 5.0, 5.3, np.random.uniform(4.5, 5.5), np.random.uniform(4.5, 5.5)]
data = pd.DataFrame({
'季度': quarters,
'GDP增长率(%)': [round(x, 2) for x in gdp_growth]
})
data = data.set_index('季度')
from dynamic_generator import DynamicContentGenerator
generator = DynamicContentGenerator()
output_path = generator.generate_chart_matplotlib(
data,
title='中国GDP增长趋势',
x_label='季度',
y_label='增长率 (%)',
filename='gdp_chart.png',
kind='line'
)
return output_path
if __name__ == "__main__":
generate(Path.cwd())

View File

@@ -0,0 +1,34 @@
import pandas as pd
import numpy as np
from pathlib import Path
from loguru import logger
def generate(output_dir):
logger.info("开始生成CPI/PPI通胀图表")
months = ['1月', '2月', '3月', '4月', '5月', '6月']
cpi = [0.7, 0.8, 0.9, 1.0, np.random.uniform(0.8, 1.2), np.random.uniform(0.8, 1.2)]
ppi = [-2.5, -2.3, -2.0, -1.8, np.random.uniform(-2.5, -1.5), np.random.uniform(-2.5, -1.5)]
data = pd.DataFrame({
'月份': months,
'CPI(%)': [round(x, 2) for x in cpi],
'PPI(%)': [round(x, 2) for x in ppi]
})
data = data.set_index('月份')
from dynamic_generator import DynamicContentGenerator
generator = DynamicContentGenerator()
output_path = generator.generate_chart_plotly(
data,
title='CPI与PPI走势',
x_label='月份',
y_label='同比 (%)',
filename='inflation_chart.png',
kind='line'
)
return output_path
if __name__ == "__main__":
generate(Path.cwd())

View File

@@ -0,0 +1,66 @@
import pandas as pd
import numpy as np
from loguru import logger
def generate(output_dir):
logger.info("开始生成市场分析图")
indices = ['上证指数', '深证成指', '创业板指', '沪深300']
current = [3150, 10200, 2050, 3800]
change_pct = [
np.random.uniform(-2, 2),
np.random.uniform(-2, 2),
np.random.uniform(-2, 2),
np.random.uniform(-2, 2)
]
data = pd.DataFrame({
'指数': indices,
'点位': current,
'涨跌幅(%)': [round(x, 2) for x in change_pct]
})
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei']
plt.rcParams['axes.unicode_minus'] = False
colors = ['green' if x < 0 else 'red' for x in change_pct]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 7))
bars = ax1.bar(data['指数'], data['点位'], color=colors, alpha=0.7)
ax1.set_title('主要指数点位', fontsize=14, fontweight='bold')
ax1.set_ylabel('点位')
ax1.grid(axis='y', linestyle='--', alpha=0.3)
for bar in bars:
height = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2., height,
f'{int(height)}', ha='center', va='bottom')
bars2 = ax2.bar(data['指数'], data['涨跌幅(%)'], color=colors, alpha=0.7)
ax2.set_title('涨跌幅', fontsize=14, fontweight='bold')
ax2.set_ylabel('涨跌幅 (%)')
ax2.axhline(y=0, color='black', linestyle='-', linewidth=0.5)
ax2.grid(axis='y', linestyle='--', alpha=0.3)
for bar in bars2:
height = bar.get_height()
va = 'bottom' if height > 0 else 'top'
ax2.text(bar.get_x() + bar.get_width()/2., height,
f'{height:+.2f}%', ha='center', va=va, fontweight='bold')
plt.suptitle('A股市场概况', fontsize=18, fontweight='bold')
plt.tight_layout()
from pathlib import Path
output_path = Path(output_dir) / 'market_analysis.png'
plt.savefig(str(output_path), dpi=150, bbox_inches='tight')
plt.close()
logger.info(f"市场分析图已生成: {output_path}")
return str(output_path)
if __name__ == "__main__":
from pathlib import Path
generate(Path.cwd())

View File

@@ -0,0 +1,34 @@
import pandas as pd
import numpy as np
from loguru import logger
def generate(output_dir):
logger.info("开始生成进出口贸易图表")
months = ['1月', '2月', '3月', '4月', '5月', '6月']
exports = np.random.randint(2800, 3200, 6)
imports = np.random.randint(2000, 2400, 6)
data = pd.DataFrame({
'月份': months,
'出口(亿美元)': exports,
'进口(亿美元)': imports
})
data = data.set_index('月份')
from dynamic_generator import DynamicContentGenerator
generator = DynamicContentGenerator()
output_path = generator.generate_chart_matplotlib(
data,
title='进出口贸易情况',
x_label='月份',
y_label='金额 (亿美元)',
filename='trade_chart.png',
kind='bar'
)
return output_path
if __name__ == "__main__":
from pathlib import Path
generate(Path.cwd())