<commit_before>from collections import namedtuple
import re
import discord

Unit = namedtuple("Unit", "name prefix conversionValue")

Units = [Unit("feet", "ft", 0.3048),
         Unit("meters", "m", 3.28084),
         Unit("pounds", "lbs", 0.453592),
         Unit("kilograms", "kg", 2.20462),
         Unit("fathoms", "fsw", 1.8288)]

UnitPairs = {'feet': 'meters',
             'meters': 'feet',
             'pounds': 'kilograms',
             'kilograms': 'pounds',
             'fathoms': 'meters'}

unitsTriggerString = '!convert'
historyLimit = 10

async def parse_units_command(message, client):
    bulk = False
    channel = message.channel
    if 'all' in message.content:
        bulk = True
    if message.content == unitsTriggerString or message.content == unitsTriggerString + ' all':
        async for msg in client.logs_from(channel, limit=historyLimit):
            for unit in Units:
                if msg.author != client.user:
                    send_message = parse_units(msg, unit)
                    if send_message != '':
                        await client.send_message(message.channel, send_message)
                        if not bulk:
                            break
    else:
        for unit in Units:
            send_message = parse_units(message, unit)
            if send_message != '':
                await client.send_message(message.channel, send_message)


def parse_units(message, unit):
    if re.search('[0-9]+(| )(' + unit.prefix + '|' + unit.name + ')', message.content) is not None:
        message_regex = re.search('[0-9]+(| )(' + unit.prefix + '|' + unit.name + ')', message.content)
        string = message_regex.group(0) + ' is '
        current_value = int(message_regex.group(0).replace(message_regex.group(2), ''))
        converted_value = current_value * unit.conversionValue
        return string + str("{0:.2f}".format(converted_value)) + ' ' + UnitPairs[unit.name]
    return ''<commit_msg>fix multiple instances of the same unit in one message<commit_after>from collections import namedtuple
import re
import discord

Unit = namedtuple("Unit", "name prefix conversionValue")

Units = [Unit("feet", "ft", 0.3048),
         Unit("meters", "m", 3.28084),
         Unit("pounds", "lbs", 0.453592),
         Unit("kilograms", "kg", 2.20462),
         Unit("fathoms", "fsw", 1.8288)]

UnitPairs = {'feet': 'meters',
             'meters': 'feet',
             'pounds': 'kilograms',
             'kilograms': 'pounds',
             'fathoms': 'meters'}

unitsTriggerString = '!convert'
historyLimit = 10


async def parse_units_command(message, client):
    bulk = False
    channel = message.channel
    if 'all' in message.content:
        bulk = True
    if message.content == unitsTriggerString or message.content == unitsTriggerString + ' all':
        async for msg in client.logs_from(channel, limit=historyLimit):
            for unit in Units:
                if msg.author != client.user:
                    send_message = parse_units(msg, unit)
                    if send_message != '':
                        messages = send_message.split(',')
                        for send in messages:
                            await client.send_message(message.channel, send)
                        if not bulk:
                            break
    else:
        for unit in Units:
            send_message = parse_units(message, unit)
            if send_message != '':
                messages = send_message.split(',')
                for send in messages:
                    await client.send_message(message.channel, send)


def parse_units(message, unit):
    if re.search('[0-9]+(| )(' + unit.prefix + '|' + unit.name + ')', message.content) is not None:
        response = ''
        loopCount = 0
        message_regex = re.finditer('[0-9]+(| )(' + unit.prefix + '|' + unit.name + ')', message.content)
        for match in message_regex:
            loopCount += 1
            string = match.group(0) + ' is '
            current_value = int(match.group(0).replace(match.group(2), ''))
            converted_value = current_value * unit.conversionValue
            if loopCount > 1:
                response += ','  # we split up into multiple messages later
            response += string + str("{0:.2f}".format(converted_value)) + ' ' + UnitPairs[unit.name]
        return response
    return ''
{'fraction_non_alphanumeric': 0.13133851073549566, 'fraction_numerical': 0.0189584285061672, 'mean_word_length': 2.121168923734854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2921886', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1239, 'n_words': 307}