|
|
|
@ -13,7 +13,7 @@ from docx.shared import Inches, Pt
|
|
|
|
|
from app.tools.deal_excels import deal_excel, top5_dod_analysis, transform_data
|
|
|
|
|
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
|
|
|
|
@ -126,23 +126,45 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# 获取所有表格
|
|
|
|
|
print("获取投诉服务的表格")
|
|
|
|
|
|
|
|
|
|
tables = doc_poweroff.tables
|
|
|
|
|
|
|
|
|
|
# 舆情直接取第一个表格
|
|
|
|
|
print("舆情的表格")
|
|
|
|
|
table_sentiment = doc_sentiment.tables[0]
|
|
|
|
|
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row1_1 = 2 # 起始行索引(从0开始)
|
|
|
|
|
end_row1_1 = 8 # 结束行索引(不包括)
|
|
|
|
|
start_col1_1 = 10 # 起始列索引(从0开始)
|
|
|
|
|
end_col1_1 = 13 # 结束列索引(不包括)
|
|
|
|
|
|
|
|
|
|
# 表1 “抢修、投诉、舆情”三工单监测汇总表
|
|
|
|
|
table1 = tables[0]
|
|
|
|
|
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row1 = 2 # 起始行索引(从0开始)
|
|
|
|
|
end_row1 = 8 # 结束行索引(不包括)
|
|
|
|
|
start_col1 = 2 # 起始列索引(从0开始)
|
|
|
|
|
end_col1 = 9 # 结束列索引(不包括)
|
|
|
|
|
|
|
|
|
|
# 表2配变过载监测汇总表
|
|
|
|
|
table2 = tables[1]
|
|
|
|
|
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row2 = 1 # 起始行索引(从0开始)
|
|
|
|
|
end_row2 = 8 # 结束行索引(不包括)
|
|
|
|
|
start_col2 = 1 # 起始列索引(从0开始)
|
|
|
|
|
end_col2 = 4 # 结束列索引(不包括)
|
|
|
|
|
|
|
|
|
|
# 表3停电用户前五供电局
|
|
|
|
|
table3 = tables[2]
|
|
|
|
|
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row3 = 2 # 起始行索引(从0开始)
|
|
|
|
|
end_row3 = 7 # 结束行索引(不包括)
|
|
|
|
|
start_col3 = 1 # 起始列索引(从0开始)
|
|
|
|
|
end_col3 = 5 # 结束列索引(不包括)
|
|
|
|
|
|
|
|
|
|
# 新增表4 95598供电类投诉前五供电局统计表
|
|
|
|
|
# table4 = doc_poweroff.add_table(6, 5)
|
|
|
|
|
|
|
|
|
@ -216,6 +238,9 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
f"表1中剩余的省份统计数据及舆情的统计数据、环比情况:{table1_extra_data}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 省份统计的表格数据在表格中的起始位置
|
|
|
|
|
start_row_pro_sta = 2
|
|
|
|
|
start_col_pro_sta = 9
|
|
|
|
|
|
|
|
|
|
# 将昨天的地市统计转成字典
|
|
|
|
|
district_stat_before = dict(district_stat_before)
|
|
|
|
@ -273,9 +298,9 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
district_stat_before,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
top5_name_list.append(f"其他{count + other_count}家单位")
|
|
|
|
|
top5_name_list.append(f"其他{count + other_count}单位")
|
|
|
|
|
top5_poweroff_list.append(poweroff_value)
|
|
|
|
|
top_dod_dict["其他单位"] = "—"
|
|
|
|
|
top_dod_dict["其他单位"] = "-"
|
|
|
|
|
|
|
|
|
|
# old_version
|
|
|
|
|
"""
|
|
|
|
@ -304,11 +329,13 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
top_dod_dict[top5[0]] = top5_dod_analysis(top5, district_stat_before)
|
|
|
|
|
|
|
|
|
|
elif 0 < len(district_statistics) < 5:
|
|
|
|
|
|
|
|
|
|
for i in range(len(district_statistics)):
|
|
|
|
|
|
|
|
|
|
top5_name_list.append(district_statistics[i][0])
|
|
|
|
|
top5_poweroff_list.append(district_statistics[i][1])
|
|
|
|
|
top_dod_dict[district_statistics[i][0]] = top5_dod_analysis(district_statistics[i], district_stat_before)
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
print(f"地市前五名称{top5_name_list}")
|
|
|
|
|
print(f"地市前五数据{top5_poweroff_list}")
|
|
|
|
|
# top_dod_dict[top1[0]] = top5_dod_analysis(top1, district_stat_before)
|
|
|
|
@ -316,13 +343,17 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
# top_dod_dict[top3[0]] = top5_dod_analysis(top3, district_stat_before)
|
|
|
|
|
# top_dod_dict[top4[0]] = top5_dod_analysis(top4, district_stat_before)
|
|
|
|
|
# top_dod_dict[top5[0]] = top5_dod_analysis(top5, district_stat_before)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
print(f"地市环比{top_dod_dict}")
|
|
|
|
|
top5_stat_list = list(top_dod_dict.values())
|
|
|
|
|
|
|
|
|
|
# 地市前5的名称、数据、环比放入列表并转至,方便写入表格4
|
|
|
|
|
top5_list = transform_data([top5_name_list, top5_poweroff_list, top5_stat_list])
|
|
|
|
|
|
|
|
|
|
# 表4中的插入位置
|
|
|
|
|
start_tb4_row = 2
|
|
|
|
|
start_tb4_col = 1
|
|
|
|
|
|
|
|
|
|
# 省总的投诉情况及环比
|
|
|
|
|
complain_dod = int(province_statistics_total) - int(province_stat_be_total)
|
|
|
|
|
|
|
|
|
@ -339,7 +370,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
complain_dod = "持平"
|
|
|
|
|
|
|
|
|
|
# 异常处置情况
|
|
|
|
|
electricity_exception = "停电、投诉、舆情整体平稳,无异常情况。"
|
|
|
|
|
electricity_exception = "无"
|
|
|
|
|
|
|
|
|
|
standardize_date = None
|
|
|
|
|
|
|
|
|
@ -629,12 +660,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
# 将表格添加到新的文档里
|
|
|
|
|
# 组装表1的数据
|
|
|
|
|
# 此处缺少省份统计数据和舆情数据
|
|
|
|
|
logger.info("将投诉服务的表格1写入日报的表格1,从2-8行,2-9列写入")
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row1 = 2 # 起始行索引(从0开始)
|
|
|
|
|
end_row1 = 8 # 结束行索引(不包括)
|
|
|
|
|
start_col1 = 2 # 起始列索引(从0开始)
|
|
|
|
|
end_col1 = 9 # 结束列索引(不包括)
|
|
|
|
|
logger.info("将数据写入word表格1")
|
|
|
|
|
copy_table(
|
|
|
|
|
table1,
|
|
|
|
|
electricity_daily.tables[0],
|
|
|
|
@ -645,12 +671,8 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 插入各个省份的投诉数据及环比
|
|
|
|
|
logger.info("将投诉数据写入到表1,第二行开始,第11列开始")
|
|
|
|
|
# 省份统计的表格数据在表格中的起始位置
|
|
|
|
|
start_row_pro_sta = 2
|
|
|
|
|
start_col_pro_sta = 11
|
|
|
|
|
logger.info("将自行统计的数据插入表格1")
|
|
|
|
|
copy_sta_table(
|
|
|
|
|
electricity_daily.tables[0],
|
|
|
|
|
table1_extra_data,
|
|
|
|
@ -659,12 +681,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 放入舆情的数据
|
|
|
|
|
logger.info("将舆情数据写入到表1,第二行开始,第11列开始")
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row1_1 = 2 # 起始行索引(从0开始)
|
|
|
|
|
end_row1_1 = 8 # 结束行索引(不包括)
|
|
|
|
|
start_col1_1 = 10 # 起始列索引(从0开始)
|
|
|
|
|
end_col1_1 = 13 # 结束列索引(不包括)
|
|
|
|
|
logger.info("将自行统计的数据插入表格2")
|
|
|
|
|
copy_table(
|
|
|
|
|
table_sentiment,
|
|
|
|
|
electricity_daily.tables[0],
|
|
|
|
@ -672,29 +689,11 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
end_row1_1,
|
|
|
|
|
start_col1_1,
|
|
|
|
|
end_col1_1,
|
|
|
|
|
3,
|
|
|
|
|
1,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 复制表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,
|
|
|
|
|
electricity_daily.tables[0],
|
|
|
|
|
start_row2,
|
|
|
|
|
end_row2,
|
|
|
|
|
start_col2,
|
|
|
|
|
end_col2,
|
|
|
|
|
target_row,
|
|
|
|
|
target_col
|
|
|
|
|
)
|
|
|
|
|
"""
|
|
|
|
|
# 复制表2的数据
|
|
|
|
|
logger.info("将自行统计的数据插入表格3")
|
|
|
|
|
copy_table(
|
|
|
|
|
table2,
|
|
|
|
|
electricity_daily.tables[1],
|
|
|
|
@ -704,25 +703,9 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
end_col2,
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# 复制表3的数据
|
|
|
|
|
logger.info("将停电前五插入表格2")
|
|
|
|
|
# 定义要查看的区域范围
|
|
|
|
|
start_row3 = 2 # 起始行索引(从0开始)
|
|
|
|
|
end_row3 = 7 # 结束行索引(不包括)
|
|
|
|
|
start_col3 = 1 # 起始列索引(从0开始)
|
|
|
|
|
end_col3 = 5 # 结束列索引(不包括)
|
|
|
|
|
copy_table(
|
|
|
|
|
table3,
|
|
|
|
|
electricity_daily.tables[1],
|
|
|
|
|
start_row3,
|
|
|
|
|
end_row3,
|
|
|
|
|
start_col3,
|
|
|
|
|
end_col3,
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
"""
|
|
|
|
|
logger.info("将自行统计的数据插入表格4")
|
|
|
|
|
copy_table(
|
|
|
|
|
table3,
|
|
|
|
|
electricity_daily.tables[2],
|
|
|
|
@ -732,20 +715,18 @@ def deal_docx(folder_path, save_path=None, time_type=0):
|
|
|
|
|
end_col3,
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# 填充表格4
|
|
|
|
|
# 需要判断是否前五数据不存在
|
|
|
|
|
logger.info("将自行统计的数据插入表格5")
|
|
|
|
|
# 表4中的插入位置
|
|
|
|
|
start_tb4_row = 2
|
|
|
|
|
start_tb4_col = 5
|
|
|
|
|
if top5_list:
|
|
|
|
|
copy_sta_table(
|
|
|
|
|
electricity_daily.tables[1],
|
|
|
|
|
electricity_daily.tables[3],
|
|
|
|
|
top5_list,
|
|
|
|
|
start_tb4_row,
|
|
|
|
|
start_tb4_col,
|
|
|
|
|
is_dynamics=False
|
|
|
|
|
is_dynamics=True,
|
|
|
|
|
length=5,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# copy_sta_table(electricity_daily.tables[3], top5_list, start_tb4_row, start_tb4_col)
|
|
|
|
|