<commit_before>import math
import xml.etree.ElementTree as et


HEADERS = '''<?xml version=\"1.0\" standalone=\"no\"?>
<?xml-stylesheet href="wheel.css" type="text/css"?>
<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">
'''

PATH_TEMPLATE = '''
M {start_outer_x},{start_outer_y}
A{outer_radius},{outer_radius} 0 0 1 {end_outer_x},{end_outer_y}
L {start_inner_x},{start_inner_y}
A{inner_radius},{inner_radius} 0 0 0 {end_inner_x},{end_inner_y}
Z
'''

FRACTION_LINE = 80
OFFSET = 20
PADDING = 10
RADIUS = 180
CENTER = PADDING + RADIUS
TAU = 2*math.pi


def annular_sector_path(center_x, center_y, inner_radius, outer_radius, start, stop):
    points = {
        'inner_radius': inner_radius,
        'outer_radius': outer_radius,
        'start_outer_x': center_x + outer_radius*math.cos(start),
        'start_outer_y': center_y + outer_radius*math.sin(start),
        'end_outer_x': center_x + outer_radius*math.cos(stop),
        'end_outer_y': center_y + outer_radius*math.sin(stop),
        'start_inner_x': center_x + inner_radius*math.cos(stop),
        'start_inner_y': center_y + inner_radius*math.sin(stop),
        'end_inner_x': center_x + inner_radius*math.cos(start),
        'end_inner_y': center_y + inner_radius*math.sin(start),
    }

    return PATH_TEMPLATE.format(**points)


def add_annular_sector(wheel, center, inner_radius, outer_radius, start, stop, style_class):
    return et.SubElement(wheel, 'path',
        d=annular_sector_path(
            center_x=center[0], center_y=center[1],
            inner_radius=inner_radius, outer_radius=outer_radius,
            start=start, stop=stop,
        ),
        attrib={'class': style_class},
    )


def angles(index, total):
    start = index * TAU / total
    stop = (index + 1) * TAU / total

    return (start - TAU/4, stop - TAU/4)


