新增对比报告自动截图
Signed-off-by: yinzijian <yinzijian@haomozhixing.onaliyun.com>
This commit is contained in:
parent
c7ddf94011
commit
be421d03b7
Binary file not shown.
|
|
@ -11,6 +11,8 @@ from collections import defaultdict
|
|||
from docxtpl import DocxTemplate, InlineImage, Listing, R, RichText
|
||||
import jinja2
|
||||
|
||||
from tool.screen import cut_report_img, CutReportImgColumn
|
||||
|
||||
|
||||
# from tool.screen import *
|
||||
|
||||
|
|
@ -78,18 +80,13 @@ class PartDetail:
|
|||
|
||||
class ImageDetail:
|
||||
def __init__(self):
|
||||
self.wave_id = ''
|
||||
self.wave_name = ''
|
||||
self.crossid = ''
|
||||
self.cross_name = ''
|
||||
self.time_list = []
|
||||
self.tp = ''
|
||||
self.high = 0 #高频停车路口,0否,1是
|
||||
self.odi = 0 #odi,0否,1是
|
||||
self.turn_ts = 0 #分流转向比,1正向,2反向
|
||||
self.in_ts = 0 #汇入转向比,1正向,2反向
|
||||
self.week_or_day = 0, #1日,2周
|
||||
self.date_name = '' #日:2024-10-15,周:2024-48
|
||||
self.tp_start = ''
|
||||
self.tp_end = ''
|
||||
self.walk = 0 #人行横道
|
||||
self.delay = 0 #延误
|
||||
self.flow_in = 0 #分流
|
||||
|
||||
|
||||
class DocDocumentContrastCtx:
|
||||
|
|
@ -100,8 +97,16 @@ class DocDocumentContrastCtx:
|
|||
self.doc = DocxTemplate(self.get_template_file_path())
|
||||
self.title = None
|
||||
self.cut_image = 0
|
||||
self.area_id = None
|
||||
self.cut_image_userid = '15836903493'
|
||||
self.cut_image_role = 'manager'
|
||||
self.crossid = None
|
||||
self.cross_name = None
|
||||
self.time_list = None
|
||||
self.tp = None
|
||||
self.walk = 1 # 人行横道
|
||||
self.delay = 1 # 延误
|
||||
self.flow_in = 1 # 分流
|
||||
self.tpl_data = {
|
||||
# 总体概述
|
||||
'part1': self.tpl_paragraph_map['part1'],
|
||||
|
|
@ -232,6 +237,7 @@ class DocDocumentContrastCtx:
|
|||
'part_name': '',
|
||||
'part_n': 'part1_1',
|
||||
'detail': [],
|
||||
'image': '',
|
||||
'table_data': [],
|
||||
}
|
||||
item_data['detail'].append(self.tpl_data['part1_1'].item1)
|
||||
|
|
@ -277,6 +283,7 @@ class DocDocumentContrastCtx:
|
|||
item_data = {
|
||||
'part_name': self.tpl_paragraph_map['part2_1'],
|
||||
'part_n': 'part2_1',
|
||||
'image': "",
|
||||
'detail': [],
|
||||
}
|
||||
item_data['detail'].append(self.tpl_data['part2_1'].item1)
|
||||
|
|
@ -288,6 +295,7 @@ class DocDocumentContrastCtx:
|
|||
item_data = {
|
||||
'part_name': self.tpl_paragraph_map['part2_2'],
|
||||
'part_n': 'part2_2',
|
||||
'image': '',
|
||||
'detail': [],
|
||||
}
|
||||
for item in self.tpl_data['part2_2'].table:
|
||||
|
|
@ -298,6 +306,7 @@ class DocDocumentContrastCtx:
|
|||
item_data = {
|
||||
'part_name': self.tpl_paragraph_map['part2_3'],
|
||||
'part_n': 'part2_3',
|
||||
'image': '',
|
||||
'detail': [],
|
||||
}
|
||||
for item in self.tpl_data['part2_3'].table:
|
||||
|
|
@ -386,19 +395,31 @@ class DocDocumentContrastCtx:
|
|||
item_date_detail['item_detail'].append(self.build_rich_text(item_item_table.detail, item_item_table.detail_value) if item_item_table.detail != '' else '')
|
||||
item_data['data'].append(item_date_detail)
|
||||
table_data.append(item_data)
|
||||
|
||||
if len(screen_image_list) > 0:
|
||||
cut_images, _ = cut_report_img(screen_image_list, self.cut_image_userid, self.cut_image_role)
|
||||
if context.get('part1'):
|
||||
cut_images = {}
|
||||
if self.cut_image == 1:
|
||||
cut_images, _ = cut_report_img([CutReportImgColumn(
|
||||
crossid='CR_10264777_2509810',
|
||||
cross_name='玉峰路与陈家营路交叉口',
|
||||
time_list=[['2026-05-01', '2026-05-04'],['2026-05-06', '2026-05-09']],
|
||||
tp_name='02:00-03:00',
|
||||
walk=1,
|
||||
delay=1,
|
||||
flow_in=1)], self.nodeid, self.area_id, self.cut_image_userid , self.cut_image_role)
|
||||
if context.get('part1') and cut_images.get('cross'):
|
||||
for item_part in context['part1']:
|
||||
if item_part['part_n'] == 'part1_3':
|
||||
for item_detail in item_part['detail']:
|
||||
if len(item_detail['images']) > 0:
|
||||
for item_image in item_detail['images']:
|
||||
item_image['image'] = InlineImage(self.doc, cut_images[item_image['image']],
|
||||
width=Mm(146)) if cut_images[
|
||||
item_image['image']] else ''
|
||||
if item_part['part_n'] == 'part1_1':item_part['image'] = InlineImage(self.doc, cut_images["cross"],width=Mm(90))
|
||||
if context.get('part2'):
|
||||
for item_part in context['part2']:
|
||||
if item_part['part_n'] == 'part2_1' and cut_images.get('walk'):
|
||||
item_part['image'] = InlineImage(self.doc, cut_images["walk"],width=Mm(90))
|
||||
if item_part['part_n'] == 'part2_2' and cut_images.get('delay'):
|
||||
item_part['image'] = InlineImage(self.doc, cut_images["delay"], width=Mm(90))
|
||||
if item_part['part_n'] == 'part2_3' and cut_images.get('flow_in'):
|
||||
item_part['image'] = InlineImage(self.doc, cut_images["flow_in"], width=Mm(90))
|
||||
self.doc.render(context, autoescape=True)
|
||||
if len(cut_images) > 0:
|
||||
for _, item_cut_images in cut_images.items():
|
||||
os.remove(item_cut_images)
|
||||
# # 渲染模板
|
||||
# for table in self.doc.tables:
|
||||
# for row in table.rows:
|
||||
|
|
@ -437,7 +458,7 @@ def set_font(para, text_to_find, font_name='仿宋', font_size=12, font_color=(0
|
|||
|
||||
|
||||
def doc_demo_contrast():
|
||||
doc1 = DocDocumentContrastCtx('9660') #获取模版对象
|
||||
doc1 = DocDocumentContrastCtx('530100') #获取模版对象
|
||||
doc1.tpl_paragraph['part1']['visible'] = 1
|
||||
doc1.tpl_paragraph['part2']['visible'] = 1
|
||||
doc1.tpl_paragraph['part2']['part2_1'] = 1
|
||||
|
|
@ -448,11 +469,15 @@ def doc_demo_contrast():
|
|||
doc1.tpl_paragraph['part4']['part4_1'] = 1
|
||||
doc1.tpl_paragraph['part4']['part4_2'] = 1
|
||||
doc1.tpl_paragraph['part5']['visible'] = 1
|
||||
|
||||
doc1.cut_image = 0
|
||||
doc1.cut_image_userid = '15836903493'
|
||||
doc1.cut_image_role = 'manager'
|
||||
doc1.title = '清盛大道与龙江路交叉口'
|
||||
#自动截图
|
||||
doc1.cut_image = 1 #开启
|
||||
doc1.area_id = 530101
|
||||
doc1.crossid = "CR_10264777_2509810"
|
||||
doc1.cross_name = "玉峰路与陈家营路交叉口"
|
||||
doc1.time_list = [['2026-05-01', '2026-05-04'], ['2026-05-06', '2026-05-09']],
|
||||
doc1.tp = "02:00-03:00"
|
||||
|
||||
|
||||
# =========1总体概论===========
|
||||
doc1.tpl_data['part1_1'].item1 = '2024年10月8日'
|
||||
|
|
@ -470,7 +495,6 @@ def doc_demo_contrast():
|
|||
detail3.detail = "路口停车次数由?下降为?,减少?,优化率为?;"
|
||||
detail3.detail_value = ['2.331', '0.563', '2.31', '6.21%']
|
||||
doc1.tpl_data['part1_1'].table = [detail1, detail2, detail3]
|
||||
|
||||
#==========2.1优化前现状分析==========
|
||||
doc1.tpl_data['part2_1'].item1 = '清盛大道与龙江路交叉口'
|
||||
doc1.tpl_data['part2_1'].item2 = '东城区'
|
||||
|
|
@ -489,9 +513,9 @@ def doc_demo_contrast():
|
|||
#===========2.3延误分析============
|
||||
detail1 = PartDetail()
|
||||
detail1.detail = "根据车辆分流转向比分析,西南进口道流量占比最大为?,东南进口道流量占比最小为?。路口的主要车流方向为东北直行和西南直行,东北进口道以直行车流为主,占比为?;西南进口道以直行车流为主,占比为?。"
|
||||
detail1.detail_value = ['5%', '7%', '8%', '12%']
|
||||
detail1.detail_value = ['5%', '9%', '8%', '12%']
|
||||
detail2 = PartDetail()
|
||||
detail2.detail = "根据车辆分流转向比分析,西南进口道流量占比最大为?,东南进口道流量占比最小为?。路口的主要车流方向为东北直行和西南直行,东北进口道以直行车流为主,占比为?;西南进口道以直行车流为主,占比为?。"
|
||||
detail2.detail = "根据车辆分流转向比分析,东北进口道流量占比最大为?,东南进口道流量占比最小为?。路口的主要车流方向为东北直行和西南直行,东北进口道以直行车流为主,占比为?;西南进口道以直行车流为主,占比为?。"
|
||||
detail2.detail_value = ['5%', '7%', '8%', '12%']
|
||||
doc1.tpl_data['part2_3'].table = [detail1, detail2]
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue