<commit_before>"""Writes a KML file of points from stdin."""

import fileinput


PLACEMARK_TEMPLATE = '''<Placemark>
    <name>{name}</name>
    <styleUrl>{style_url}</styleUrl>
    <LineString>
            <tessellate>1</tessellate>
            <coordinates>
                {coordinates}
        </coordinates>
    </LineString>
</Placemark>
'''

STYLE_TEMPLATE = '''<StyleMap id="m{id}">
        <Pair>
                <key>normal</key>
                <styleUrl>#{id}0</styleUrl>
        </Pair>
        <Pair>
                <key>highlight</key>
                <styleUrl>#{id}1</styleUrl>
        </Pair>
</StyleMap>
<Style id="{id}0">
        <IconStyle>
                <scale>{scale}</scale>
        </IconStyle>
        <LineStyle>
                <color>{color}</color>
                <width>1</width>
        </LineStyle>
</Style>
<Style id="{id}1">
        <LineStyle>
                <color>{color}</color>
                <width>1</width>
        </LineStyle>
</Style>'''

FOLDER_TEMPLATE = '''<Folder>
    <name>{name}</name>
    {placemark}
</Folder>
'''


def build_color_map(runs):
    """Returns the color map for a series of runs.

    runs is:
      [
        {
          'device_id_1': [(lat, long), (lat, long), ...],
          'device_id_2': [(lat, long), (lat, long), ...]
          ...
        },
        {
          'device_id_1': [(lat, long), (lat, long), ...],
          'device_id_2': [(lat, long), (lat, long), ...]
          ...
        },
        ...
    ]
    """

    color_map = {
        # Default the estimate to yellow
        # ABGR
        'estimate': 'ff00ffff'
    }
    # ABGR
    preferred_colors = ['ff0000ff', 'ff00ff00', 'ffff0000']
    for run in runs:
        for device in run:
            if device in color_map:
                continue

            if len(preferred_colors) > 0:
                color = preferred_colors.pop()
            else:
                color = 'ffaaffff'
            color_map[device] = color
    return color_map


def device_id_to_style_url(device):<commit_msg>Add more preferred colors<commit_after>"""Writes a KML file of points from stdin."""

import fileinput


PLACEMARK_TEMPLATE = '''<Placemark>
    <name>{name}</name>
    <styleUrl>{style_url}</styleUrl>
    <LineString>
            <tessellate>1</tessellate>
            <coordinates>
                {coordinates}
        </coordinates>
    </LineString>
</Placemark>
'''

STYLE_TEMPLATE = '''<StyleMap id="m{id}">
        <Pair>
                <key>normal</key>
                <styleUrl>#{id}0</styleUrl>
        </Pair>
        <Pair>
                <key>highlight</key>
                <styleUrl>#{id}1</styleUrl>
        </Pair>
</StyleMap>
<Style id="{id}0">
        <IconStyle>
                <scale>{scale}</scale>
        </IconStyle>
        <LineStyle>
                <color>{color}</color>
                <width>1</width>
        </LineStyle>
</Style>
<Style id="{id}1">
        <LineStyle>
                <color>{color}</color>
                <width>1</width>
        </LineStyle>
</Style>'''

FOLDER_TEMPLATE = '''<Folder>
    <name>{name}</name>
    {placemark}
</Folder>
'''


def build_color_map(runs):
    """Returns the color map for a series of runs.

    runs is:
      [
        {
          'device_id_1': [(lat, long), (lat, long), ...],
          'device_id_2': [(lat, long), (lat, long), ...]
          ...
        },
        {
          'device_id_1': [(lat, long), (lat, long), ...],
          'device_id_2': [(lat, long), (lat, long), ...]
          ...
        },
        ...
    ]
    """

    color_map = {
        # Default the estimate to yellow
        # ABGR
        'estimate': 'ff00ffff'
    }
    # ABGR
    preferred_colors = ['ff0000ff', 'ff00ff00', 'ffff0000', 'ffff00ff', 'ff654321']
    for run in runs:
        for device in run:
            if device in color_map:
                continue

            if len(preferred_colors) > 0:
                color = preferred_colors.pop()
            else:
                color = 'ffaaffff'
            color_map[device] = color
    return color_map


def device_id_to_style_url(device):
{'fraction_non_alphanumeric': 0.16141541444498303, 'fraction_numerical': 0.014541929229277752, 'mean_word_length': 1.605429292929293, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 105, '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': '3706695', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1331, 'n_words': 262}