feat 🐛:增加计算

v2025-07-11
许标 1 week ago
parent febff32998
commit 62d7b0ebd0

@ -63,10 +63,8 @@ def count_outage_sentiment(text):
# text = "全网监测到涉电力供应类舆情风险信息11条环比减少2条"
# text = "涉电力供应类舆情风险信息22条环比持平。其中1条为官方媒体发布其余21条均为个人账号发布。"
# 使用正则表达式匹配数字和关键词
pattern = r"信息(\d+)条,环比(增加|减少)(\d)条"
pattern_equal = r"信息(\d+)条,环比持平"
pattern = r"信息(\d+)条,环比(增加|减少)(\d+)条"
match = re.search(pattern, text)
match_equal = re.search(pattern_equal, text)
num1 = ""
change = ""
num2 = ""
@ -93,13 +91,16 @@ def count_outage_sentiment(text):
print(f"计算结果:{result}")
else:
print("变化类型未知,无法计算")
else:
# update:2025-07-08 增加持平
elif match_equal:
num1 = int(match_equal.group(1))
pattern = r"信息(\d+)条,环比持平"
match = re.search(pattern, text)
if match:
num1 = int(match.group(1))
change = "持平"
num2 = int(match_equal.group(1))
num2 = int(match.group(1))
result = ""
# change = match_equal.group(2)
else:
pattern = r"信息(\d+)条,同比(增加|减少)(\d+)条"
match = re.search(pattern, text)

@ -283,7 +283,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
top_dod_dict[need_district_statistics[i][0]] = top5_dod_analysis(
need_district_statistics[i], district_stat_before
)
if count == 1:
if count == 1 and other_count==0:
top5_name_list.append(
need_district_statistics[len(need_district_statistics) - 1][0]
)
@ -476,7 +476,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
over_load_percent = f"{over_load_percent:.2f}%"
over_load_type = "增加"
else:
over_load_percent = 0
over_load_percent = ""
over_load_type = "持平"
else:
over_load_before = ""
@ -680,6 +680,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
)
# 放入舆情的数据
logger.info("将自行统计的数据插入表格2")
copy_table(
table_sentiment,
electricity_daily.tables[0],
@ -691,6 +692,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
)
# 复制表2的数据
logger.info("将自行统计的数据插入表格3")
copy_table(
table2,
electricity_daily.tables[1],
@ -702,6 +704,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
)
# 复制表3的数据
logger.info("将自行统计的数据插入表格4")
copy_table(
table3,
electricity_daily.tables[2],
@ -714,6 +717,7 @@ def deal_docx(folder_path, save_path=None, time_type=0):
# 填充表格4
# 需要判断是否前五数据不存在
logger.info("将自行统计的数据插入表格5")
if top5_list:
copy_sta_table(
electricity_daily.tables[3],

@ -3,6 +3,7 @@ import logging
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml import CT_P
from pandas.core.indexers import length_of_indexer
# 获取日志记录器
logger = logging.getLogger(__name__)
@ -41,9 +42,9 @@ def copy_sta_table(
length: int = None,
):
try:
logger.info("开始将自行统计的数据插入word表格中")
logger.info(f"开始将自行统计的数据插入word表格中,{target_table}")
# update:2025-07-04 删除多余的行数
if is_dynamics is not None and is_dynamics and len(data) < length:
if is_dynamics is not None and is_dynamics and len(data)>1:
for i in range(len(data) - 1):
source_row = target_table.rows[-1]._element
new_row_element = copy.deepcopy(source_row)

Loading…
Cancel
Save