def add_fraction(wheel, packages, total):
    text_attributes = {
            'text-anchor': 'middle',
            'dominant-baseline': 'central',
            'font-size': str(2*OFFSET),
            'font-family': '"Helvetica Neue",Helvetica,Arial,sans-serif',
            'fill': '#333333',
        }

    # Packages with some sort of wheel
    wheel_packages = sum(package['wheel'] for package in packages)

    packages_with_wheels = et.SubElement(wheel, 'text',
        x=str(CENTER), y=str(CENTER - OFFSET),
        attrib=text_attributes,
    )
    packages_with_wheels.text='{}'.format(wheel_packages)

    # Dividing line
    et.SubElement(wheel, 'line',
        x1=str(CENTER - FRACTION_LINE//2), y1=str(CENTER),
        x2=str(CENTER + FRACTION_LINE//2), y2=str(CENTER),
        attrib={'stroke': '#333333', 'stroke-width': '2'},
        )

    # Total packages
    total_packages = et.SubElement(wheel, 'text',
        x=str(CENTER), y=str(CENTER + OFFSET),
        attrib=text_attributes,
    )
    total_packages.text='{}'.format(total)


def generate_svg_wheel(packages, total):
    wheel = et.Element('svg', viewBox='0 0 {0} {0}'.format(2*CENTER), version='1.1', xmlns='http://www.w3.org/2000/svg')

    for index, result in enumerate(packages):
        start, stop = angles(index, total)
        sector = add_annular_sector(
            wheel,
            center=(CENTER, CENTER),
            inner_radius=RADIUS//2, outer_radius=RADIUS,
            start=start, stop=stop,
            style_class=result['css_class'],
        )
        title = et.SubElement(sector, 'title')
        title.text = u'{} {}'.format(result['name'], result['icon'])

    add_fraction(wheel, packages, total)

    with open('wheel.svg', 'w') as svg:
        svg.write(HEADERS)
        svg.write(et.tostring(wheel))
<commit_msg>Pep8 fixes<commit_after>import math
import xml.etree.ElementTree as et


HEADERS = '''<?xml version=\"1.0\" standalone=\"no\"?>
<?xml-stylesheet href="wheel.css" type="text/css"?>
<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">
'''

PATH_TEMPLATE = '''
M {start_outer_x},{start_outer_y}
A{outer_radius},{outer_radius} 0 0 1 {end_outer_x},{end_outer_y}
L {start_inner_x},{start_inner_y}
A{inner_radius},{inner_radius} 0 0 0 {end_inner_x},{end_inner_y}
Z
'''

FRACTION_LINE = 80
OFFSET = 20
PADDING = 10
RADIUS = 180
CENTER = PADDING + RADIUS
TAU = 2*math.pi


def annular_sector_path(
        center_x, center_y, inner_radius, outer_radius, start, stop):
    points = {
        'inner_radius': inner_radius,
        'outer_radius': outer_radius,
        'start_outer_x': center_x + outer_radius*math.cos(start),
        'start_outer_y': center_y + outer_radius*math.sin(start),
        'end_outer_x': center_x + outer_radius*math.cos(stop),
        'end_outer_y': center_y + outer_radius*math.sin(stop),
        'start_inner_x': center_x + inner_radius*math.cos(stop),
        'start_inner_y': center_y + inner_radius*math.sin(stop),
        'end_inner_x': center_x + inner_radius*math.cos(start),
        'end_inner_y': center_y + inner_radius*math.sin(start),
    }

    return PATH_TEMPLATE.format(**points)


def add_annular_sector(
        wheel, center, inner_radius, outer_radius, start, stop, style_class):
    return et.SubElement(
        wheel, 'path',
        d=annular_sector_path(
            center_x=center[0], center_y=center[1],
            inner_radius=inner_radius, outer_radius=outer_radius,
            start=start, stop=stop,
        ),
        attrib={'class': style_class},
    )


def angles(index, total):
    start = index * TAU / total
    stop = (index + 1) * TAU / total

    return (start - TAU/4, stop - TAU/4)


def add_fraction(wheel, packages, total):
    text_attributes = {
        'text-anchor': 'middle',
        'dominant-baseline': 'central',
        'font-size': str(2*OFFSET),
        'font-family': '"Helvetica Neue",Helvetica,Arial,sans-serif',
        'fill': '#333333',
    }

    # Packages with some sort of wheel
    wheel_packages = sum(package['wheel'] for package in packages)

    packages_with_wheels = et.SubElement(
        wheel, 'text',
        x=str(CENTER), y=str(CENTER - OFFSET),
        attrib=text_attributes,
    )
    packages_with_wheels.text = '{}'.format(wheel_packages)

    # Dividing line
    et.SubElement(
        wheel, 'line',
        x1=str(CENTER - FRACTION_LINE//2), y1=str(CENTER),
        x2=str(CENTER + FRACTION_LINE//2), y2=str(CENTER),
        attrib={'stroke': '#333333', 'stroke-width': '2'},
    )

    # Total packages
    total_packages = et.SubElement(
        wheel, 'text',
        x=str(CENTER), y=str(CENTER + OFFSET),
        attrib=text_attributes,
    )
    total_packages.text = '{}'.format(total)


def generate_svg_wheel(packages, total):
    wheel = et.Element(
        'svg',
        viewBox='0 0 {0} {0}'.format(2*CENTER),
        version='1.1',
        xmlns='http://www.w3.org/2000/svg',
    )

    for index, result in enumerate(packages):
        start, stop = angles(index, total)
        sector = add_annular_sector(
            wheel,
            center=(CENTER, CENTER),
            inner_radius=RADIUS//2, outer_radius=RADIUS,
            start=start, stop=stop,
            style_class=result['css_class'],
        )
        title = et.SubElement(sector, 'title')
        title.text = u'{} {}'.format(result['name'], result['icon'])

    add_fraction(wheel, packages, total)

    with open('wheel.svg', 'w') as svg:
        svg.write(HEADERS)
        svg.write(et.tostring(wheel))
{'fraction_non_alphanumeric': 0.15050437121721588, 'fraction_numerical': 0.01735036987222596, 'mean_word_length': 3.0611687602403057, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 2, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 8}, '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': '6364184', 'n_tokens_mistral': 2710, 'n_tokens_neox': 2571, 'n_words': 472}