|
|
|
@ -10,10 +10,10 @@ from docx import Document
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from docx.shared import Inches, Pt
|
|
|
|
|
from app.tools.deal_excels import deal_excel, top5_dod_analysis, transform_data
|
|
|
|
|
from app.tools.deal_excels import deal_excel, top5_dod_analysis, transform_data, deal_excel_over_load
|
|
|
|
|
from app.tools.get_time import get_time
|
|
|
|
|
from app.tools.replace_text import replace_text_in_docx
|
|
|
|
|
from app.tools.replace_table import copy_table, copy_sta_table, copy_table_no_align
|
|
|
|
|
from app.tools.replace_table import copy_table, copy_sta_table
|
|
|
|
|
from app.tools.style import table_style
|
|
|
|
|
from app.tools.effective_date import get_next_day
|
|
|
|
|
from app.tools.find_before_word import extract_overload_info_from_previous_day
|
|
|
|
@ -61,8 +61,12 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
file_path_dict["power_off_excel"] = folder_path + "/" + file
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if file.endswith(".xlsx") and "停电报表配变明细" in file:
|
|
|
|
|
file_path_dict["over_load_excel"] = folder_path + "/" + file
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# 如果传入的文件不对,抛出异常
|
|
|
|
|
if len(file_path_dict) != 3:
|
|
|
|
|
if len(file_path_dict) != 4:
|
|
|
|
|
logger.exception("文件格式错误")
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=400,
|
|
|
|
@ -104,13 +108,29 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if "first_point_para2" not in doc_dict:
|
|
|
|
|
if re.match(r".*抢修工单.*", para.text):
|
|
|
|
|
# print(para.text)
|
|
|
|
|
doc_dict["first_point_para2"] = re.sub(
|
|
|
|
|
r"[,,]整体抢修工作态势正常。+$", "", para.text
|
|
|
|
|
)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# 第二点过载台数
|
|
|
|
|
if re.search(r"过载(\d+)(?:[条台]|\s*)?", para.text):
|
|
|
|
|
doc_dict["over_load"] = (
|
|
|
|
|
re.search(r"过载(\d+)(?:[条台]|\s*)?", para.text).group().replace("过载", "")
|
|
|
|
|
).replace("条", "").replace("台", "")
|
|
|
|
|
# print(doc_dict['over_load'])
|
|
|
|
|
continue
|
|
|
|
|
"""
|
|
|
|
|
if re.search(r"过载\d+台", para.text):
|
|
|
|
|
doc_dict["over_load"] = (
|
|
|
|
|
re.search(r"过载\d+台", para.text).group().replace("过载", "")
|
|
|
|
|
).replace("台", "")
|
|
|
|
|
# print(doc_dict['over_load'])
|
|
|
|
|
continue
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# 拿到舆情的段落
|
|
|
|
|
paragraphs_sentiment = doc_sentiment.paragraphs
|
|
|
|
@ -137,11 +157,12 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
table1 = tables[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 表2配变过载监测汇总表
|
|
|
|
|
table2 = tables[1]
|
|
|
|
|
# 表2配变过载监测汇总表——配变过载集成到了一张表table1
|
|
|
|
|
#table2 = tables[1]
|
|
|
|
|
|
|
|
|
|
# 表3停电用户前五供电局
|
|
|
|
|
table3 = tables[2]
|
|
|
|
|
# 表3停电用户前五供电局——停电前五移动到了第二张表
|
|
|
|
|
table3 = tables[1]
|
|
|
|
|
#table3 = tables[2]
|
|
|
|
|
|
|
|
|
|
# 新增表4 95598供电类投诉前五供电局统计表
|
|
|
|
|
# table4 = doc_poweroff.add_table(6, 5)
|
|
|
|
@ -348,10 +369,10 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
standardize_date = (
|
|
|
|
|
f"{month_before}月{day_before}日17时至{month}月{day}日17时期间,"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
elif time_type == 1:
|
|
|
|
|
# -------------------------20250429更新,修改开始和结束时间---------------------------------
|
|
|
|
|
standardize_date = f"{year}年{month}月{day}日0时至24时期间,"
|
|
|
|
|
#standardize_date = f"{year}年{month}月{day}日0时至24时期间,"
|
|
|
|
|
standardize_date = f"{month}月{day}日0时至24时期间,"
|
|
|
|
|
# standardize_date = ''
|
|
|
|
|
# -------------------------20250429更新,修改开始和结束时间---------------------------------
|
|
|
|
|
|
|
|
|
@ -424,6 +445,8 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
|
|
|
|
|
current_doc_name = f"南方电网公司停电抢修投诉服务舆情管控三工单联动监测日报{year}{int(month):02d}{int(day):02d}.docx"
|
|
|
|
|
|
|
|
|
|
if "over_load" not in doc_dict:
|
|
|
|
|
raise Exception("过载数据不符合标准未解析,请查看文档")
|
|
|
|
|
doc_dict_over_load = doc_dict["over_load"]
|
|
|
|
|
over_load_before = extract_overload_info_from_previous_day(
|
|
|
|
|
current_word=current_doc_name
|
|
|
|
@ -577,7 +600,8 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
|
|
|
|
|
# 将数据组装相关的时间内容
|
|
|
|
|
doc_dict["first_point_para1"] = standardize_date + doc_dict["first_point_para1"]
|
|
|
|
|
doc_dict["sentiment_para"] = standardize_date + doc_dict["sentiment_para"]
|
|
|
|
|
#doc_dict["sentiment_para"] = standardize_date + doc_dict["sentiment_para"]
|
|
|
|
|
doc_dict["sentiment_para"] = doc_dict["sentiment_para"]
|
|
|
|
|
|
|
|
|
|
# {{standardize_date}}全网收到{{complain_num}}条供电类投诉,环比{{complain_dod}}条;
|
|
|
|
|
complain_text = (
|
|
|
|
@ -678,21 +702,20 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
# 复制表1的数据
|
|
|
|
|
logger.info("将配变过载写入表0,第二行开始,第9列开始")
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row2 = 1 # 起始行索引(从0开始)
|
|
|
|
|
end_row2 = 7 # 结束行索引(不包括)
|
|
|
|
|
start_col2 = 2 # 起始列索引(从0开始)
|
|
|
|
|
end_col2 = 4 # 结束列索引(不包括)
|
|
|
|
|
target_row=1
|
|
|
|
|
target_col=7
|
|
|
|
|
copy_table_no_align(
|
|
|
|
|
table2,
|
|
|
|
|
start_row2 = 2 # 起始行索引(从0开始)
|
|
|
|
|
end_row2 = 8 # 结束行索引(不包括)
|
|
|
|
|
start_col2 = 9 # 起始列索引(从0开始)
|
|
|
|
|
end_col2 = 11 # 结束列索引(不包括)
|
|
|
|
|
#target_row=1
|
|
|
|
|
#target_col=7
|
|
|
|
|
copy_table(
|
|
|
|
|
table1,
|
|
|
|
|
electricity_daily.tables[0],
|
|
|
|
|
start_row2,
|
|
|
|
|
end_row2,
|
|
|
|
|
start_col2,
|
|
|
|
|
end_col2,
|
|
|
|
|
target_row,
|
|
|
|
|
target_col
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
"""
|
|
|
|
|
copy_table(
|
|
|
|
@ -748,6 +771,21 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
is_dynamics=False
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
logger.info("将配变重过载的数据插入表格5")
|
|
|
|
|
# 统计配变过载前五的数据
|
|
|
|
|
top_5_results = deal_excel_over_load(file_path_dict["over_load_excel"])
|
|
|
|
|
# 表4中的插入位置
|
|
|
|
|
start_tb4_row = 2
|
|
|
|
|
start_tb4_col = 8
|
|
|
|
|
if not top_5_results.empty:
|
|
|
|
|
data = top_5_results.values
|
|
|
|
|
copy_sta_table(
|
|
|
|
|
electricity_daily.tables[1],
|
|
|
|
|
data,
|
|
|
|
|
start_tb4_row,
|
|
|
|
|
start_tb4_col,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# copy_sta_table(electricity_daily.tables[3], top5_list, start_tb4_row, start_tb4_col)
|
|
|
|
|
|
|
|
|
|
# 将表格中的字体中文设置成仿宋,英文数字设置成新罗马,均为11号大小
|
|
|
|
|