mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2026-01-01 17:30:47 +00:00
flake8
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from reportlab.pdfbase import pdfmetrics
|
# from reportlab.pdfbase import pdfmetrics
|
||||||
from reportlab.pdfbase.ttfonts import TTFont
|
# from reportlab.pdfbase.ttfonts import TTFont
|
||||||
|
|
||||||
from reportlab.lib.units import inch
|
from reportlab.lib.units import inch
|
||||||
from reportlab.lib.pagesizes import letter, portrait
|
from reportlab.lib.pagesizes import letter, portrait
|
||||||
@@ -18,8 +18,8 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
|
|||||||
show_priorities=False, include_omitted=False):
|
show_priorities=False, include_omitted=False):
|
||||||
columns = list()
|
columns = list()
|
||||||
reel_numbers = reel_list or sorted(
|
reel_numbers = reel_list or sorted(
|
||||||
set([x.reel for x in lines if x.reel is not None])
|
set([x.reel for x in lines if x.reel is not None])
|
||||||
)
|
)
|
||||||
|
|
||||||
num_column_width = 15. / 32. * inch
|
num_column_width = 15. / 32. * inch
|
||||||
|
|
||||||
@@ -46,35 +46,49 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
|
|||||||
|
|
||||||
columns.append({
|
columns.append({
|
||||||
'heading': 'TV',
|
'heading': 'TV',
|
||||||
'value_getter': (lambda recs: len([r for r in recs if r.tv])),
|
'value_getter': lambda recs: len([r for r in recs if r.tv]),
|
||||||
'value_getter2': (lambda recs:
|
'value_getter2': (lambda recs:
|
||||||
time_format(sum([r.time_budget_mins or 0.
|
time_format(sum([r.time_budget_mins or 0.
|
||||||
for r in recs if r.tv]))),
|
for r in recs if r.tv]))
|
||||||
|
),
|
||||||
'style_getter': (lambda col_index:
|
'style_getter': (lambda col_index:
|
||||||
[('ALIGN', (col_index, 0), (col_index, -1), 'CENTER'),
|
[('ALIGN', (col_index, 0), (col_index, -1),
|
||||||
|
'CENTER'),
|
||||||
('LINEBEFORE', (col_index, 0), (col_index, -1),
|
('LINEBEFORE', (col_index, 0), (col_index, -1),
|
||||||
1., colors.black),
|
1., colors.black),
|
||||||
('LINEAFTER', (col_index, 0), (col_index, -1),
|
('LINEAFTER', (col_index, 0), (col_index, -1),
|
||||||
.5, colors.gray)]),
|
.5, colors.gray)]
|
||||||
|
),
|
||||||
'width': num_column_width
|
'width': num_column_width
|
||||||
})
|
})
|
||||||
|
|
||||||
columns.append({
|
columns.append({
|
||||||
'heading': 'Opt',
|
'heading': 'Opt',
|
||||||
'value_getter': lambda recs: len([r for r in recs if r.optional]),
|
'value_getter': lambda recs: len([r for r in recs if r.optional]),
|
||||||
'value_getter2': lambda recs: time_format(sum([r.time_budget_mins or 0.
|
'value_getter2': (lambda recs:
|
||||||
for r in recs if r.optional])),
|
time_format(sum([r.time_budget_mins or 0.
|
||||||
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER'),
|
for r in recs if r.optional]))
|
||||||
('LINEAFTER', (col_index, 0), (col_index, -1), .5, colors.gray)],
|
),
|
||||||
|
'style_getter': (lambda col_index:
|
||||||
|
[('ALIGN', (col_index, 0), (col_index, -1),
|
||||||
|
'CENTER'),
|
||||||
|
('LINEAFTER', (col_index, 0), (col_index, -1),
|
||||||
|
.5, colors.gray)]
|
||||||
|
),
|
||||||
'width': num_column_width
|
'width': num_column_width
|
||||||
})
|
})
|
||||||
|
|
||||||
columns.append({
|
columns.append({
|
||||||
'heading': 'Eff',
|
'heading': 'Eff',
|
||||||
'value_getter': lambda recs: len([r for r in recs if r.effort]),
|
'value_getter': lambda recs: len([r for r in recs if r.effort]),
|
||||||
'value_getter2': lambda recs: time_format(sum([r.time_budget_mins or 0.
|
'value_getter2': (lambda recs:
|
||||||
for r in recs if r.effort])),
|
time_format(sum([r.time_budget_mins or 0.
|
||||||
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')],
|
for r in recs if r.effort]))
|
||||||
|
),
|
||||||
|
'style_getter': (lambda col_index:
|
||||||
|
[('ALIGN', (col_index, 0), (col_index, -1),
|
||||||
|
'CENTER')]
|
||||||
|
),
|
||||||
'width': num_column_width
|
'width': num_column_width
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -90,23 +104,26 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
|
|||||||
})
|
})
|
||||||
|
|
||||||
if len(reel_numbers) > 0:
|
if len(reel_numbers) > 0:
|
||||||
# columns.append({
|
|
||||||
# 'heading': 'RX',
|
|
||||||
# 'value_getter': lambda recs: blank_len([r for r in recs if 'Reel' not in r.keys()]),
|
|
||||||
# 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) for r in recs
|
|
||||||
# if 'Reel' not in r.keys()])),
|
|
||||||
# 'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')],
|
|
||||||
# 'width': num_column_width
|
|
||||||
# })
|
|
||||||
|
|
||||||
for n in reel_numbers:
|
for n in reel_numbers:
|
||||||
columns.append({
|
columns.append({
|
||||||
'heading': n,
|
'heading': n,
|
||||||
'value_getter': lambda recs, n1=n: len([r for r in recs if r.reel == n1]),
|
'value_getter': (lambda recs, n1=n:
|
||||||
'value_getter2': lambda recs, n1=n: time_format(sum([r.time_budget_mins or 0. for r
|
len([r for r in recs if r.reel == n1])
|
||||||
in recs if r.reel == n1])),
|
),
|
||||||
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER'),
|
'value_getter2': (lambda recs, n1=n:
|
||||||
('LINEAFTER', (col_index, 0), (col_index, -1), .5, colors.gray)],
|
time_format(sum([r.time_budget_mins or 0.
|
||||||
|
for r in recs
|
||||||
|
if r.reel == n1]))
|
||||||
|
),
|
||||||
|
'style_getter': (lambda col_index:
|
||||||
|
[('ALIGN', (col_index, 0), (col_index, -1),
|
||||||
|
'CENTER'),
|
||||||
|
('LINEAFTER', (col_index, 0),
|
||||||
|
(col_index, -1),
|
||||||
|
.5, colors.gray)]
|
||||||
|
),
|
||||||
|
|
||||||
'width': num_column_width
|
'width': num_column_width
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -114,18 +131,26 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
|
|||||||
for n in range(1, 6,):
|
for n in range(1, 6,):
|
||||||
columns.append({
|
columns.append({
|
||||||
'heading': 'P%i' % n,
|
'heading': 'P%i' % n,
|
||||||
'value_getter': lambda recs: len([r for r in recs if r.priority == n]),
|
'value_getter': lambda recs: len([r for r in recs
|
||||||
'value_getter2': lambda recs: time_format(sum([r.time_budget_mins or 0.
|
if r.priority == n]),
|
||||||
for r in recs if r.priority == n])),
|
'value_getter2': (lambda recs:
|
||||||
|
time_format(sum([r.time_budget_mins or 0.
|
||||||
|
for r in recs
|
||||||
|
if r.priority == n]))
|
||||||
|
),
|
||||||
'style_getter': lambda col_index: [],
|
'style_getter': lambda col_index: [],
|
||||||
'width': num_column_width
|
'width': num_column_width
|
||||||
})
|
})
|
||||||
|
|
||||||
columns.append({
|
columns.append({
|
||||||
'heading': '>P5',
|
'heading': '>P5',
|
||||||
'value_getter': lambda recs: len([r for r in recs if (r.priority or 5) > 5]),
|
'value_getter': lambda recs: len([r for r in recs
|
||||||
'value_getter2': lambda recs: time_format(sum([r.time_budget_mins or 0.
|
if (r.priority or 5) > 5]),
|
||||||
for r in recs if (r.priority or 5) > 5])),
|
'value_getter2': (lambda recs:
|
||||||
|
time_format(sum([r.time_budget_mins or 0.
|
||||||
|
for r in recs
|
||||||
|
if (r.priority or 5) > 5]))
|
||||||
|
),
|
||||||
'style_getter': lambda col_index: [],
|
'style_getter': lambda col_index: [],
|
||||||
'width': num_column_width
|
'width': num_column_width
|
||||||
})
|
})
|
||||||
@@ -134,32 +159,47 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
|
|||||||
columns.append({
|
columns.append({
|
||||||
'heading': 'Omit',
|
'heading': 'Omit',
|
||||||
'value_getter': lambda recs: len([r for r in recs if r.omitted]),
|
'value_getter': lambda recs: len([r for r in recs if r.omitted]),
|
||||||
'value_getter2': lambda recs: time_format(sum([r.time_budget_mins or 0.
|
'value_getter2': (lambda recs:
|
||||||
for r in recs if r.omitted])),
|
time_format(sum([r.time_budget_mins or 0.
|
||||||
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')],
|
for r in recs if r.omitted]))),
|
||||||
|
'style_getter': (lambda col_index:
|
||||||
|
[('ALIGN', (col_index, 0), (col_index, -1),
|
||||||
|
'CENTER')]
|
||||||
|
),
|
||||||
'width': num_column_width
|
'width': num_column_width
|
||||||
})
|
})
|
||||||
|
|
||||||
columns.append({
|
columns.append({
|
||||||
'heading': 'Total',
|
'heading': 'Total',
|
||||||
'value_getter': lambda recs: len([r for r in recs if not r.omitted]),
|
'value_getter': lambda recs: len([r for r in recs if not r.omitted]),
|
||||||
'value_getter2': lambda recs: time_format(sum([r.time_budget_mins or 0.
|
'value_getter2': (lambda recs:
|
||||||
for r in recs if not r.omitted]), zero_str=None),
|
time_format(
|
||||||
'style_getter': lambda col_index: [('LINEBEFORE', (col_index, 0), (col_index, -1), 1.0, colors.black),
|
sum([r.time_budget_mins or 0.
|
||||||
('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')],
|
|
||||||
|
for r in recs if not r.omitted])
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'style_getter': (lambda col_index:
|
||||||
|
[('LINEBEFORE', (col_index, 0), (col_index, -1),
|
||||||
|
1.0, colors.black),
|
||||||
|
('ALIGN', (col_index, 0), (col_index, -1),
|
||||||
|
'CENTER')]
|
||||||
|
),
|
||||||
'width': 0.5 * inch
|
'width': 0.5 * inch
|
||||||
})
|
})
|
||||||
|
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
|
|
||||||
def populate_columns(lines: List[ADRLine], columns, include_omitted, _page_size):
|
def populate_columns(lines: List[ADRLine], columns, include_omitted,
|
||||||
|
_page_size):
|
||||||
data = list()
|
data = list()
|
||||||
styles = list()
|
styles = list()
|
||||||
columns_widths = list()
|
columns_widths = list()
|
||||||
|
|
||||||
sorted_character_numbers: List[str] = sorted(set([x.character_id for x in lines]),
|
sorted_character_numbers: List[str] = sorted(
|
||||||
key=lambda x: str(x))
|
set([x.character_id for x in lines]),
|
||||||
|
key=lambda x: str(x))
|
||||||
|
|
||||||
# construct column styles
|
# construct column styles
|
||||||
|
|
||||||
@@ -184,8 +224,10 @@ def populate_columns(lines: List[ADRLine], columns, include_omitted, _page_size)
|
|||||||
row_data.append(col['value_getter'](list(char_records)))
|
row_data.append(col['value_getter'](list(char_records)))
|
||||||
row_data2.append(col['value_getter2'](list(char_records)))
|
row_data2.append(col['value_getter2'](list(char_records)))
|
||||||
|
|
||||||
styles.extend([('TEXTCOLOR', (0, row2_index), (-1, row2_index), colors.red),
|
styles.extend([('TEXTCOLOR', (0, row2_index), (-1, row2_index),
|
||||||
('LINEBELOW', (0, row2_index), (-1, row2_index), 0.5, colors.black)])
|
colors.red),
|
||||||
|
('LINEBELOW', (0, row2_index), (-1, row2_index),
|
||||||
|
0.5, colors.black)])
|
||||||
|
|
||||||
data.append(row_data)
|
data.append(row_data)
|
||||||
data.append(row_data2)
|
data.append(row_data2)
|
||||||
@@ -202,7 +244,8 @@ def populate_columns(lines: List[ADRLine], columns, include_omitted, _page_size)
|
|||||||
summary_row1.append("")
|
summary_row1.append("")
|
||||||
summary_row2.append("")
|
summary_row2.append("")
|
||||||
|
|
||||||
styles.append(('LINEABOVE', (0, row1_index), (-1, row1_index), 2.0, colors.black))
|
styles.append(('LINEABOVE', (0, row1_index), (-1, row1_index), 2.0,
|
||||||
|
colors.black))
|
||||||
|
|
||||||
data.append(summary_row1)
|
data.append(summary_row1)
|
||||||
data.append(summary_row2)
|
data.append(summary_row2)
|
||||||
@@ -214,17 +257,20 @@ def populate_columns(lines: List[ADRLine], columns, include_omitted, _page_size)
|
|||||||
# pass
|
# pass
|
||||||
|
|
||||||
|
|
||||||
def output_report(lines: List[ADRLine], reel_list: List[str], include_omitted=False,
|
def output_report(lines: List[ADRLine], reel_list: List[str],
|
||||||
page_size=portrait(letter), font_name='Helvetica'):
|
include_omitted=False, page_size=portrait(letter),
|
||||||
columns = build_columns(lines, include_omitted=include_omitted, reel_list=reel_list)
|
font_name='Helvetica'):
|
||||||
data, style, columns_widths = populate_columns(lines, columns, include_omitted, page_size)
|
columns = build_columns(lines, include_omitted=include_omitted,
|
||||||
|
reel_list=reel_list)
|
||||||
|
data, style, columns_widths = populate_columns(lines, columns,
|
||||||
|
include_omitted, page_size)
|
||||||
|
|
||||||
style.append(('FONTNAME', (0, 0), (-1, -1), font_name))
|
style.append(('FONTNAME', (0, 0), (-1, -1), font_name))
|
||||||
style.append(('FONTSIZE', (0, 0), (-1, -1), 9.))
|
style.append(('FONTSIZE', (0, 0), (-1, -1), 9.))
|
||||||
style.append(('LINEBELOW', (0, 0), (-1, 0), 1.0, colors.black))
|
style.append(('LINEBELOW', (0, 0), (-1, 0), 1.0, colors.black))
|
||||||
# style.append(('LINEBELOW', (0, 1), (-1, -1), 0.25, colors.gray))
|
# style.append(('LINEBELOW', (0, 1), (-1, -1), 0.25, colors.gray))
|
||||||
|
|
||||||
#pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
# pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
||||||
|
|
||||||
title = "%s Line Count" % lines[0].title
|
title = "%s Line Count" % lines[0].title
|
||||||
filename = title + '.pdf'
|
filename = title + '.pdf'
|
||||||
@@ -236,7 +282,8 @@ def output_report(lines: List[ADRLine], reel_list: List[str], include_omitted=Fa
|
|||||||
document_header='Line Count')
|
document_header='Line Count')
|
||||||
|
|
||||||
# header_data, header_style, header_widths = build_header(columns_widths)
|
# header_data, header_style, header_widths = build_header(columns_widths)
|
||||||
# header_table = Table(data=header_data, style=header_style, colWidths=header_widths)
|
# header_table = Table(data=header_data, style=header_style,
|
||||||
|
# colWidths=header_widths)
|
||||||
|
|
||||||
table = Table(data=data, style=style, colWidths=columns_widths)
|
table = Table(data=data, style=style, colWidths=columns_widths)
|
||||||
|
|
||||||
@@ -251,6 +298,7 @@ def output_report(lines: List[ADRLine], reel_list: List[str], include_omitted=Fa
|
|||||||
omitted_count = len([x for x in lines if x.omitted])
|
omitted_count = len([x for x in lines if x.omitted])
|
||||||
|
|
||||||
if not include_omitted and omitted_count > 0:
|
if not include_omitted and omitted_count > 0:
|
||||||
story.append(Paragraph("* %i Omitted lines are excluded." % omitted_count, style))
|
story.append(Paragraph("* %i Omitted lines are excluded." %
|
||||||
|
omitted_count, style))
|
||||||
|
|
||||||
doc.build(story)
|
doc.build(story)
|
||||||
|
|||||||
@@ -27,23 +27,28 @@ def build_aux_data_field(line: ADRLine):
|
|||||||
tag_field = ""
|
tag_field = ""
|
||||||
if line.effort:
|
if line.effort:
|
||||||
bg_color = 'red'
|
bg_color = 'red'
|
||||||
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font> " % (bg_color, fg_color, "EFF")
|
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font> " \
|
||||||
|
% (bg_color, fg_color, "EFF")
|
||||||
elif line.tv:
|
elif line.tv:
|
||||||
bg_color = 'blue'
|
bg_color = 'blue'
|
||||||
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font> " % (bg_color, fg_color, "TV")
|
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font> " \
|
||||||
|
% (bg_color, fg_color, "TV")
|
||||||
elif line.adlib:
|
elif line.adlib:
|
||||||
bg_color = 'purple'
|
bg_color = 'purple'
|
||||||
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font> " % (bg_color, fg_color, "ADLIB")
|
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font> " \
|
||||||
|
% (bg_color, fg_color, "ADLIB")
|
||||||
elif line.optional:
|
elif line.optional:
|
||||||
bg_color = 'green'
|
bg_color = 'green'
|
||||||
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font>" % (bg_color, fg_color, "OPTIONAL")
|
tag_field += "<font backColor=%s textColor=%s fontSize=11>%s</font>" \
|
||||||
|
% (bg_color, fg_color, "OPTIONAL")
|
||||||
|
|
||||||
entries.append(tag_field)
|
entries.append(tag_field)
|
||||||
|
|
||||||
return "<br />".join(entries)
|
return "<br />".join(entries)
|
||||||
|
|
||||||
|
|
||||||
def build_story(lines: List[ADRLine], tc_rate: TimecodeFormat, font_name='Helvetica'):
|
def build_story(lines: List[ADRLine], tc_rate: TimecodeFormat,
|
||||||
|
font_name='Helvetica'):
|
||||||
story = list()
|
story = list()
|
||||||
|
|
||||||
this_scene = None
|
this_scene = None
|
||||||
@@ -60,7 +65,8 @@ def build_story(lines: List[ADRLine], tc_rate: TimecodeFormat, font_name='Helvet
|
|||||||
('LEFTPADDING', (0, 0), (0, 0), 0.0),
|
('LEFTPADDING', (0, 0), (0, 0), 0.0),
|
||||||
('BOTTOMPADDING', (0, 0), (-1, -1), 24.)]
|
('BOTTOMPADDING', (0, 0), (-1, -1), 24.)]
|
||||||
|
|
||||||
cue_number_field = "%s<br /><font fontSize=7>%s</font>" % (line.cue_number, line.character_name)
|
cue_number_field = "%s<br /><font fontSize=7>%s</font>" \
|
||||||
|
% (line.cue_number, line.character_name)
|
||||||
|
|
||||||
time_data = time_format(line.time_budget_mins)
|
time_data = time_format(line.time_budget_mins)
|
||||||
|
|
||||||
@@ -79,7 +85,8 @@ def build_story(lines: List[ADRLine], tc_rate: TimecodeFormat, font_name='Helvet
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
line_table = Table(data=line_table_data,
|
line_table = Table(data=line_table_data,
|
||||||
colWidths=[inch * 0.75, inch, inch * 3., 0.5 * inch, inch * 2.],
|
colWidths=[inch * 0.75, inch, inch * 3., 0.5 * inch,
|
||||||
|
inch * 2.],
|
||||||
style=table_style)
|
style=table_style)
|
||||||
|
|
||||||
if (line.scene or "[No Scene]") != this_scene:
|
if (line.scene or "[No Scene]") != this_scene:
|
||||||
@@ -97,7 +104,7 @@ def build_story(lines: List[ADRLine], tc_rate: TimecodeFormat, font_name='Helvet
|
|||||||
|
|
||||||
def build_tc_data(line: ADRLine, tc_format: TimecodeFormat):
|
def build_tc_data(line: ADRLine, tc_format: TimecodeFormat):
|
||||||
tc_data = tc_format.seconds_to_smpte(line.start) + "<br />" + \
|
tc_data = tc_format.seconds_to_smpte(line.start) + "<br />" + \
|
||||||
tc_format.seconds_to_smpte(line.finish)
|
tc_format.seconds_to_smpte(line.finish)
|
||||||
third_line = []
|
third_line = []
|
||||||
if line.reel is not None:
|
if line.reel is not None:
|
||||||
if line.reel[0:1] == 'R':
|
if line.reel[0:1] == 'R':
|
||||||
@@ -111,11 +118,12 @@ def build_tc_data(line: ADRLine, tc_format: TimecodeFormat):
|
|||||||
return tc_data
|
return tc_data
|
||||||
|
|
||||||
|
|
||||||
def generate_report(page_size, lines: List[ADRLine], tc_rate: TimecodeFormat, character_number=None,
|
def generate_report(page_size, lines: List[ADRLine], tc_rate: TimecodeFormat,
|
||||||
include_omitted=True):
|
character_number=None, include_omitted=True):
|
||||||
if character_number is not None:
|
if character_number is not None:
|
||||||
lines = [r for r in lines if r.character_id == character_number]
|
lines = [r for r in lines if r.character_id == character_number]
|
||||||
title = "%s ADR Report (%s)" % (lines[0].title, lines[0].character_name)
|
title = "%s ADR Report (%s)" % (lines[0].title,
|
||||||
|
lines[0].character_name)
|
||||||
document_header = "%s ADR Report" % lines[0].character_name
|
document_header = "%s ADR Report" % lines[0].character_name
|
||||||
else:
|
else:
|
||||||
title = "%s ADR Report" % lines[0].title
|
title = "%s ADR Report" % lines[0].title
|
||||||
|
|||||||
Reference in New Issue
Block a user