<commit_before># vim: set expandtab sw=4 ts=4:
# disable pylint message about unused variable 'fig'
# pylint: disable=unused-variable
'''
Generates a trend (graph) from the buildtimes in buildtimes.xml

Copyright (C) 2014-2015 <NAME> <<EMAIL>>

This file is part of buildtimetrend/python-lib
<https://github.com/buildtimetrend/python-lib/>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''

from lxml import etree
import matplotlib
from buildtimetrend.tools import get_logger
# Force matplotlib to not use any Xwindow backend.
matplotlib.use('Agg')
from matplotlib import pyplot as plt
from buildtimetrend.tools import check_file


class Trend(object):
    '''
    Trend class, generates a chart from gathered buildtime data
    '''
    def __init__(self):
        self.stages = {}
        self.builds = []

    def gather_data(self, result_file):
        '''
        Get buildtime data from an xml file

        Parameters
        - result_file : xml file containing the buildtime data
        '''
        # load buildtimes file
        if check_file(result_file):
            root_xml = etree.parse(result_file).getroot()
        else:
            return False

        index = 0
        # print content of buildtimes file
        for build_xml in root_xml:
            build_id = build_xml.get('build')
            job_id = build_xml.get('job')

            if job_id is None and build_id is None:
                build_name = "#%d" % (index + 1)
            elif job_id is not None:
                build_name = job_id
            else:
                build_name = build_id

            self.builds.append(build_name)

            # add 0 to each existing stage, to make sure that
            # the indexes of each value
            # are correct, even if a stage does not exist in a build
            # if a stage exists, the zero will be replaced by its duration
            for stage in self.stages:
                self.stages[stage].append(0)

            # add duration of each stage to stages list
            for build_child in build_xml:
                if build_child.tag == 'stages':
                    stage_count = len(build_child)
                    self.parse_xml_stages(build_child, index)
            get_logger().info("Build ID : %s, Job : %s, stages : %d",<commit_msg>display build IDs in loglevel debug<commit_after># vim: set expandtab sw=4 ts=4:
# disable pylint message about unused variable 'fig'
# pylint: disable=unused-variable
'''
Generates a trend (graph) from the buildtimes in buildtimes.xml

Copyright (C) 2014-2015 <NAME> <<EMAIL>>

This file is part of buildtimetrend/python-lib
<https://github.com/buildtimetrend/python-lib/>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''

from lxml import etree
import matplotlib
from buildtimetrend.tools import get_logger
# Force matplotlib to not use any Xwindow backend.
matplotlib.use('Agg')
from matplotlib import pyplot as plt
from buildtimetrend.tools import check_file


class Trend(object):
    '''
    Trend class, generates a chart from gathered buildtime data
    '''
    def __init__(self):
        self.stages = {}
        self.builds = []

    def gather_data(self, result_file):
        '''
        Get buildtime data from an xml file

        Parameters
        - result_file : xml file containing the buildtime data
        '''
        # load buildtimes file
        if check_file(result_file):
            root_xml = etree.parse(result_file).getroot()
        else:
            return False

        index = 0
        # print content of buildtimes file
        for build_xml in root_xml:
            build_id = build_xml.get('build')
            job_id = build_xml.get('job')

            if job_id is None and build_id is None:
                build_name = "#%d" % (index + 1)
            elif job_id is not None:
                build_name = job_id
            else:
                build_name = build_id

            self.builds.append(build_name)

            # add 0 to each existing stage, to make sure that
            # the indexes of each value
            # are correct, even if a stage does not exist in a build
            # if a stage exists, the zero will be replaced by its duration
            for stage in self.stages:
                self.stages[stage].append(0)

            # add duration of each stage to stages list
            for build_child in build_xml:
                if build_child.tag == 'stages':
                    stage_count = len(build_child)
                    self.parse_xml_stages(build_child, index)
            get_logger().debug("Build ID : %s, Job : %s, stages : %d",
{'fraction_non_alphanumeric': 0.06888154461645503, 'fraction_numerical': 0.0052182988345799266, 'mean_word_length': 2.394332939787485, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 22}, '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': '2450567', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1524, 'n_words': 634}