From 2aca5a3e8f411b4bb4662980a45ad9e38049d66d Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Mon, 17 May 2021 23:04:38 -0700 Subject: [PATCH] Very rough implementation of line count --- .idea/dictionaries/jamie.xml | 1 + ptulsconv/commands.py | 5 +- ptulsconv/pdf/line_count.py | 90 ++++++++++++++++++++++++++++++++++ ptulsconv/pdf/recordist_log.py | 20 ++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 ptulsconv/pdf/line_count.py create mode 100644 ptulsconv/pdf/recordist_log.py diff --git a/.idea/dictionaries/jamie.xml b/.idea/dictionaries/jamie.xml index 9f6c472..727aec9 100644 --- a/.idea/dictionaries/jamie.xml +++ b/.idea/dictionaries/jamie.xml @@ -2,6 +2,7 @@ fmpxml + futura ptulsconv timecode timespan diff --git a/ptulsconv/commands.py b/ptulsconv/commands.py index e359ddb..43d3683 100644 --- a/ptulsconv/commands.py +++ b/ptulsconv/commands.py @@ -13,6 +13,7 @@ from .reporting import print_section_header_style, print_status_style, print_war from .validations import * from ptulsconv.pdf.supervisor_1pg import output_report as output_supervisor_1pg +from ptulsconv.pdf.line_count import output_report as output_line_count # field_map maps tags in the text export to fields in FMPXMLRESULT # - tuple field 0 is a list of tags, the first tag with contents will be used as source @@ -217,7 +218,9 @@ def convert(input_file, output_format='fmpxml', start=None, end=None, select_ree json.dump(normalize_record_keys(parsed), output) elif output_format == 'full': print("Sorry, the `full` output type is not yet supported.") - output_supervisor_1pg(normalize_record_keys(parsed)) + normalized_records = normalize_record_keys(parsed) + output_supervisor_1pg(normalized_records) + output_line_count(normalized_records) elif output_format == 'fmpxml': if xsl is None: fmp_dump(parsed, input_file, output) diff --git a/ptulsconv/pdf/line_count.py b/ptulsconv/pdf/line_count.py new file mode 100644 index 0000000..9cc0848 --- /dev/null +++ b/ptulsconv/pdf/line_count.py @@ -0,0 +1,90 @@ +from reportlab.pdfgen.canvas import Canvas + +from reportlab.pdfbase import pdfmetrics +from reportlab.pdfbase.ttfonts import TTFont + +from reportlab.lib.units import inch +from reportlab.lib.pagesizes import letter +from reportlab.lib import colors + +from reportlab.lib.styles import getSampleStyleSheet +from reportlab.platypus import Paragraph, Table, TableStyle + +from .common import GRect + +import datetime + + +def output_report(records): + + # CN + # Role + # Actor + # R1, R2, R3, R4, R5, R6 + # Opt + # TV + # EFF + # Total + + reel_numbers = sorted(set([x.get('Reel', None) for x in records['events'] if 'Reel' in x.keys()])) + + aux_columns = [{'heading': 'OPT', 'key': 'Optional'}, + {'heading': 'TV', 'key': 'TV'}, + {'heading': 'EFF', 'key': 'Effort'}] + + sorted_character_numbers = sorted(set([x['CN'] for x in records['events']]), + key=lambda x: int(x)) + + pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc')) + + page: GRect = GRect(0, 0, letter[1], letter[0]) + page = page.inset(inch * 0.5) + + headers = ['#', 'Role', 'Actor'] + + if len(reel_numbers) > 0: + for n in reel_numbers: + headers.append(n) + + headers.append("Total") + + for m in aux_columns: + headers.append(m['heading']) + + line_count_data = [headers] + + + for cn in sorted_character_numbers: + this_row = [cn] + this_character_cues = [x for x in records['events'] if x['Character Number'] == cn] + this_row.append(this_character_cues[0].get('Character Name', "")) + this_row.append(this_character_cues[0].get('Actor Name', "")) + + if len(reel_numbers) > 0: + for _ in reel_numbers: + this_row.append("X") + + this_row.append(len([x for x in this_character_cues if 'Omit' not in x.keys()])) + for m in aux_columns: + this_row.append(0) + + line_count_data.append(this_row) + pass + + style = TableStyle([('FONTNAME', (0, 0), (-1, -1), 'Futura'), + ('FONTSIZE', (0, 0), (-1, -1), 11), + ('LINEBELOW', (0, 0), (-1, 0), 1.0, colors.black), + ('ALIGN', (3, 1), (-1, -1), 'RIGHT') + ] + ) + + table = Table(data=line_count_data, style=style, colWidths=[0.5 * inch, 1.25 * inch, 2. * inch, 0.5 * inch, + 0.5 * inch, 0.5 * inch, 0.5 * inch, 0.5 * inch]) + + c = Canvas('Line Count.pdf', pagesize=(letter[1], letter[0])) + + w, h = table.wrap(page.width, page.height) + table.drawOn(canvas=c, x=page.min_x, y=page.max_y - h) + + c.showPage() + c.save() diff --git a/ptulsconv/pdf/recordist_log.py b/ptulsconv/pdf/recordist_log.py new file mode 100644 index 0000000..8d7a5f0 --- /dev/null +++ b/ptulsconv/pdf/recordist_log.py @@ -0,0 +1,20 @@ +from reportlab.pdfgen.canvas import Canvas + +from reportlab.pdfbase import pdfmetrics +from reportlab.pdfbase.ttfonts import TTFont + +from reportlab.lib.units import inch +from reportlab.lib.pagesizes import letter + +from reportlab.lib.styles import getSampleStyleSheet +from reportlab.platypus import Paragraph + +from .common import GRect + +import datetime + + +def output_report(records): + # order by start + + pass \ No newline at end of file