def generate_card_results(self, tracks: List[Song], cards: List[BingoTicket]): """generate PDF showing when each ticket wins""" doc = DG.Document(pagesize=PageSizes.A4, title=f'{self.options.game_id} - {self.options.title}', topMargin="0.25in", bottomMargin="0.25in", rightMargin="0.25in", leftMargin="0.25in") doc.append(self.options.palette.logo_image("6.2in")) doc.append(DG.Spacer(width=0, height="0.05in")) doc.append(DG.Paragraph( f'Results For Game Number: <b>{self.options.game_id}</b>', self.TEXT_STYLES['results-heading'])) doc.append(DG.Paragraph( self.options.title, self.TEXT_STYLES['results-title'])) pstyle = self.TEXT_STYLES['results-cell'] heading: DG.TableRow = [ DG.Paragraph('<b>Ticket Number</b>', pstyle), DG.Paragraph('<b>Wins after track</b>', pstyle), DG.Paragraph('<b>Start Time</b>', pstyle), ] data: List[DG.TableRow] = [] cards = copy.copy(cards) cards.sort(key=lambda card: card.ticket_number, reverse=False) for card in cards: win_point = self.get_when_ticket_wins(tracks, card) song = tracks[win_point - 1] data.append([ DG.Paragraph(f'{card.ticket_number}', pstyle), DG.Paragraph( f'Track {win_point} - {song.title} ({song.artist})', pstyle), DG.Paragraph(Duration(song.start_time).format(), pstyle) ]) col_widths: List[Dimension] = [ Dimension("0.75in"), Dimension("5.5in"), Dimension("0.85in"), ] hstyle = pstyle.replace( name='results-table-heading', background=self.options.palette.title_bg) tstyle = TableStyle(name='results-table', borderColour=Colour('black'), borderWidth=1.0, gridColour=Colour('black'), gridWidth=0.5, verticalAlignment=VerticalAlignment.CENTER, headingStyle=hstyle) table = DG.Table(data, heading=heading, repeat_heading=True, colWidths=col_widths, style=tstyle) doc.append(table) filename = str(self.options.ticket_results_output_name()) self.doc_gen.render(filename, doc, Progress())
def generate_tickets_pdf(self, cards: List[BingoTicket]) -> None: """generate a PDF file containing all the Bingo tickets""" doc = DG.Document(pagesize=PageSizes.A4, title=f'{self.options.game_id} - {self.options.title}', topMargin="0.15in", rightMargin="0.15in", bottomMargin="0.15in", leftMargin="0.15in") page: int = 1 num_cards: int = len(cards) cards_per_page: int = 3 if self.options.rows == 2: cards_per_page = 4 elif self.options.rows > 3: cards_per_page = 2 id_style = self.TEXT_STYLES['ticket-id'] title_style = id_style.replace('ticket-title', alignment=HorizontalAlignment.LEFT) for count, card in enumerate(cards, start=1): self.progress.text = f'Card {count}/{num_cards}' self.progress.pct = 100.0 * float(count) / float(num_cards) self.render_bingo_ticket(card, doc) data: List[DG.TableRow] = [[ DG.Paragraph(self.options.title, title_style), DG.Paragraph( f"{self.options.game_id} / T{card.ticket_number} / P{page}", id_style), ]] tstyle = TableStyle(name='ticket-id', borderWidth=0, gridWidth=0, verticalAlignment=VerticalAlignment.CENTER) table = DG.Table( data, colWidths=[Dimension(80), Dimension(80)], rowHeights=[Dimension(f'16pt')], style=tstyle) doc.append(table) if count % cards_per_page != 0: doc.append( DG.HorizontalLine('hline', width="100%", thickness="1px", colour=Colour('gray'), dash=[2, 2])) doc.append(DG.Spacer(width=0, height="0.08in")) else: doc.append(DG.PageBreak()) page += 1 filename = str(self.options.bingo_tickets_output_name()) self.doc_gen.render(filename, doc, Progress())
def generate_track_listing(self, tracks: List[Song]) -> None: """generate a PDF version of the track order in the game""" assert len(tracks) > 0 doc = DG.Document( PageSizes.A4, topMargin="0.25in", bottomMargin="0.25in", leftMargin="0.35in", rightMargin="0.35in", title=f'{self.options.game_id} - {self.options.title}') doc.append(self.options.palette.logo_image("6.2in")) doc.append(DG.Spacer(width=0, height="0.05in")) doc.append( DG.Paragraph( f'Track Listing For Game Number: <b>{self.options.game_id}</b>', self.TEXT_STYLES['track-heading'])) doc.append( DG.Paragraph(self.options.title, self.TEXT_STYLES['track-title'])) cell_style = self.TEXT_STYLES['track-cell'] heading: DG.TableRow = [ DG.Paragraph('<b>Order</b>', cell_style), DG.Paragraph('<b>Title</b>', cell_style), DG.Paragraph('<b>Artist</b>', cell_style), DG.Paragraph('<b>Start Time</b>', cell_style), DG.Paragraph('', cell_style), ] data: List[DG.TableRow] = [] for index, song in enumerate(tracks, start=1): order = DG.Paragraph(f'<b>{index}</b>', cell_style) title = DG.Paragraph(song.title, cell_style) if self.should_include_artist(song): artist = DG.Paragraph(song.artist, cell_style) else: artist = DG.Paragraph('', cell_style) start = DG.Paragraph( Duration(song.start_time).format(), cell_style) end_box = DG.Paragraph('', cell_style) data.append([order, title, artist, start, end_box]) col_widths = [ Dimension("0.55in"), Dimension("2.9in"), Dimension("2.9in"), Dimension("0.85in"), Dimension("0.2in") ] hstyle = cell_style.replace(name='track-table-heading', background=self.options.palette.title_bg) tstyle = TableStyle(name='track-table', borderColour=Colour('black'), borderWidth=1.0, gridColour=Colour('black'), gridWidth=0.5, verticalAlignment=VerticalAlignment.CENTER, headingStyle=hstyle) table = DG.Table(data, heading=heading, repeat_heading=True, colWidths=col_widths, style=tstyle) doc.append(table) filename = str(self.options.track_listing_output_name()) self.doc_gen.render(filename, doc, Progress())