update Export Data Farmat

This commit is contained in:
2025-08-28 22:09:59 +08:00
parent debbf6e8c1
commit 41beb2ec33
4 changed files with 11 additions and 32 deletions

View File

@@ -45,11 +45,11 @@ class DataExporter:
field_names = [col['COLUMN_NAME'] for col in columns
if col['COLUMN_NAME'] not in ('id', 'update_time')]
# 查询数据
# 查询数据, 按照 avg_all 字段倒叙排列
data = db.execute_query(f"""
SELECT {', '.join(field_names)}
FROM {table_name}
ORDER BY stock_code
ORDER BY avg_all DESC
""")
if not data:

View File

@@ -31,33 +31,6 @@ class MarketDataCalculator:
- 导出数据到CSV文件
"""
# # 表头映射配置
# HEADER_MAP = {
# 'stock_code': '股票代码',
# 'stock_name': '股票名称',
# 'ym_2501': '2025年01月',
# 'ym_2502': '2025年02月',
# 'ym_2503': '2025年03月',
# 'ym_2504': '2025年04月',
# 'ym_2505': '2025年05月',
# 'ym_2506': '2025年06月',
# 'ym_2507': '2025年07月',
# 'ym_2508': '2025年08月',
# 'avg_all': '月度均值'
# }
# # 月份范围配置
# MONTH_RANGES = {
# 'ym_2501': ('2025-01-01', '2025-01-31'),
# 'ym_2502': ('2025-02-01', '2025-02-28'),
# 'ym_2503': ('2025-03-01', '2025-03-31'),
# 'ym_2504': ('2025-04-01', '2025-04-30'),
# 'ym_2505': ('2025-05-01', '2025-05-31'),
# 'ym_2506': ('2025-06-01', '2025-06-30'),
# 'ym_2507': ('2025-07-01', '2025-07-31'),
# 'ym_2508': ('2025-08-01', '2025-08-31')
# }
def __init__(self, db_config: dict, logger_name: str = 'Calculate'):
"""
初始化市场数据计算器
@@ -155,7 +128,9 @@ class MarketDataCalculator:
""".format(source_table)
result = db.execute_query(sql, (stock_code, start_date, end_date))
monthly_data[month_col] = float(result[0]['avg_close']) * 1000 if result and result[0]['avg_close'] else None
# 保存小数点后两位,以亿为单位
# monthly_data[month_col] = float(result[0]['avg_close']) * 1000 if result and result[0]['avg_close'] else None
monthly_data[month_col] = round(float(result[0]['avg_close']) * 1000 / 100000000, 3) if result and result[0]['avg_close'] else None
# 提取所有以 'ym_' 开头的键的值
ym_values = [value for key, value in monthly_data.items() if key.startswith('ym_')]
@@ -167,6 +142,7 @@ class MarketDataCalculator:
monthly_data['avg_all'] = average
self.logger.debug(f"股票 {stock_code} 月间流通市值平均值为: {average}")
else:
monthly_data['avg_all'] = 0 # 给一个空值,保证数据库不报错
self.logger.warning(f"股票 {stock_code} 没有有效的月度数据")
# 插入或更新数据

View File

@@ -362,7 +362,7 @@ class KLineUpdater:
# 这里可以添加具体的更新逻辑
# 例如:遍历股票代码,获取数据并保存到数据库
# 每天收盘后更新数据 -> 操作界面中,这个参数需要放出来
start_date = (datetime.now() - timedelta(days = 3 * 356)).strftime("%Y-%m-%d")
start_date = (datetime.now() - timedelta(days = 1)).strftime("%Y-%m-%d")
end_date = (datetime.now() + timedelta(days = 1)).strftime("%Y-%m-%d")
# 获取流通股数据字典

View File

@@ -892,4 +892,7 @@ HK.01591
HK.01715
HK.00489
HK.08218
HK.06960
HK.06960
HK.02936
HK.03858
HK.08132