非标业绩提报test文件夹整理
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
# 添加父目录到系统路径,以便导入模块
|
||||||
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
from back_ground_module import CommonModule
|
||||||
|
|
||||||
|
# 创建公共模块实例
|
||||||
|
common_module = CommonModule()
|
||||||
|
|
||||||
|
# 设置输出目录
|
||||||
|
output_dir = "../test/output"
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
def save_data_yichang_to_csv():
|
||||||
|
"""
|
||||||
|
获取异常明细数据并保存到CSV文件
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
print("开始获取异常明细数据...")
|
||||||
|
|
||||||
|
# 获取前一天的异常数据
|
||||||
|
data_yichang_S = common_module.get_yichang_details(days_back=1)
|
||||||
|
|
||||||
|
if data_yichang_S is None or data_yichang_S.empty:
|
||||||
|
print("未获取到数据或数据为空")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 转换为字符串类型
|
||||||
|
data_yichang_S = data_yichang_S.astype(str)
|
||||||
|
|
||||||
|
# 生成文件名(包含日期)
|
||||||
|
current_date = datetime.datetime.now().strftime("%Y%m%d")
|
||||||
|
filename = f"data_yichang_{current_date}.csv"
|
||||||
|
filepath = os.path.join(output_dir, filename)
|
||||||
|
|
||||||
|
# 保存到CSV
|
||||||
|
data_yichang_S.to_csv(filepath, index=False, encoding='utf-8-sig')
|
||||||
|
|
||||||
|
print(f"数据已成功保存到: {filepath}")
|
||||||
|
print(f"数据行数: {len(data_yichang_S)}")
|
||||||
|
print(f"数据列数: {len(data_yichang_S.columns)}")
|
||||||
|
print(f"\n列名:\n{list(data_yichang_S.columns)}")
|
||||||
|
|
||||||
|
# 显示前5行数据预览
|
||||||
|
print(f"\n数据预览(前5行):")
|
||||||
|
print(data_yichang_S.head())
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"保存数据时发生错误: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
save_data_yichang_to_csv()
|
||||||
|
|
||||||
Reference in New Issue
Block a user