<commit_before>from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter, landscape
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.utils import ImageReader
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table

class Reporter(object):
    fonts = {
        'Cicle': 'fonts/cicle.ttf',
        'Cicle-Strong': 'fonts/cicle_strong.ttf',

    }
    style_additions =[
        ParagraphStyle(name='PageTitle', fontName='Cicle-Strong', fontSize=25, alignment=TA_JUSTIFY),
        ParagraphStyle(name='PageByline', fontName='Cicle', fontSize=20, alignment=TA_JUSTIFY),
        ParagraphStyle(name='Heading', fontName='Cicle-Strong', fontSize=15, alignment=TA_JUSTIFY),
        ParagraphStyle(name='TableHeading', fontName='Cicle-Strong', fontSize=6, alignment=TA_JUSTIFY),
        ParagraphStyle(name='Text', fontName='Cicle', fontSize=12, alignment=TA_JUSTIFY),
        ParagraphStyle(name='Small', fontName='Cicle', fontSize=6, alignment=TA_JUSTIFY),
    ]
    elements = []

    def __init__(self):
        for name, path in self.fonts.iteritems():
            pdfmetrics.registerFont(TTFont(name, path))
        
        self.styles=getSampleStyleSheet()
        for style in self.style_additions:
            self.styles.add(style)
        
        self.doc = SimpleDocTemplate(
            "report.pdf",
            pagesize=landscape(letter),
            rightMargin=52,
            leftMargin=52,
            topMargin=25,
            bottomMargin=25
        )

    def draw_footer(self, canvas, doc):
        canvas.setTitle('Autoload Report')
        canvas.drawImage(ImageReader('media/logo.png'), 675, 15, 100, 13)

    def gen_heading(self):
        elements = []
        elements.append(Paragraph('Results - %s' % self.test['title'], self.styles["PageTitle"]))
        elements.append(Spacer(1, 10))
        url = self.test['server']
        if self.test.has_key('port'):
            url += ':%s' % self.test['port']
        url += self.test['uri']
        url = url.replace("'", '').replace('"', '')
        elements.append(Paragraph(url, self.styles["PageByline"]))
        elements.append(Spacer(1, 30))
        return elements
    
    def gen_params(self):
        elements = []
        elements.append(Paragraph('Test Parameters', self.styles["Heading"]))
        elements.append(Spacer(1, 10))
   
        params = '<br />'.join(["%s: %s" % (key, value) for key, value in self.test.iteritems()])
        elements.append(Paragraph(params, self.styles["Small"]))
        elements.append(Spacer(1, 20))
        return elements

    def gen_graphs(self):
        elements = []
        elements.append(self.graphs.reply_graph)
        elements.append(self.graphs.time_graph)
        elements.append(self.graphs.error_graph)
        return elements
        
    def gen_results_table(self):
        elements = []
        elements.append(Paragraph('Raw HTTPerf Results', self.styles["Heading"]))
        elements.append(Spacer(1, 10))


        data = [[
            Paragraph('Request Rate (req/s)', self.styles["TableHeading"]), 
            Paragraph('Reply Time (ms)', self.styles["TableHeading"]), 
            Paragraph('Errors', self.styles["TableHeading"]),
            Paragraph('Net IO (KB/s)', self.styles["TableHeading"]),
            Paragraph('Reply Rate Avg (req/s)', self.styles["TableHeading"]),
        ]]

        rates = self.results.keys()
        rates.sort()
        for rate in rates:
            data.append([
                Paragraph(str(rate), self.styles["TableHeading"]), 
                Paragraph(str(self.results[rate]['rep_time']), self.styles["Small"]), 
                Paragraph(str(self.results[rate]['errors']), self.styles["Small"]), 
                Paragraph(str(self.results[rate]['net_io']), self.styles["Small"]), 
                Paragraph(str(self.results[rate]['rep_rate_avg']), self.styles["Small"]), 
            ])

        elements.append(Table(data))
        elements.append(Spacer(1, 20))
        return elements
   
    def gen_conclusion(self):
        elements = []
        elements.append(Paragraph('Conclusion', self.styles["Heading"]))
        elements.append(Spacer(1, 10))

        rates = self.results.keys()
        rates.sort()

        elements.append(Paragraph('Performance starts to degrade at roughly %s requests per second. At %s requests per second the service managed to reply at %s requests per second, reply time is %s percent longer and error rate is %s time(s) more than at idle.' % (rates[-2], rates[-1], int(self.results[rates[-1]]['rep_rate_avg']), int(self.results[rates[-1]]['rep_time']/self.results[rates[0]]['rep_time'] * 100), int(self.results[rates[-1]]['errors'])), self.styles["Text"]))
        elements.append(Spacer(1, 30))
        return elements

    def build_page(self, test, graphs, results):
        self.test = test
        self.graphs = graphs
        self.results = results

        self.layout = [
            ['', ''],<commit_msg>determine breaking point better<commit_after>from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter, landscape
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.utils import ImageReader
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table

class Reporter(object):
    fonts = {
        'Cicle': 'fonts/cicle.ttf',
        'Cicle-Strong': 'fonts/cicle_strong.ttf',

    }
    style_additions =[
        ParagraphStyle(name='PageTitle', fontName='Cicle-Strong', fontSize=25, alignment=TA_JUSTIFY),
        ParagraphStyle(name='PageByline', fontName='Cicle', fontSize=20, alignment=TA_JUSTIFY),
        ParagraphStyle(name='Heading', fontName='Cicle-Strong', fontSize=15, alignment=TA_JUSTIFY),
        ParagraphStyle(name='TableHeading', fontName='Cicle-Strong', fontSize=6, alignment=TA_JUSTIFY),
        ParagraphStyle(name='Text', fontName='Cicle', fontSize=12, alignment=TA_JUSTIFY),
        ParagraphStyle(name='Small', fontName='Cicle', fontSize=6, alignment=TA_JUSTIFY),
    ]
    elements = []

    def __init__(self):
        for name, path in self.fonts.iteritems():
            pdfmetrics.registerFont(TTFont(name, path))
        
        self.styles=getSampleStyleSheet()
        for style in self.style_additions:
            self.styles.add(style)
        
        self.doc = SimpleDocTemplate(
            "report.pdf",
            pagesize=landscape(letter),
            rightMargin=52,
            leftMargin=52,
            topMargin=25,
            bottomMargin=25
        )

    def draw_footer(self, canvas, doc):
        canvas.setTitle('Autoload Report')
        canvas.drawImage(ImageReader('media/logo.png'), 675, 15, 100, 13)

    def gen_heading(self):
        elements = []
        elements.append(Paragraph('Results - %s' % self.test['title'], self.styles["PageTitle"]))
        elements.append(Spacer(1, 10))
        url = self.test['server']
        if self.test.has_key('port'):
            url += ':%s' % self.test['port']
        url += self.test['uri']
        url = url.replace("'", '').replace('"', '')
        elements.append(Paragraph(url, self.styles["PageByline"]))
        elements.append(Spacer(1, 30))
        return elements
    
    def gen_params(self):
        elements = []
        elements.append(Paragraph('Test Parameters', self.styles["Heading"]))
        elements.append(Spacer(1, 10))
   
        params = '<br />'.join(["%s: %s" % (key, value) for key, value in self.test.iteritems()])
        elements.append(Paragraph(params, self.styles["Small"]))
        elements.append(Spacer(1, 20))
        return elements

    def gen_graphs(self):
        elements = []
        elements.append(self.graphs.reply_graph)
        elements.append(self.graphs.time_graph)
        elements.append(self.graphs.error_graph)
        return elements
        
    def gen_results_table(self):
        elements = []
        elements.append(Paragraph('Raw HTTPerf Results', self.styles["Heading"]))
        elements.append(Spacer(1, 10))


        data = [[
            Paragraph('Request Rate (req/s)', self.styles["TableHeading"]), 
            Paragraph('Reply Time (ms)', self.styles["TableHeading"]), 
            Paragraph('Errors', self.styles["TableHeading"]),
            Paragraph('Net IO (KB/s)', self.styles["TableHeading"]),
            Paragraph('Reply Rate Avg (req/s)', self.styles["TableHeading"]),
        ]]

        rates = self.results.keys()
        rates.sort()
        for rate in rates:
            data.append([
                Paragraph(str(rate), self.styles["TableHeading"]), 
                Paragraph(str(self.results[rate]['rep_time']), self.styles["Small"]), 
                Paragraph(str(self.results[rate]['errors']), self.styles["Small"]), 
                Paragraph(str(self.results[rate]['net_io']), self.styles["Small"]), 
                Paragraph(str(self.results[rate]['rep_rate_avg']), self.styles["Small"]), 
            ])

        elements.append(Table(data))
        elements.append(Spacer(1, 20))
        return elements
   
    def gen_conclusion(self):
        elements = []
        elements.append(Paragraph('Conclusion', self.styles["Heading"]))
        elements.append(Spacer(1, 10))

        rates = self.results.keys()
        rates.sort()

        i = 0
        for rate in rates[1:]:
            if self.results[rate]['rep_time'] > self.results[rates[0]]['rep_time'] * 100:
                breaking_point_rate = rate
                breaking_point_index = i
                break
            i += 1

        elements.append(Paragraph('Performance starts to degrade at roughly %s requests per second. At %s requests per second the service managed to reply at %s requests per second, reply time is %s percent longer and error rate is %s time(s) more than at idle.' % (breaking_point_rate, breaking_point_rate, int(self.results[rates[breaking_point_index]]['rep_rate_avg']), int(self.results[breaking_point_index]['rep_time']/self.results[rates[0]]['rep_time'] * 100), int(self.results[rates[breaking_point_index]]['errors'])), self.styles["Text"]))
        elements.append(Spacer(1, 30))
        return elements

    def build_page(self, test, graphs, results):
        self.test = test
        self.graphs = graphs
        self.results = results

        self.layout = [
            ['', ''],
{'fraction_non_alphanumeric': 0.14176281445053907, 'fraction_numerical': 0.011726877246075278, 'mean_word_length': 2.830134009416878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5482733', 'n_tokens_mistral': 3255, 'n_tokens_neox': 3066, 'n_words': 592}