Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
iluvcapra committed Jul 21, 2023
1 parent 622f049 commit fbcbba1
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 69 deletions.
162 changes: 105 additions & 57 deletions ptulsconv/pdf/line_count.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
# from reportlab.pdfbase import pdfmetrics
# from reportlab.pdfbase.ttfonts import TTFont

from reportlab.lib.units import inch
from reportlab.lib.pagesizes import letter, portrait
Expand All @@ -18,8 +18,8 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
show_priorities=False, include_omitted=False):
columns = list()
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

Expand All @@ -46,35 +46,49 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],

columns.append({
'heading': 'TV',
'value_getter': (lambda recs: len([r for r in recs if r.tv])),
'value_getter2': (lambda recs:
time_format(sum([r.time_budget_mins or 0.
for r in recs if r.tv]))),
'style_getter': (lambda col_index:
[('ALIGN', (col_index, 0), (col_index, -1), 'CENTER'),
'value_getter': lambda recs: len([r for r in recs if r.tv]),
'value_getter2': (lambda recs:
time_format(sum([r.time_budget_mins or 0.
for r in recs if r.tv]))
),
'style_getter': (lambda col_index:
[('ALIGN', (col_index, 0), (col_index, -1),
'CENTER'),
('LINEBEFORE', (col_index, 0), (col_index, -1),
1., colors.black),
('LINEAFTER', (col_index, 0), (col_index, -1),
.5, colors.gray)]),
.5, colors.gray)]
),
'width': num_column_width
})

columns.append({
'heading': 'Opt',
'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.
for r in recs if r.optional])),
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER'),
('LINEAFTER', (col_index, 0), (col_index, -1), .5, colors.gray)],
'value_getter2': (lambda recs:
time_format(sum([r.time_budget_mins or 0.
for r in recs if r.optional]))
),
'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
})

columns.append({
'heading': 'Eff',
'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.
for r in recs if r.effort])),
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')],
'value_getter2': (lambda recs:
time_format(sum([r.time_budget_mins or 0.
for r in recs if r.effort]))
),
'style_getter': (lambda col_index:
[('ALIGN', (col_index, 0), (col_index, -1),
'CENTER')]
),
'width': num_column_width
})

Expand All @@ -90,42 +104,53 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
})

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:
columns.append({
'heading': n,
'value_getter': lambda recs, n1=n: len([r for r in recs if r.reel == n1]),
'value_getter2': lambda recs, n1=n: 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)],
'value_getter': (lambda recs, n1=n:
len([r for r in recs if r.reel == n1])
),
'value_getter2': (lambda recs, n1=n:
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
})

if show_priorities:
for n in range(1, 6,):
columns.append({
'heading': 'P%i' % n,
'value_getter': lambda recs: len([r 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])),
'value_getter': lambda recs: len([r 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: [],
'width': num_column_width
})

columns.append({
'heading': '>P5',
'value_getter': lambda recs: len([r 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])),
'value_getter': lambda recs: len([r 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: [],
'width': num_column_width
})
Expand All @@ -134,32 +159,47 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
columns.append({
'heading': 'Omit',
'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.
for r in recs if r.omitted])),
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')],
'value_getter2': (lambda recs:
time_format(sum([r.time_budget_mins or 0.
for r in recs if r.omitted]))),
'style_getter': (lambda col_index:
[('ALIGN', (col_index, 0), (col_index, -1),
'CENTER')]
),
'width': num_column_width
})

columns.append({
'heading': 'Total',
'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.
for r in recs if not r.omitted]), zero_str=None),
'style_getter': lambda col_index: [('LINEBEFORE', (col_index, 0), (col_index, -1), 1.0, colors.black),
('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')],
'value_getter2': (lambda recs:
time_format(
sum([r.time_budget_mins or 0.

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
})

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()
styles = list()
columns_widths = list()

sorted_character_numbers: List[str] = sorted(set([x.character_id for x in lines]),
key=lambda x: str(x))
sorted_character_numbers: List[str] = sorted(
set([x.character_id for x in lines]),
key=lambda x: str(x))

# construct column styles

Expand All @@ -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_data2.append(col['value_getter2'](list(char_records)))

styles.extend([('TEXTCOLOR', (0, row2_index), (-1, row2_index), colors.red),
('LINEBELOW', (0, row2_index), (-1, row2_index), 0.5, colors.black)])
styles.extend([('TEXTCOLOR', (0, row2_index), (-1, row2_index),
colors.red),
('LINEBELOW', (0, row2_index), (-1, row2_index),
0.5, colors.black)])

data.append(row_data)
data.append(row_data2)
Expand All @@ -202,7 +244,8 @@ def populate_columns(lines: List[ADRLine], columns, include_omitted, _page_size)
summary_row1.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_row2)
Expand All @@ -214,17 +257,20 @@ def populate_columns(lines: List[ADRLine], columns, include_omitted, _page_size)
# pass


def output_report(lines: List[ADRLine], reel_list: List[str], include_omitted=False,
page_size=portrait(letter), font_name='Helvetica'):
columns = build_columns(lines, include_omitted=include_omitted, reel_list=reel_list)
data, style, columns_widths = populate_columns(lines, columns, include_omitted, page_size)
def output_report(lines: List[ADRLine], reel_list: List[str],
include_omitted=False, page_size=portrait(letter),
font_name='Helvetica'):
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(('FONTSIZE', (0, 0), (-1, -1), 9.))
style.append(('LINEBELOW', (0, 0), (-1, 0), 1.0, colors.black))
# 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
filename = title + '.pdf'
Expand All @@ -236,7 +282,8 @@ def output_report(lines: List[ADRLine], reel_list: List[str], include_omitted=Fa
document_header='Line Count')

# 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)

Expand All @@ -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])

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)
2 changes: 1 addition & 1 deletion ptulsconv/pdf/recordist_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
def output_report(records):
# order by start

pass
pass
30 changes: 19 additions & 11 deletions ptulsconv/pdf/summary_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,28 @@ def build_aux_data_field(line: ADRLine):
tag_field = ""
if line.effort:
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:
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:
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:
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)

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()

this_scene = None
Expand All @@ -60,7 +65,8 @@ def build_story(lines: List[ADRLine], tc_rate: TimecodeFormat, font_name='Helvet
('LEFTPADDING', (0, 0), (0, 0), 0.0),
('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)

Expand All @@ -79,7 +85,8 @@ def build_story(lines: List[ADRLine], tc_rate: TimecodeFormat, font_name='Helvet
]]

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)

if (line.scene or "[No Scene]") != this_scene:
Expand All @@ -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):
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 = []
if line.reel is not None:
if line.reel[0:1] == 'R':
Expand All @@ -111,11 +118,12 @@ def build_tc_data(line: ADRLine, tc_format: TimecodeFormat):
return tc_data


def generate_report(page_size, lines: List[ADRLine], tc_rate: TimecodeFormat, character_number=None,
include_omitted=True):
def generate_report(page_size, lines: List[ADRLine], tc_rate: TimecodeFormat,
character_number=None, include_omitted=True):
if character_number is not None:
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
else:
title = "%s ADR Report" % lines[0].title
Expand Down

0 comments on commit fbcbba1

Please sign in to comment.