<commit_before># coding=utf-8
#
# Copyright 2013 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#from datetime import datetime
from django.utils.datetime_safe import datetime


class Certificates(object):
    FIELDS = ['accreditation', 'name','capacity','scheme','country',
              'technology','output','period','certs',
              'start_no','finish_no','factor','issue_dt',
              'status','status_dt','current_holder','reg_no']

    def __init__(self, node):
        """ Extract information from the supplied XML node.
        """

        mapping = [
            ['textbox4', 'accreditation'],
            ['textbox13', 'name'],
            ['textbox5', 'scheme'],
            ['textbox19', 'capacity', 0],
            ['textbox12', 'country'],
            ['textbox15', 'technology'],
            ['textbox31', 'output'],
            ['textbox18', 'period'],
            ['textbox21', 'certs', 0],
            ['textbox24', 'start_no'],
            ['textbox27', 'finish_no'],
            ['textbox37', 'factor', 0],
            ['textbox30', 'issue_dt'],
            ['textbox33', 'status'],
            ['textbox36', 'status_dt'],
            ['textbox39', 'current_holder'],
            ['textbox45', 'reg_no']
        ]

        for m in mapping:
            self.set_attr_from_xml(node, m)

        self.factor = float(self.factor)
        self.certs = int(self.certs) or 0
        self.capacity = float(self.capacity) or 0
        self.issue_dt = datetime.strptime(self.issue_dt, '%Y-%m-%dT00:00:00')
        self.status_dt = datetime.strptime(self.status_dt, '%Y-%m-%dT00:00:00')

        if self.period.startswith("01"):
            dt = datetime.strptime(self.period[:10], '%d/%m/%Y')
            self.period = dt.strftime("%b-%Y")

    def set_attr_from_xml(self, node, mapping):
        val = node.get(mapping[0], None)
        if val is not None and val.isdigit():
            val = int(val)
        if val is None and len(mapping) == 3:
            val = mapping[2]
        setattr(self, mapping[1], val)

    def as_string(self):
        s = '\n'
        for f in self.FIELDS:
            s += "    %-30s: %s\n" % (f.capitalize(), self[f])
        return s

    def as_dict(self):
        return {f: getattr(self, f) for f in self.FIELDS}

    def as_list(self):
        return [getattr(self, f) for f in self.FIELDS]

    def output_summary(self):
        perc = (float(self['certs']) / self['capacity']) * 100
        return "%s: %s   %s vs %s => %.02f%%" % (self['period'], self['name'], self['certs'],
                                                 self['capacity'], perc)
<commit_msg>Fix date formats for some certificates Correct for the change of attributes made a while back<commit_after># coding=utf-8
#
# Copyright 2013 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#from datetime import datetime
from django.utils.datetime_safe import datetime


class Certificates(object):
    FIELDS = ['accreditation', 'name','capacity','scheme','country',
              'technology','output','period','certs',
              'start_no','finish_no','factor','issue_dt',
              'status','status_dt','current_holder','reg_no']

    def __init__(self, node):
        """ Extract information from the supplied XML node.
        """

        mapping = [
            ['textbox4', 'accreditation'],
            ['textbox13', 'name'],
            ['textbox5', 'scheme'],
            ['textbox19', 'capacity', 0],
            ['textbox12', 'country'],
            ['textbox15', 'technology'],
            ['textbox31', 'output'],
            ['textbox18', 'period'],
            ['textbox21', 'certs', 0],
            ['textbox24', 'start_no'],
            ['textbox27', 'finish_no'],
            ['textbox37', 'factor', 0],
            ['textbox30', 'issue_dt'],
            ['textbox33', 'status'],
            ['textbox36', 'status_dt'],
            ['textbox39', 'current_holder'],
            ['textbox45', 'reg_no']
        ]

        for m in mapping:
            self.set_attr_from_xml(node, m)

        self.factor = float(self.factor)
        self.certs = int(self.certs) or 0
        self.capacity = float(self.capacity) or 0
        self.issue_dt = datetime.strptime(self.issue_dt, '%Y-%m-%dT%H:%M:00')
        self.status_dt = datetime.strptime(self.status_dt, '%Y-%m-%dT%H:%M:00')

        if self.period.startswith("01"):
            dt = datetime.strptime(self.period[:10], '%d/%m/%Y')
            self.period = dt.strftime("%b-%Y")

    def set_attr_from_xml(self, node, mapping):
        val = node.get(mapping[0], None)
        if val is not None and val.isdigit():
            val = int(val)
        if val is None and len(mapping) == 3:
            val = mapping[2]
        setattr(self, mapping[1], val)

    def as_string(self):
        s = '\n'
        for f in self.FIELDS:
            s += "    %-30s: %s\n" % (f.capitalize(), getattr(self, f))
        return s

    def as_dict(self):
        return {f: getattr(self, f) for f in self.FIELDS}

    def as_list(self):
        return [getattr(self, f) for f in self.FIELDS]

    def output_summary(self):
        perc = (float(self['certs']) / self['capacity']) * 100
        return "%s: %s   %s vs %s => %.02f%%" % (self['period'], self['name'], self['certs'],
                                                 self['capacity'], perc)

{'fraction_non_alphanumeric': 0.1512302146998903, 'fraction_numerical': 0.021626704278326282, 'mean_word_length': 2.3501312335958007, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '638494', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1894, 'n_words': 530}