#!/usr/bin/env python # -*- coding: utf8 -*- # Python program to create # password-protected bonus files # Create pdf using FPDF # Encrypt PDF using pyPDF2 # Get file name and password import PyPDF2 import random from fpdf import FPDF from pathlib import Path import numpy as np def shuffleOutcomes(risk, resolutionType): x1 = risk[0][0] p1 = risk[0][1] x0 = risk[1][0] p0 = risk[1][1] if resolutionType == "shell": payoff = [x1, x0] elif resolutionType == 'cards': # cards are numbered from 1 to 100 - shuffled assignment # Payoff gives final position of each card payoff = list(range(100)) random.shuffle(payoff) return payoff def shuffleAmounts(allAmounts): numTypes = len(allAmounts) selectedType = list(range(numTypes)) envelopeNumbers = [] while len(envelopeNumbers) < numTypes: newNum = random.randint(1111,9999) if newNum not in envelopeNumbers: envelopeNumbers.append(newNum) assignedType = random.sample(envelopeNumbers, numTypes) selectedType = random.sample(selectedType, numTypes) shuffledPay = [allAmounts[t] for t in selectedType] return {z[0]: list(z[1:]) for z in zip(assignedType, shuffledPay, selectedType)} def shuffleColorTypes(colorList, allAmounts): numTypes = len(allAmounts) if len(colorList) != len(allAmounts): raise ValueError selectedType = list(range(numTypes)) assignedType = random.sample(selectedType, numTypes) shuffledPay = [allAmounts[num] for num in assignedType] return {z[0]: list(z[1:]) for z in zip(selectedType, colorList, assignedType, shuffledPay)} def matchingProbabilities(colorList, shapes): numTypes = 101 # all propbabilities selectedType = list(range(numTypes)) assignedType = random.sample(selectedType, numTypes) # Output selected type as index, [color, shape, assignedType] tmp = [ [color, shape] for shape in shapes for color in colorList[:-1]] #tmp = tmp[:numTypes] # only safe correct number of elements tmp.append([colorList[-1], shapes[-1]]) typeDict = {} for idx, info in enumerate(tmp): typeDict[idx] = [info[0], info[1], assignedType[idx]] return typeDict ''' def shuffleOutcomes(bonusFileDict): shuffledDict = {} for key, value in bonusFileDict.items(): taskType = value[0] resolutionType = value[1] risk = value[2] x1 = risk[0][0] p1 = risk[0][1] x0 = risk[1][0] p0 = risk[1][1] if resolutionType == "shell": payoff = [x1, x0] elif resolutionType == 'cards': x1List = [x1 for i in range(int(p1 * 100))] x0List = [x0 for i in range(int(p0 * 100))] payoff = x1List + x0List random.shuffle(payoff) shuffledDict[key] = [taskType, resolutionType, payoff] return shuffledDict ''' # Create PDFs def protectPDF(inputfile, password, outputfile): pdfFile = open(inputfile, 'rb') # Create reader and writer object pdfReader = PyPDF2.PdfFileReader(pdfFile) pdfWriter = PyPDF2.PdfFileWriter() # Add all pages to writer (accepted answer results into blank pages) for pageNum in range(pdfReader.numPages): pdfWriter.addPage(pdfReader.getPage(pageNum)) # Encrypt with your password pdfWriter.encrypt(password) # Write it to an output file. (you can delete unencrypted version now) resultPdf = open(outputfile, 'wb') pdfWriter.write(resultPdf) resultPdf.close() def verificationPDF( verificationType, shuffledPayoff, inputfile, typeMatching, #bonusFileDict, #shuffledDict, #password_bonusFile ): class PDF(FPDF): def footer(self): # Go to 1.5 cm from bottom self.set_y(-10) # Select Arial italic 8 self.set_font('DejaVu', 'I', 8) # Print centered page number self.cell(w=210, h=10, txt= 'Page %s' % self.page_no(), align = 'C') def titles(self, text): self.set_xy(0.0,0.0) self.set_font('DejaVu', 'B', 16) self.cell(w=210.0, h=40.0, align='C', txt=text, border=0) th = self.font_size self.ln(th) def subTitles(self, text): y_pos = self.get_y() self.set_xy(left, y_pos) self.set_font('DejaVu', 'B', 14) th = self.font_size self.multi_cell(w=pdf_w - 2 * left , h=th, align='L', txt=text, border=0) self.ln(th) def write_multicell(self, startx, text): starty = self.get_y() if starty <= top: starty = top self.set_xy(startx, starty) self.set_font('DejaVu', '', 12) th = self.font_size self.multi_cell(w=pdf_w - 2 * left , h=th * 1.2, align='J', txt=text, border=0) self.ln(th) def write_multicell_with_styles(self, startx, text_list, color = None): starty = self.get_y() self.set_font('DejaVu', '', 14) if starty <= top: starty = top self.set_xy(startx, starty) th = self.font_size #loop through differenct sections in different styles for text_part in text_list: #check and set style try: current_style = text_part['style'] except KeyError: current_style = '' try: textcolor = text_part['coloredtext'] h = textcolor.lstrip('#') rgbColor = tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) self.set_fill_color(rgbColor[0], rgbColor[1], rgbColor[2]) self.cell(h = th * 1.3, txt=text_part["text"], fill=True) continue except KeyError: "" try: data = text_part["coloredShape"] shapeColor = data[0] shape = data[1] h = shapeColor.lstrip('#') rgbColor = tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) # test if we need new line shapeSize = 7 currentX = self.get_x() if (currentX + shapeSize) > (pdf_w - left): self.cell(w = 0, h= th * 1.3, fill=False) self.set_y(self.get_y() + th * 1.2) self.set_x(startx) self.set_fill_color(rgbColor[0], rgbColor[1], rgbColor[2]) self.drawShape(shape, self.get_x(), self.get_y() - 1, shapeSize ) self.set_x(startx + shapeSize) except KeyError: "" self.set_font('DejaVu', current_style, 12) if color: line_break = False if '\n' in text_part['text']: line_break = True # Need to use cells for writing text to achieve coloring self.set_fill_color(232, 232, 232) #loop through words and write them down space_width = self.get_string_width(' ') for word in text_part['text'].split(): #print(text_part['text']) current_pos = self.get_x() word_width = self.get_string_width(word + " ") + space_width #check for newline if (current_pos + word_width) > (pdf_w - left): self.cell(w = 0, h= th * 1.3, fill=True) self.set_y(self.get_y() + th * 1.2) self.set_x(startx) if int(round(self.get_x(),0)) != startx: self.cell(word_width, th * 1.3, " " + word, fill=True) else: self.cell(word_width, th * 1.3, word, fill=True) # Add line if last element and line break symbol if line_break and word == list(text_part['text'].split())[-1]: self.cell(w = 0, h= th * 1.3, fill=True) self.ln(th * 1.2) if text_part == text_list[-1]: ## Fill Last Line self.cell(w = 0, h= th * 1.3, fill=True) else: self.write(th * 1.2 , text_part['text']) self.ln(th) def enumeration(self, justify, number, text): self.set_font('DejaVu', '', 12) startx = self.get_x() + justify starty = self.get_y() th = self.font_size self.set_xy(startx, starty) self.cell(w=justify, h=th*1.2, align='L', txt=number, border=0) self.set_xy(startx + justify, starty) self.multi_cell(w=0, h=th * 1.2, align='L', txt=text, border=0) self.ln(th) def subEnumeration(self, justify, text): self.set_font('DejaVu', '', 12) startx = self.get_x() + 2 * justify starty = self.get_y() th = self.font_size self.set_xy(startx, starty) self.cell(w=justify, h=th * 1.2, align='L', txt="-", border=0) self.set_xy(startx + justify/2, starty) self.multi_cell(w=0, h=th*1.2, align='L', txt=text, border=0) self.ln(th) def table1(self, data): self.set_line_width(0.5) th = self.font_size col_width = (pdf_w - 2 * left) / 6 col_grid = [0.8, 0.8, 2.8, 0.8, 0.8] width_list = [col_width * space for space in col_grid] self.set_font('DejaVu', 'B', 12) self.cell(w=col_width, h=th*1.2, align='L', txt="Table 1: Content of the bonus files", border=0) self.ln(th * 1.5) startx = self.get_x() starty = self.get_y() self.line(startx, starty, startx+pdf_w - 2*left ,starty) self.cell(w=width_list[0], h=th*2, align='C', txt="Bonus file", border=0) self.cell(w=width_list[1], h=th*2, align='C', txt="Method", border=0) self.cell(w=width_list[2], h=th*2, align='C', txt="Option 1", border=0) self.cell(w=width_list[3], h=th*2, align='C', txt="Option 2", border=0) self.cell(w=width_list[4], h=th*2, align='C', txt="Details", border=0) self.line(startx, starty + th*2, startx + pdf_w - 2*left, starty + th*2) self.ln(th*2) self.set_font('DejaVu', '', 10) num = 1 page = 4 for key in data: if (num % 2) == 0: self.set_fill_color(200, 200, 200) else: self.set_fill_color(255, 255, 255) infos = data[key] resolutionMethod = infos[1].capitalize() risk = infos[2] option1= "£" + '%.2f' %risk[0][0] + " with " + '%.0f' %(risk[0][1] * 100) + "% probability and £" + '%.2f' %risk[1][0] + " otherwise." option2 = "£" + '%.2f' %infos[3] self.cell(w=width_list[0], h=th*1.2, align='C', txt=str(key), fill=True) self.cell(w=width_list[1], h=th*1.2, align='C', txt=str(resolutionMethod), fill=True) self.cell(w=width_list[2], h=th*1.2, align='C', txt=option1, fill=True) self.cell(w=width_list[3], h=th*1.2, align='C', txt=option2, fill=True) self.cell(w=width_list[4], h=th*1.2, align='C', txt="p. " + str(page), fill=True) self.ln(th*1.2) num += 1 page += 1 startx = self.get_x() starty = self.get_y() self.line(startx, starty, startx+pdf_w - 2*left ,starty) self.set_fill_color(255, 255, 255) def colorGraphic(self, data, figNumber): # data is a dictionary - get relevant data in correct order first tableList = [ [item[1][0], item[1][2]] for item in data.items() ] #tableList.sort(key=lambda tup: tup[1]) # Write table th = self.font_size numCols = 10 col_width = (pdf_w - 2 * left) / numCols col_grid = [2, 1, 1, 1, 1, 1, 1, 2] width_list = [col_width * space for space in col_grid] colorCols = 6 cellFactor = 0.6 cellSize = col_width * cellFactor numRows = len(tableList) % colorCols + 1 if self.get_y() + numRows * cellSize > 260: # Graphic extends over page self.add_page() startx = self.get_x() + width_list[0] starty = self.get_y() self.set_font('DejaVu', '', 10) self.set_text_color(255,255,255) self.set_y(starty) num = 0 columnX = startx self.set_x(startx) self.ln(th) for color, payoff in tableList: option2 = "£" + '%.2f' %payoff h = color.lstrip('#') rgbColor = tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) self.set_fill_color(rgbColor[0], rgbColor[1], rgbColor[2]) colorX = columnX + col_width * ((1-cellFactor) / 2) self.set_x(colorX) self.cell(w=cellSize, h= cellSize, txt=option2, align='C', fill=True) columnX = columnX + width_list[(num % colorCols) + 1] num += 1 if num>0 and ((num % colorCols) == 0): endx = self.get_x() + cellSize * 0.1 self.ln(cellSize * 1.1) columnX = startx self.set_x(startx) self.ln(th) endy = self.get_y() + cellSize # Draw border around self.set_xy(startx,starty) self.cell(w = endx - startx, h=endy-starty, border=True) self.set_xy(startx,endy + 0.5 * th ) self.set_font('DejaVu', 'B', 12) self.set_text_color(0,0,0) self.cell(txt="Figure " + str(figNumber) + ": Assignment of safe amounts to colors", align='L', border=0) self.set_fill_color(255, 255, 255) self.ln() def envelopeShape(self, leftX = 0, topY = 0, elemSize = 0, openEnvelope = False): self.set_line_width(0.5) middleX = leftX + elemSize / 2 rightX = leftX + elemSize corpusY = topY + (1/4) * elemSize bottomY = topY + 0.8 * elemSize # ensure rectangular appearance if openEnvelope: # Outside shape via polygon coords = ((middleX, topY), (leftX, corpusY), (leftX, bottomY), (rightX, bottomY), (rightX, corpusY), (middleX, topY)) self.polygon(coords, style="FD") # Internal line self.line(x1=leftX, y1 = corpusY, x2 = rightX, y2 = corpusY) else: bottomY = topY + 0.6 * elemSize # ensure rectangular appearance coords = ((leftX, topY), (leftX, bottomY), (rightX, bottomY), (rightX, topY), (leftX, topY)) self.polygon(coords, style="FD") # Internal line self.line(x1=leftX, y1 = topY, x2 = middleX, y2 = corpusY) self.line(x1=middleX, y1 = corpusY, x2 = rightX , y2 = topY) def envelopeUpper(self, leftX = 0, startY = 10, topY = 0, bottomY = 20, width = 100, height=100): middleX = leftX + 0.5 * width rightX = leftX + width self.set_fill_color(255, 250, 245) coords = ((leftX, startY), (middleX, bottomY), (rightX, startY), (middleX, topY), (leftX, startY)) self.polygon(coords, style="FD") #self.line(x1=leftX, y1=startY, x2 = rightX, y2 = startY) def envelopeCorpus(self, leftX = 0, topY = 0, middleY = 20, bottomY=100, width = 100): middleX = leftX + 0.5 * width rightX = leftX + width self.set_fill_color(255, 248, 239) coords = ((leftX, topY), (leftX, bottomY), (rightX, bottomY), (rightX, topY), (middleX, middleY), (leftX, topY)) self.polygon(coords, style="FD") def choiceSlip(self, leftX = 0, topY=0, bottomY= 100, width = 100, safeAmount=0.00, risk = [0,2]): self.set_fill_color(255, 255, 255) middleX = leftX + 0.5 * width height = bottomY - topY headerHeight = 0.15 * height # Left column halfWidth = 0.5 * width self.set_xy(leftX, topY) self.set_font('DejaVu', 'B', 7) self.cell(w = halfWidth, h= headerHeight, border=1, fill=True, txt ="Risk", align="C") self.set_xy(leftX, topY + headerHeight) self.cell(w = halfWidth, h= height - headerHeight, border=1, fill=True) # Insert Image imWidth = 0.4 * halfWidth lImX = leftX + 0.04 * halfWidth rImX = leftX + 0.96 * halfWidth - imWidth imY = topY + headerHeight + 0.1 * headerHeight self.set_xy(lImX, imY ) self.image("_static/img/shell.png", link='', type='', w= imWidth) self.set_xy(rImX, imY ) self.image("_static/img/shell.png", link='', type='', w= imWidth) # Insert Payoff Slips self.set_font('DejaVu', '', 8) th = 1.2 * self.font_size slipWidth = 0.5 * halfWidth slipX = leftX + 0.5 * (halfWidth - slipWidth) tSlipY = self.get_y() + 0.1 * headerHeight bSlipY = tSlipY + th + 0.2 * headerHeight self.set_xy(slipX, tSlipY) topTxt = "£" + '%.2f' %max(risk) self.cell(w = slipWidth, h= th, border=1, fill=True, txt=topTxt, align="C") self.set_xy(slipX, bSlipY) bottomTxt = "£" + '%.2f' %min(risk) self.cell(w = slipWidth, h= th, border=1, fill=True, txt=bottomTxt, align="C") # Right column - Safe amount self.set_font('DejaVu', 'B', 7) self.set_xy(middleX, topY) self.cell(w = halfWidth, h= headerHeight, border=1, fill=True, txt="Safe amount", align="C") self.set_xy(middleX, topY + headerHeight) self.cell(w = halfWidth, h= height - headerHeight, border=1, fill=True) # Cell for border # Insert Text self.set_font('DejaVu', '', 8) self.set_xy(middleX, topY + headerHeight) safeTxt = "£" + '%.2f' %safeAmount self.cell(w = halfWidth, h= 0.7 * height - headerHeight, border=0, fill=False, txt = safeTxt, align='C') # Cell for text def openEnvelopeAndSlip(self, leftX=0, topY=0, elemWidth=0, elemHeight=0, envelopeNum=00, envelopeAmount = 0, riskPayoff = [2,0]): self.set_xy(leftX, topY) #self.cell(w = elemSize, h= elemSize, border=1) # envelope upper letterTopY = topY + 0.3 * elemHeight corpusStartY = topY + 0.5 * elemHeight openBottomY = topY + 0.7 * elemHeight self.envelopeUpper(leftX, corpusStartY, letterTopY, openBottomY, elemWidth, elemHeight) # choice situation paperLeftX = leftX + 0.04 * elemWidth paperWidth = 0.92 * elemWidth paperTopY = topY + 0.05 * elemHeight paperBottomY = topY + 0.6 * elemHeight self.choiceSlip(leftX = paperLeftX, topY=paperTopY, bottomY= paperBottomY, width = paperWidth, safeAmount=envelopeAmount, risk = riskPayoff) # envelope corpus corpusEndY = topY + 0.95* elemHeight self.envelopeCorpus(leftX=leftX, topY=corpusStartY, middleY=openBottomY, bottomY=corpusEndY, width=elemWidth) # Envelope number self.set_font('DejaVu', 'B', 10) numY = corpusEndY - 1.5 * self.font_size self.set_xy(leftX, numY) self.cell(w= elemWidth, h= 1.1 * self.font_size, align='R', txt=str(envelopeNum), border=0 ) def envelopes(self, safeAmount, riskPayoff, figNumber): #self.add_page() # data is a dictionary - get relevant data in correct order first #print(data.items()) tableList = [ [item[0], item[1][0]] for item in safeAmount.items() ] #self.envelopeShape(leftX= 50, topY = 100, elemSize = 100) self.set_font('DejaVu', '', 10) self.set_text_color(0,0,0) # black text self.set_fill_color(r=255, g=248, b=239) self.set_line_width(0.2) # Write table th = self.font_size numCols = 17 col_width = (pdf_w - 2 * left) / numCols # Column grid is square # effective column size colPerElem = 5 effColWidth = colPerElem * col_width effRowHeight = effColWidth * 0.8 elemColumns = 3 # 10 shapes per row cellFactor = 0.95 # cellWidth = effColWidth * cellFactor cellHeight = effRowHeight * cellFactor ''' if self.get_y() + numRows * col_width > 260: # Graphic extends over page self.add_page() ''' # Define table grid colX = [self.get_x() + i * col_width for i in range(numCols)] effColX = colX[1::colPerElem] upperY = 10 # y-vale after insert_page() rowGrid = np.arange(upperY, 230, effRowHeight) col = 0 # Start in first column if max(rowGrid) < self.get_y(): row = 0 self.add_page() else: row = next(x for x, val in enumerate(rowGrid) if val >= self.get_y()) # Start from closest neighbor that's bigger than current positions for envelopeNum, amount in tableList: # First fill rows, then columns leftX = effColX[col] + (effColWidth - cellWidth) / 2 topY = rowGrid[row] + 1.5 * (effColWidth - cellWidth) self.openEnvelopeAndSlip(leftX=leftX, topY=topY, elemWidth=cellWidth, elemHeight=cellHeight, envelopeNum=envelopeNum, envelopeAmount=amount, riskPayoff=riskPayoff) #self.cell(w=col_width, h= col_width, txt=str(number), align='C', fill=False, border=False) self.set_xy(effColX[col], rowGrid[row]) col += 1 if col == elemColumns: col = 0 row += 1 if row == len(rowGrid): startx = colX[1] endx = colX[-1] starty = rowGrid[0] endy = self.get_y() + cellHeight + 5 # Frame around elements self.set_xy(startx,starty) self.cell(w = endx - startx, h=endy-starty, border=True) row = 0 self.add_page() #Draw border around startx = colX[1] endx = colX[-1] starty = rowGrid[0] endy = rowGrid[row] + 5 self.set_xy(startx,starty) self.cell(w = endx - startx, h=endy-starty, border=True) self.set_xy(startx,endy + 0.5 * th ) self.set_font('DejaVu', 'B', 12) self.set_text_color(0,0,0) self.cell(txt="Figure " + str(figNumber) + ".", align='L', border=0) self.set_fill_color(255, 255, 255) self.ln(4 * th ) #self.add_page() def cardNumbersTable(self, colheaders, data, tableNumber): self.set_line_width(0.5) self.set_font('DejaVu', '', 10) th = self.font_size separationColWidth = 3 # Width of empty column in the middle of the table col_width = (pdf_w - 2 * left - separationColWidth) / (2*len(colheaders)) for key in data: self.set_font('DejaVu', 'B', 12) title = "Table " + str(tableNumber) + ": Winning numbers for the card draws in the " tableNumber += 1 #self.cell(w=col_width, h=th*1.2, align='L', txt=title, border=0) task = key + " Task" if list(key.split())[0] == "Red": self.set_fill_color(255,50,50) elif list(key.split())[0] == "Orange": self.set_fill_color(247,149,29) # write title self.write(txt=title) self.cell(w = self.get_string_width(task) + 3, txt = task, fill=True) self.ln(th * 1.5) startx = self.get_x() starty = self.get_y() self.line(startx, starty, startx+ 6 * col_width ,starty) self.line(startx + 6 * col_width + separationColWidth, starty, startx+pdf_w - 2*left ,starty) for i in range(2): self.cell(w=col_width, h=th*2, align='C', txt="", border=0) self.cell(w=col_width * (len(colheaders)-1), h=th*1.8, align='C', txt="Repetition", border=0) self.cell(w=separationColWidth, h=th*2, align='C', txt="", border=0) self.ln(th*1.5) for i in range(2): # Write Column Headers for head in colheaders: self.cell(w=col_width, h=th*1.8, align='C', txt=head, border=0) self.cell(w=separationColWidth, h=th*1.8, align='C', txt="", border=0) self.ln(th*2) starty = self.get_y() self.line(startx, starty, startx+ 6 * col_width ,starty) self.line(startx + 6 * col_width + separationColWidth, starty, startx+pdf_w - 2*left ,starty) # Write Content self.set_font('DejaVu', '', 10) num = 1 for rowheader in data[key]: if rowheader > 50: break rowcontent = data[key][rowheader] rowcontent_right = data[key][rowheader+50] header_print = str(rowheader) header_print_right = str(rowheader+50) if (num % 2) == 0: self.set_fill_color(200, 200, 200) else: self.set_fill_color(255, 255, 255) self.cell(w=col_width, h=th*1.4, align='C', txt=str(header_print), fill=True) for rowtext in rowcontent: self.cell(w=col_width, h=th*1.4, align='C', txt=str(rowtext), fill=True) self.cell(w=separationColWidth, h=th*1.4, align='C', txt="") # Empty cell, not filled #Right table column self.cell(w=col_width, h=th*1.4, align='C', txt=str(header_print_right), fill=True) for rowtext in rowcontent_right: self.cell(w=col_width, h=th*1.4, align='C', txt=str(rowtext), fill=True) self.ln(th*1.4) # Go to new line num += 1 startx = self.get_x() starty = self.get_y() self.line(startx, starty, startx+ 6 * col_width ,starty) self.line(startx + 6 * col_width + separationColWidth, starty, startx+pdf_w - 2*left ,starty) self.set_fill_color(255, 255, 255) if list(data.keys())[-1] != key: self.add_page() def shellGraph(self, img_L, img_R, payoff, figNumber): th = self.font_size graphicWidth = 120 unitWidth = graphicWidth / 7 graphicHeight = 60 startx = left + (pdf_w - 2 * left - graphicWidth)/2 starty = self.get_y() headery = starty shelly = starty + (1/6) * graphicHeight shellx_left = startx + unitWidth shellx_right = startx + 4 * unitWidth self.set_x(startx) #Draw a border around self.cell(w = graphicWidth, h= graphicHeight, border=1) # Left Header self.set_xy(shellx_left, headery ) self.cell(w= 2 * unitWidth, h= 0.6* text_height, align='C', txt="Left shell", border=0 ) # Right Header self.set_xy(shellx_right, headery ) self.cell(w= 2 * unitWidth, h= 0.6* text_height, align='C', txt="Right shell", border=0 ) # Left shell self.set_xy(shellx_left, shelly ) self.image(img_L, link='', type='', w= 2 * unitWidth) # Right shell self.set_xy(shellx_right, shelly ) self.image(img_R, link='', type='', w= 2 * unitWidth) # destructure payoff payoff_1 = "£" + '%.2f' %payoff[0] payoff_2 = "£" + '%.2f' %payoff[1] self.set_font('Helvetica', '', 10) slipy = self.get_y() + (1/20) * graphicHeight # Left slip self.set_xy( shellx_left, slipy) self.cell(w= 2 * unitWidth, h= 0.6* text_height, align='C', txt=payoff_1, border=1) # Right slip self.set_xy( shellx_right, slipy) self.cell(w= 2 * unitWidth, h= 0.6* text_height, align='C', txt=payoff_2, border=1) # Move to below picture self.set_y(starty + graphicHeight + 0.5 * th) self.set_x(startx) self.set_font('DejaVu', 'B', 12) self.cell(txt="Figure " + str(figNumber) + ".", align='L', border=0) self.ln() def cardGraph(self, payoff, figNumber): # payoff is a list with endpositions of the specific index graphicWidth = 120 graphicHeight = 120 cardWidth = 8 cardHeight = 10 rowHeight = 11 startx = left + (pdf_w - 2 * left - graphicWidth)/2 starty = self.get_y() + 0.5 * rowHeight cardx_left = startx + cardWidth + 2 self.set_x(startx) #Draw a border around self.cell(w = graphicWidth, h= graphicHeight, border=1) # Draw cards self.set_xy( cardx_left ,starty) self.set_font('Helvetica', '', 8) for idx, pay in enumerate(payoff): if idx > 0 and (idx % 10) == 0: self.set_xy( cardx_left , self.get_y() + rowHeight) cardText = shuffledPayoff.index(idx) self.cell( w= cardWidth, h= cardHeight, align='C', txt=str(cardText), border=1) self.set_x( self.get_x() + 2) # Move to below picture self.set_y(starty + graphicHeight) self.set_x(startx) self.set_font('DejaVu', 'B', 12) self.cell(txt="Figure " + str(figNumber) + ": Upturned cards", align='L', border=0) self.ln() self.ln() def drawShape(self, form, leftX = 0, topY = 0, elemSize = 0): #pdf.set_line_width(2) #pdf.set_draw_color(255) #pdf.set_fill_color(r=230, g=30, b=180) rightX = leftX + elemSize bottomY = topY + elemSize if form == "pentagon": coords = ((leftX + elemSize / 2, topY), (leftX, topY + (0.4) * elemSize ), (leftX + (1/4) * elemSize, bottomY), (leftX + (3/4) * elemSize, bottomY), (rightX, topY + (0.4) * elemSize)) self.polygon(coords, style="F") elif form == "triangle": coords = ((leftX + elemSize / 2, topY), (leftX, bottomY), (rightX, bottomY)) self.polygon(coords, style="F") elif form == "trapezoid": coords = ((leftX + elemSize / 4, topY + 0.1 * elemSize), (leftX, topY + 0.9 * elemSize), (rightX,topY + 0.9 * elemSize), (leftX + (3/4) * elemSize,topY + 0.1 * elemSize)) self.polygon(coords, style="F") elif form == "circle": self.circle(x=leftX, y=topY, r=elemSize, style="F") elif form == "square": self.rect(x=leftX, y=topY, w=elemSize, h=elemSize, style="F") def shapeGrid(self, data, figNumber): # data is a dictionary - get relevant data in correct order first # Order: Color, Shape, Number tableList = [ [item[1][0], item[1][1] ,item[1][2]] for item in data.items() ] self.set_font('DejaVu', '', 10) self.set_text_color(255,255,255) # Write table th = self.font_size numCols = 12 col_width = (pdf_w - 2 * left) / numCols # Column grid is square elemColumns = 10 # 10 shapes per row cellFactor = 0.7 # cellWidth = col_width * cellFactor numRows = int(len(tableList)/ elemColumns) + 1 if self.get_y() + numRows * col_width > 260: # Graphic extends over page self.add_page() # Define table grid rowY = [self.get_y() + i * col_width for i in range(numRows + 1)] colX = [self.get_x() + i * col_width for i in range(numCols)] # Define square size of element col = 1 # Start in first column row = 0 # Start in zeroth row for color, shape, number in tableList: # First fill rows, then columns leftX = colX[col] + (col_width - cellWidth) / 2 topY = rowY[row] + (col_width - cellWidth) / 2 h = color.lstrip('#') rgbColor = tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) self.set_fill_color(rgbColor[0], rgbColor[1], rgbColor[2]) self.drawShape(shape, leftX, topY, cellWidth) self.set_xy(colX[col], rowY[row]) self.cell(w=col_width, h= col_width, txt=str(number), align='C', fill=False, border=False) col += 1 if col == 11: col = 1 row += 1 #Draw border around startx = colX[1] endx = colX[-1] starty = rowY[0] endy = rowY[-1] self.set_xy(startx,starty) self.cell(w = endx - startx, h=endy-starty, border=True) self.set_xy(startx,endy + 0.5 * th ) self.set_font('DejaVu', 'B', 12) self.set_text_color(0,0,0) self.cell(txt="Figure " + str(figNumber) + ": Assignment of the number of winning cards to colored forms", align='L', border=0) self.set_fill_color(255, 255, 255) self.ln() pdf = PDF() #our pdf object # Define width pdf_w=210 #A4 page is 240mm wide left = 10 top = 30 enumerationIndent = 10 text_height=14 option_height = 60 figNum = 0 # Add Fonts import os cwd = os.getcwd() fonts = [ ('DejaVu', '', cwd + '/font/DejaVuSans.ttf'), ('DejaVu', 'B', cwd + '/font/DejaVuSans-Bold.ttf'), ('DejaVu', 'I', cwd + '/font/DejaVuSans-Oblique.ttf'), ('DejaVu', 'BI', cwd + '/font/DejaVuSans-BoldOblique.ttf'), ] for font in fonts: #print("font") #print(font[0]) #print(font[1]) #print(font[2]) #pdf.add_font(font[0], fname=font[2]) pdf.add_font(font[0], style= font[1], fname=font[2]) pdf.set_font('DejaVu', '', 14) pdf.add_page() pdf.titles("Verification.pdf") if verificationType == "binaryChoice": intro_text = [{'text':'This document allows you to '}, {'style':'U','text':'personally verify'}, {'text':' that your bonus was determined fairly, exactly as described during the experiment. '}, {'text':'Specifically, you can verify that the outcome of Option 1 (the risk) was determined fairly. \n'}] pdf.write_multicell_with_styles(left, intro_text) elif verificationType == "priceList": # Bonus files or multiple types intro_text = [{'text':'This document allows you to '}, {'style':'U','text':'personally verify'}, {'text':' that your bonus was determined fairly, exactly as described during the experiment. '}, {'text':'Specifically, you can verify the following points:\n'}] pdf.write_multicell_with_styles(left, intro_text) pdf.enumeration(enumerationIndent,"1.", 'Your bonus-relevant choice (i.e., the choice that determined your bonus) was selected fairly, because the set of colors was not manipulated:') pdf.subEnumeration(enumerationIndent, "Had you selected a different color, another choice could have been bonus-relevant and another safe amount could have been your bonus.") pdf.subEnumeration(enumerationIndent, "Because each safe amount belongs to exactly one color, each choice was equally likely to be bonus-relevant.") pdf.enumeration(enumerationIndent,"2.", "If your bonus was determined by the outcome of a risk, then the outcome was determined fairly, exactly as described during the experiment.") text = [{'style':'U','text':'Note:'}, {'text':' Because you downloaded this document at the beginning of the experiment, its content cannot depend on your behavior later in the experiment. That is, we―the experimenters―were committed to the content of this document before we knew what you would do. Had we given you a low bonus regardless of the color and/or the shell that you selected, this untruthfulness would become apparent now. This is the reason why this document allows you to verify our truthfulness.\n'},] pdf.write_multicell_with_styles(left, text) pdf.ln() pdf.subTitles("1. Proof that your bonus-relevant choice was selected fairly, exactly as described during the experiment") text = [ {'text': 'During the experiment, you selected one out of ' + str(max(typeMatching.keys()) + 1) + ' different colors. '}, {'text': 'Using the graphic on the next page, you can verify that the color you selected belongs to the safe amount in your bonus-relevant choice. '}, {'text': 'If you selected '}, {'coloredtext': str(typeMatching[0][0]), 'text': " " }, {'text':', for example, you can verify that the safe amount in your bonus-relevant choice is indeed ' }, {'text': "£" + '%.2f' %typeMatching[0][2] +". " }, {'text': 'Because each safe amount from the experiment belongs to exactly one color, each choice was equally likely to be bonus-relevant.'}, ] pdf.write_multicell_with_styles(left, text) pdf.ln() figNum += 1 pdf.colorGraphic(typeMatching, figNum) pdf.ln() pdf.add_page() pdf.subTitles("2. Proof that the risk was resolved fairly, exactly as described during the experiment") elif verificationType == "priceList_new": #Alternative price list without colored cards # Bonus files or multiple types intro_text = [{'text':'This document allows you to '}, {'style':'U','text':'personally verify'}, {'text':' that your bonus was determined fairly, exactly as described during the experiment. '}, {'text':'Specifically, you can verify that:\n\n'}] pdf.write_multicell_with_styles(left, intro_text) pdf.enumeration(enumerationIndent,"1.", 'The option pair that determined your bonus was selected fairly, because the set of envelopes was not manipulated:') pdf.subEnumeration(enumerationIndent, "Had you selected a different envelope, another option pair would have determined your bonus.") pdf.subEnumeration(enumerationIndent, "Because each option pair is contained in exactly one envelope, your instruction for each option pair was equally likely to determine your bonus.") pdf.enumeration(enumerationIndent,"2.", "If your bonus was determined by the outcome of a risk, then the outcome was determined fairly, exactly as described during the experiment.") text = [{'style':'U','text':'Note:'}, {'text':' Because you downloaded this document before selecting an envelope, before giving instructions, and before lifting a shell, its content cannot depend on your envelope, on your instructions, or on the shell that you select. Had we—the experimenters—given you a low bonus regardless of the envelope and/or the shell that you selected, this untruthfulness would become apparent now. This is the reason why this document allows you to verify our truthfulness.\n'},] pdf.write_multicell_with_styles(left, text) pdf.ln() pdf.subTitles("1. Proof that the option pair that determined your bonus was selected fairly, exactly as described during the experiment") figNum += 1 envelopeNumbers = list(typeMatching.keys()) envelopeAmounts = [val[0] for val in typeMatching.values()] envelopeRows = [val[1] for val in typeMatching.values()] text = [ {'text': 'During the experiment, you selected one out of ' + str(max(envelopeRows) + 1) + ' different envelopes. '}, {'text': 'Using Figure ' + str(figNum) +', you can verify that the option pair in your selected envelope belongs to the one that determined your bonus. '}, {'text': 'If you selected Envelope ' + str(envelopeNumbers[0])}, {'text':', for example, you can verify that the option pair in your envelope indeed consists of the risk and the safe amount ' }, {'text': "£" + '%.2f' %envelopeAmounts[0] +". " }, {'text': 'Because each option pair from the experiment is contained in exactly one envelope, your instruction for each option pair was equally likely to determine your bonus.'}, ] pdf.write_multicell_with_styles(left, text) pdf.ln() pdf.envelopes(typeMatching, shuffledPayoff, figNum) pdf.ln() #pdf.add_page() pdf.subTitles("2. Proof that the risk was resolved fairly, exactly as described during the experiment") elif verificationType == "probMatching": intro_text = [{'text':'This document allows you to '}, {'style':'U','text':'personally verify'}, {'text':' that your bonus was determined fairly, exactly as described during the experiment. '}, {'text':'Specifically, you can verify the following points:\n'}] pdf.write_multicell_with_styles(left, intro_text) pdf.enumeration(enumerationIndent,"1.", 'Your bonus-relevant choice (i.e., the choice that determined your bonus) was selected fairly, because the set of colored forms was not manipulated:') pdf.subEnumeration(enumerationIndent, "Had you selected a different colored form, another choice could have been bonus-relevant and a risk with a different number of winning cards could have been your bonus.") pdf.subEnumeration(enumerationIndent, "Because each number of winning cards belongs to exactly one colored form, each choice was equally likely to be bonus-relevant.") pdf.enumeration(enumerationIndent,"2.", "If your bonus was determined by the outcome of a risk, then the outcome was determined fairly, exactly as described during the experiment.") text = [{'style':'U','text':'Note:'}, {'text':' Because you downloaded this document at the beginning of the experiment, its content cannot depend on your behavior later in the experiment. That is, we―the experimenters―were committed to the content of this document before we knew what you would do. Had we given you a low bonus regardless of the colored form and/or the card that you selected, this untruthfulness would become apparent now. This is the reason why this document allows you to verify our truthfulness.\n'},] pdf.write_multicell_with_styles(left, text) pdf.ln() pdf.subTitles("1. Proof that your bonus-relevant choice was selected fairly, exactly as described during the experiment") text = [ {'text': 'During the experiment, you selected one out of ' + str(max(typeMatching.keys()) + 1) + ' different colored forms. '}, {'text': 'Using the graphic on the next page, you can verify that the colored form you selected belongs to the number of winning cards of the risk in your bonus-relevant choice. '}, {'text': 'If you selected '}, {'coloredShape': typeMatching[0], 'text': " "}, {'text':', for example, you can verify that the risk in your bonus-relevant choice indeed has ' }, {'text': str(typeMatching[0][2]) + " winning cards. " }, {'text': 'Because each number of winning cards (0 to 100) belongs to exactly one colored shape, each choice was equally likely to be bonus-relevant.'}, ] pdf.write_multicell_with_styles(left, text) pdf.ln() figNum += 1 pdf.shapeGrid(typeMatching, figNum) pdf.ln() pdf.add_page() pdf.subTitles("2. Proof that the risk was resolved fairly, exactly as described during the experiment") if verificationType in ["binaryChoice", "priceList", "priceList_new"]: figNum += 1 shell_L = "_static/img/shell.png" shell_R = "_static/img/shell.png" if verificationType == "binaryChoice": upper_text = [ {'text': "If you chose Option 1 (the risk), you had to select either the left or the right shell to determine your bonus. "}, {'text': "You then received the outcome that was shown on the paper slip under the shell you selected. "}, {'text': "The graphic below shows the lifted shells and corresponds to the one you saw on the screen after determining your bonus.\n"}, ] elif verificationType == "priceList_new": upper_text = [ {'text': "If you instructed us to give you the risk for the option pair in your envelope, you had to lift either the left or the right shell to determine your bonus. "}, {'text': "You then received the outcome that was shown on the paper slip under the shell you lifted. "}, {'text': "Figure " + str(figNum) + " shows the lifted shells and is the same as the one you saw on the screen after determining your bonus.\n"}, ] else: upper_text = [ {'text': "If you chose the risk in your bonus-relevant choice, you had to select either the left or the right shell to determine your bonus. "}, {'text': "You then received the outcome that was shown on the paper slip under the shell you selected. "}, {'text': "The graphic below shows the lifted shells and corresponds to the one you saw on the screen after determining your bonus.\n"}, ] lower_text = [ {'text': "Because the left shell shows outcome £" + '%.2f' %shuffledPayoff[0]}, {'text': " and the right shell outcome £"+ '%.2f' %shuffledPayoff[1]}, {'text': ", either outcome was equally likely. \n"}, ] #Write text pdf.write_multicell_with_styles(left, upper_text) pdf.ln() pdf.shellGraph(shell_L, shell_R, shuffledPayoff, figNum) # Get from random order! pdf.ln() pdf.write_multicell_with_styles(left, lower_text) if verificationType == "binaryChoice": text = [{'style':'U','text':'Note:'}, {'text':' Because you downloaded this document at the beginning of the experiment, its content cannot depend on your behavior later in the experiment. That is, we―the experimenters―were committed to the content of this document before we knew what you would do. In particular, we could not know whether you would select the left or the right shell when creating the picture above. Had we given you the low outcome regardless of which shell you selected, this untruthfulness would become apparent now. Therefore, this document allows you to verify that your bonus was determined fairly, exactly as described during the experiment.\n'},] pdf.write_multicell_with_styles(left, text) elif verificationType in ["probMatching"]: upper_text = [ {'text': "If you chose the risk in your bonus-relevant choice, you had to click one card to determine your bonus. "}, {'text': "The card was then turned around. If the number written on the card was equal to the number of winning cards or smaller, you received the higher outcome. Otherwise, you received the lower outcome. "}, {'text': "The graphic below shows all cards turned around and corresponds to the one you saw on the screen after determining your bonus.\n"}, ] lower_text = [ {'text': "Because each number from 1 to 100 is written on exactly one card, each number was equally likely. \n"}, ] #Write text pdf.write_multicell_with_styles(left, upper_text) pdf.ln() figNum += 1 pdf.cardGraph(shuffledPayoff, figNum) pdf.write_multicell_with_styles(left, lower_text) ''' intro_text = [{'text':'This document allows you to '}, {'style':'U','text':'personally verify'}, {'text':' that your bonus was determined fairly, exactly as described during the experiment.\n'}, {'text':'\n'}, {'text':'Specifically, you can verify the following points:\n'}] pdf.enumeration(enumerationIndent,"1.", "Your bonus task was selected fairly, because the set of bonus files that you chose from was not manipulated:") pdf.subEnumeration(enumerationIndent, "Had you chosen a different bonus file, a different task would have been your bonus task.") pdf.subEnumeration(enumerationIndent, "Each task was equally likely to be your bonus task, because each task was contained in exactly one bonus file.") pdf.enumeration(enumerationIndent,"2.", "The safe amounts of money in the bonus files vary fairly.") pdf.enumeration(enumerationIndent,"3.", "If your bonus was determined by the outcome of a risk, then the outcome was determined fairly, exactly as described during the experiment.") text = [{'style':'U','text':'Note:'}, {'text':' Because you downloaded this document at the beginning of the experiment, its content cannot depend on your behavior later in the experiment. That is, we―the experimenters―were committed to the content of this document before we knew what you would do. This is the reason why this document allows you to verify our truthfulness.\n'},] pdf.write_multicell_with_styles(left, text) pdf.add_page() pdf.subTitles("1. Proof that your bonus task was selected fairly, as explained during the experiment") text = [ {'text':'Early in the experiment, you chose a numbered bonus file. Now that you have the password to your bonus file (it is "'}, {'text':password_bonusFile}, {'text':'"), you can verify that this bonus file indeed contains the task that was relevant for your bonus.\n'}, {'text':'Table 1 lists the tasks contained in all bonus files that you could have chosen. You can verify that the task described in your bonus file is the same as the task described in Table 1. For example, if you chose BonusFile'}, {'text': str(list(bonusFileDict.keys())[-1])}, {'text':'.pdf, you can verify that the task described therein is indeed the one described in the last row of Table 1.\n\n' }, {'text':'Recall that you downloaded this document at the beginning of the experiment, before choosing your bonus file. At that time, we could not know which bonus file you would choose and download. If your bonus task would be different to the task described in Table 1, this manipulation would become apparent now.\n'}, {'text':'Moreover, note that each task that you completed during the experiment was contained in exactly one bonus file. Therefore, each of the three tasks was equally likely to be your bonus task.\n \n'}, ] pdf.write_multicell_with_styles(left, text) pdf.table1(bonusFileDict) pdf.ln() pdf.ln() pdf.subTitles("2. Proof that the safe amounts of money vary fairly") text = [ {'text':'The column "Option 2" in Table 1 allows you to verify that the safe amounts of money vary fairly. That is, we did not select many or especially low amounts that could have resulted in a lower bonus for you.\n'}, ] pdf.write_multicell_with_styles(left, text) pdf.add_page() pdf.subTitles("3. Proof that all bonus-relevant risks were resolved fairly according to the stated probabilities") text = [ {'text': "This section explains how you can verify that the outcome of your bonus-relevant risk was determined fairly. "}, {'text': "Remember that you downloaded this file before resolving any risk, i.e., before we knew which shell ('L' or 'R') or which card you would choose.\n \n"}, {'text': "For each task, we explain on a separate page how the risk was resolved. "}, {'text': "You can directly go to the page that is shown next to your bonus file in Table 1."}, ] pdf.write_multicell_with_styles(left, text) for key, value in bonusFileDict.items(): pdf.add_page() ## add Page in the beginning to have correct number of pages taskType = value[0] resolutionType = value[1] risk = value[2] x1 = risk[0][0] p1 = risk[0][1] x0 = risk[1][0] p0 = risk[1][1] shuffledPayoff = shuffledDict[key][2] if resolutionType == 'shell': shell_L = "_static/img/trapezoid_L.png" shell_R = "_static/img/trapezoid_R.png" title = "Risk resolution using shells – Evaluation" upper_text = [ {'text': "To resolve the risk using the shells, you had to click on either the left ('L') or right ('R') shell. "}, {'text': "Before the experiment, we assigned a monetary outcome to the left shell ('L') and another monetary outcome to the right shell ('R'). "}, {'text': "You received the outcome that was assigned to the shell you clicked. "}, {'text': "The graphic below shows you the lifted shells. "}, {'text': "With this, you can verify that the same graphic was indeed shown on your screen when you resolved the risk. \n"}, ] lower_text = [ {'text': "As shell 'L' shows the outcome £" + '%.2f' %shuffledPayoff[0]}, {'text': ", and shell 'R' shows the outcome £"+ '%.2f' %shuffledPayoff[1]}, {'text': ", each outcome indeed had a probability of 50%. "}, {'text': "Because we could not know which shell you would click at the time we prepared this document, we could not manipulate the outcome.\n"}, ] #Write title pdf.subTitles(title) pdf.write_multicell_with_styles(left, upper_text) pdf.shellGraph(shell_L, shell_R, shuffledPayoff) # Get from random order! pdf.write_multicell_with_styles(left, lower_text) elif resolutionType == 'cards': if taskType == "certaintyEquivalent": title = "Risk resolution using cards – Evaluation" elif taskType == "probabilityEquivalent": title = "Risk resolution using cards – Probability evaluation" upper_text = [ {'text': "To resolve the risk using the cards, you had to click on a card from a well-shuffled card deck. "}, #{'text': "The cards were numbered from 1 to 100. "}, {'text': "Before the experiment, we assigned a monetary outcome to each card. "}, {'text': "You received the outcome that was assigned to the card you clicked. "}, {'text': "The graphic below shows you all cards face up. "}, {'text': "With this, you can verify that the same graphic was indeed shown on your screen when you resolved the risk. \n"}, ] lower_text = [ {'text': "As there are " + str(int(p1*100)) + " cards that show the outcome £" + '%.2f' %x1}, {'text': ", and " + str(int(p0*100)) + " cards that show the outcome £" + '%.2f' %x0}, {'text': ", the probability of obtaining each outcome was indeed as stated. "}, {'text': "Because we could not know which card you would click at the time we prepared this document, we could not manipulate the outcome.\n"}, ] #Write title pdf.subTitles(title) pdf.write_multicell_with_styles(left, upper_text) pdf.cardGraph(shuffledPayoff) pdf.write_multicell_with_styles(left, lower_text) ''' #pdf.output(inputfile, 'F') pdf.output(inputfile) def createVerificationPDF( studyName, shuffledPayoff, password, id, typeMatching = [], ): #bonusFileDict, #shuffledDict, #password_bonusFile, # Create Folder if not existing folder = "_static/bonusFiles/" + str(id) + "/" folder_no_pwd = "_static/bonusFiles/" + str(id) + "/no_pwd/" Path(folder).mkdir(parents=True, exist_ok=True) Path(folder_no_pwd).mkdir(parents=True, exist_ok=True) inputfile = folder_no_pwd + "Verification.pdf" outputfile = folder + "Verification.pdf" verificationPDF( studyName, shuffledPayoff, inputfile, typeMatching, #bonusFileDict, #shuffledDict, #password_bonusFile ) protectPDF(inputfile, password, outputfile) # Testing ''' typeMatching = {5964: [1.4, 14], 3283: [0.4, 4], 9920: [0.9, 9], 7350: [1.3, 13], 7860: [0.6, 6], 4495: [1.2, 12], 6211: [1.8, 18], 8098: [1.5, 15], 7116: [2.0, 20], 8428: [0.0, 0], 6857: [1.7, 17], 2487: [1.1, 11], 2307: [1.0, 10], 4241: [1.6, 16], 4444: [0.7, 7], 2346: [0.8, 8], 9913: [0.3, 3], 5850: [1.9, 19], 7753: [0.1, 1], 6094: [0.5, 5], 4975: [0.2, 2]} createVerificationPDF( "priceList_new", [2,0], "Loewe50", 1001, typeMatching ) typeMatching = {0: ['#1f77b4', 1, 0.1], 1: ['#aec7e8', 6, 0.6], 2: ['#ff7f0e', 14, 1.4], 3: ['#ffbb78', 19, 1.9], 4: ['#2ca02c', 0, 0.0], 5: ['#98df8a', 13, 1.3], 6: ['#d62728', 3, 0.3], 7: ['#ff9896', 15, 1.5], 8: ['#9467bd', 7, 0.7], 9: ['#c5b0d5', 20, 2.0], 10: ['#8c564b', 8, 0.8], 11: ['#c49c94', 4, 0.4], 12: ['#e377c2', 11, 1.1], 13: ['#f7b6d2', 17, 1.7], 14: ['#7f7f7f', 16, 1.6], 15: ['#c7c7c7', 2, 0.2], 16: ['#bcbd22', 18, 1.8], 17: ['#dbdb8d', 10, 1.0], 18: ['#17becf', 5, 0.5], 19: ['#9edae5', 9, 0.9], 20: ['#ff0029', 12, 1.2]} createVerificationPDF( "priceList", [2,0], "Loewe50", 1001, typeMatching ) ''' '''' shapes = ["square", "circle", "triangle", "pentagon", "trapezoid"] colors = ['#1f77b4', "#aec7e8", '#ff7f0e'] numbers = [random.randint(0,100) for i in range(len(shapes) * len(colors))] tmp = [[shape, col] for shape in shapes for col in colors] typeMatching = {} for idx, elem in enumerate(tmp): typeMatching[idx] = [elem[1], elem[0], numbers[idx]] pay = [59, 48, 95, 58, 56, 12, 82, 99, 28, 13, 26, 61, 68, 17, 1, 27, 85, 38, 94, 5, 54, 71, 89, 62, 92, 4, 18, 67, 53, 31, 91, 73, 57, 8, 98, 9, 77, 81, 66, 86, 36, 42, 33, 37, 87, 14, 43, 39, 16, 15, 96, 83, 40, 88, 0, 63, 21, 46, 69, 24, 6, 47, 41, 70, 72, 52, 29, 80, 51, 84, 30, 65, 60, 78, 32, 74, 35, 76, 50, 3, 25, 90, 97, 19, 55, 45, 34, 49, 64, 44, 75, 20, 10, 22, 2, 93, 79, 11, 7, 23] createVerificationPDF( "probMatching", pay, "Loewe50", 1001, typeMatching ) '''