update Export Data Farmat
This commit is contained in:
@@ -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} 没有有效的月度数据")
|
||||
|
||||
# 插入或更新数据
|
||||
|
||||
Reference in New Issue
Block a user