diff --git a/ptulsconv/commands.py b/ptulsconv/commands.py index 79f9688..7fb0d22 100644 --- a/ptulsconv/commands.py +++ b/ptulsconv/commands.py @@ -53,6 +53,7 @@ adr_field_map = ((['Title', 'PT.Session.Name'], 'Title', str), (['Movie.Start_Offset_Seconds'], 'Movie Seconds', float), ) + def dump_field_map(field_map_name, output=sys.stdout): output.write("# Map of Tag fields to XML output columns\n") output.write("# (in order of precedence)\n") @@ -70,6 +71,7 @@ def dump_field_map(field_map_name, output=sys.stdout): for tag in field[0]: output.write("# %-27s-> %-20s | %-8s| %-7i\n" % (tag[:27], field[1][:20], field[2].__name__, n + 1)) + def normalize_record_keys(records): for record in records['events']: for field in adr_field_map: diff --git a/ptulsconv/pdf/common.py b/ptulsconv/pdf/common.py index 5c541ee..b191bd2 100644 --- a/ptulsconv/pdf/common.py +++ b/ptulsconv/pdf/common.py @@ -75,8 +75,10 @@ def make_doc_template(page_size, filename, document_title, record, document_head -def time_format(mins): - if mins < 60.: +def time_format(mins, zero_str = ""): + if mins == 0. and zero_str is not None: + return zero_str + elif mins < 60.: return "%im" % round(mins) else: m = round(mins) diff --git a/ptulsconv/pdf/line_count.py b/ptulsconv/pdf/line_count.py index 04a2b25..46f5018 100644 --- a/ptulsconv/pdf/line_count.py +++ b/ptulsconv/pdf/line_count.py @@ -26,41 +26,51 @@ def build_columns(records, show_priorities = False): else: return str(l) + num_column_width = 0.375 * inch + columns.append({ 'heading': '#', 'value_getter': lambda recs: recs[0]['Character Number'], + 'value_getter2': lambda recs: "", 'style_getter': lambda col_index: [], - 'width': 0.75 * inch + 'width': 0.375 * inch, + 'summarize': False }) columns.append({ 'heading': 'Role', 'value_getter': lambda recs: recs[0]['Character Name'], - 'style_getter': lambda col_index: [], - 'width': 1.75 * inch + 'value_getter2': lambda recs: recs[0].get('Actor Name', ""), + 'style_getter': lambda col_index: [('LINEAFTER', (col_index, 0), (col_index, -1), 1.0, colors.black)], + 'width': 1.75 * inch, + 'summarize': False }) - columns.append({ - 'heading': 'Actor', - 'value_getter': lambda recs: recs[0].get('Actor Name', ''), - 'style_getter': lambda col_index: [(('LINEAFTER'), (col_index, 0), (col_index, -1), 1.0, colors.black)], - 'width': 1.75 * inch - }) + # columns.append({ + # 'heading': 'Actor', + # 'value_getter': lambda recs: recs[0].get('Actor Name', ''), + # 'style_getter': lambda col_index: [(('LINEAFTER'), (col_index, 0), (col_index, -1), 1.0, colors.black)], + # 'width': 1.75 * inch + # }) - if len(reel_numbers) > 0: + if True: #len(reel_numbers) > 0: columns.append({ 'heading': 'RX', 'value_getter': lambda recs: blank_len([r for r in recs if r.get('Reel', None) in ("", None)]), - 'style_getter': lambda col_index: [], - 'width': 0.5 * inch + 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) for r in recs + if r.get('Reel', None) in ("", None)])), + '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: blank_len([r for r in recs if r['Reel'] == n]), - 'style_getter': lambda col_index: [], - 'width': 0.5 * inch + 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) for r in recs + if r['Reel'] == n])), + 'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')], + 'width': num_column_width }) if show_priorities: @@ -68,52 +78,64 @@ def build_columns(records, show_priorities = False): columns.append({ 'heading': 'P%i' % n, 'value_getter': lambda recs: blank_len([r for r in recs if r.get('Priority', None) == n]), + 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) + for r in recs if r.get('Priority', None) == n])), 'style_getter': lambda col_index: [], - 'width': 0.375 * inch + 'width': num_column_width }) columns.append({ 'heading': '>P5', 'value_getter': lambda recs: blank_len([r for r in recs if r.get('Priority', 5) > 5]), + 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) + for r in recs if r.get('Priority', 5) > 5])), 'style_getter': lambda col_index: [], - 'width': 0.375 * inch + 'width': num_column_width }) columns.append({ 'heading': 'TV', 'value_getter': lambda recs: blank_len([r for r in recs if 'TV' in r.keys()]), - 'style_getter': lambda col_index: [], - 'width': 0.375 * inch + 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) for r in recs if 'TV' in r.keys()])), + '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),], + 'width': num_column_width }) columns.append({ 'heading': 'Opt', 'value_getter': lambda recs: blank_len([r for r in recs if 'Optional' in r.keys()]), - 'style_getter': lambda col_index: [], - 'width': 0.375 * inch + 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) for r in recs if 'Optional' in r.keys()])), + '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: blank_len([r for r in recs if 'Effort' in r.keys()]), - 'style_getter': lambda col_index: [], - 'width': 0.375 * inch - }) + # columns.append({ + # 'heading': 'Eff', + # 'value_getter': lambda recs: blank_len([r for r in recs if 'Effort' in r.keys()]), + # 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins',0.) for r in recs if 'Effort' in r.keys()])), + # 'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER')], + # 'width': 0.5 * inch + # }) columns.append({ 'heading': 'Total', 'value_getter': lambda recs: len([r for r in recs if 'Omitted' not in r.keys()]), - 'style_getter': lambda col_index: [(('LINEBEFORE'), (col_index, 0), (col_index, -1), 1.0, colors.black), - ('ALIGN', (col_index, 0), (col_index, -1), 'RIGHT')], - 'width': 0.5 * inch + 'value_getter2': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) + for r in recs if 'Omitted' not in r.keys()]), 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')], + 'width': num_column_width }) - columns.append({ - 'heading': 'Studio Time', - 'value_getter': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) for r in recs])), - 'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'RIGHT')], - 'width': inch - }) + # columns.append({ + # 'heading': 'Studio Time', + # 'value_getter': lambda recs: time_format(sum([r.get('Time Budget Mins', 0.) for r in recs])), + # 'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'RIGHT')], + # 'width': inch + # }) # columns.append({ # 'heading': 'Omit', @@ -139,19 +161,42 @@ def populate_columns(records, columns): styles.extend(c['style_getter'](i)) columns_widths.append(c['width']) - # construct data table - # headers data.append(list(map(lambda x: x['heading'], columns))) - # values + lines = [x for x in records['events'] if 'Omitted' not in x.keys()] + for n in sorted_character_numbers: - char_records = sorted([x for x in records['events'] if x['Character Number'] == n], + char_records = sorted([x for x in lines if x['Character Number'] == n], key=lambda x: x['PT.Clip.Start_Seconds']) row_data = list() + row_data2 = list() for col in columns: + row1_index = len(data) + row2_index = row1_index + 1 row_data.append(col['value_getter'](char_records)) + row_data2.append(col['value_getter2'](char_records)) + 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) + + summary_row1 = list() + summary_row2 = list() + row1_index = len(data) + + for col in columns: + if col.get('summarize', True): + summary_row1.append(col['value_getter'](lines)) + summary_row2.append(col['value_getter2'](lines)) + else: + summary_row1.append("") + summary_row2.append("") + + styles.append(('LINEABOVE', (0, row1_index), (-1, row1_index), 2.0, colors.black)) + + data.append(summary_row1) + data.append(summary_row2) return data, styles, columns_widths @@ -160,7 +205,7 @@ def output_report(records): columns = build_columns(records) data, style, columns_widths = populate_columns(records, columns) style.append(('FONTNAME', [0, 0], (-1, -1), "Futura")) - style.append(('FONTSIZE', (0, 0), (-1, -1), 11)) + 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)) @@ -172,22 +217,6 @@ def output_report(records): document_title=title, record=records['events'][0], document_header='Line Count') - # page: GRect = GRect(0, 0, letter[1], letter[0]) - # page = page.inset(inch * 0.5) - # title_box, table_box = page.split_y(inch, 'd') - # - # c = ReportCanvas('%s Line Count.pdf' % records['events'][0]['Title'], pagesize=(letter[1], letter[0])) - # c.setFont('Futura', 18.) - # c.drawCentredString(title_box.center_x, title_box.center_y, "Line Count") - # table = Table(data=data, style=style, colWidths=columns_widths) - # - # w, h = table.wrap(table_box.width, table_box.height) - # table.drawOn(canvas=c, - # x=table_box.min_x + table_box.width / 2. - w / 2., - # y=table_box.max_y - h) doc.build([table]) - - # c.showPage() - # c.save() diff --git a/ptulsconv/pdf/summary_log.py b/ptulsconv/pdf/summary_log.py index 357aa41..6e25abc 100644 --- a/ptulsconv/pdf/summary_log.py +++ b/ptulsconv/pdf/summary_log.py @@ -41,6 +41,7 @@ def build_story(lines): scene_style = getSampleStyleSheet()['Normal'] scene_style.fontName = 'Futura' scene_style.leftIndent = 0. + scene_style.leftPadding = 0. line_style = getSampleStyleSheet()['Normal'] line_style.fontName = 'Futura' diff --git a/ptulsconv/pdf/talent_sides.py b/ptulsconv/pdf/talent_sides.py index 3e06d0a..505036f 100644 --- a/ptulsconv/pdf/talent_sides.py +++ b/ptulsconv/pdf/talent_sides.py @@ -59,8 +59,9 @@ def output_report(records): # Unicode: U+2192, UTF-8: E2 86 92 story.append( KeepTogether( - [HRFlowable(width='100%', color=colors.black), - Table(data=data_block, colWidths=[1.5 * inch, 6. * inch]), + [HRFlowable(width='50%', color=colors.black), + Table(data=data_block, colWidths=[1.5 * inch, 6. * inch], + style=[('LEFTPADDING', (0, 0), (-1, -1), 0.)]), Paragraph(line['Line'], prompt_style), Spacer(1., inch * 1.5)] )