<commit_before>import math
import networkx
from networkx.readwrite.json_graph import node_link_data, node_link_graph
from json import loads, dumps

hull_classes = {
    'chimera': 'carrier',
    'archon': 'carrier',
    'nidhoggur': 'carrier',
    'thanatos': 'carrier',
    'wyvern': 'supercarrier',
    'aeon': 'supercarrier',
    'hel': 'supercarrier',
    'nyx': 'supercarrier',
    'revenant': 'supercarrier',
    'phoenix': 'dreadnought',
    'revelation': 'dreadnought',
    'naglfar': 'dreadnought',
    'moros': 'dreadnought',
    'widow': 'blackops',
    'redeemer': 'blackops',
    'panther': 'blackops',
    'sin': 'blackops',
    'charon': 'jumpfreighter',
    'ark': 'jumpfreighter',
    'nomad': 'jumpfreighter',
    'anshar': 'jumpfreighter',
    'leviathan': 'titan',
    'avatar': 'titan',
    'ragnarok': 'titan',
    'erebus': 'titan',
    'rorqual': 'industrial',
}

base_range = {
    'carrier': 6.5,
    'dreadnought': 5.0,
    'industrial': 5.0,
    'jumpfreighter': 5.0,
    'supercarrier': 4.0,
    'titan': 3.5,
    'blackops': 3.5,
}

isotope_usage = {
    'carrier': 1500,
    'dreadnought': 1500,
    'industrial': 1500,
    'jumpfreighter': 5000,
    'supercarrier': 1500,
    'titan': 1500,
    'blackops': 450,
}


EVE_LY = 9460000000000000  # EVE's definition of a ly in KM

def calc_distance(sys1, sys2):
    """Calculate the distance in light years between two sets of 3d coordinates"""
    return math.sqrt(sum((a - b)**2 for a, b in zip(sys1, sys2))) / EVE_LY

def hull_to_range(hull, jdc_skill):
    """Returns the jump range of a provided ship hull and Jump Drive Calibration skill"""
    if hull.lower() not in hull_classes:
        raise ValueError('Unknown hull class {}'.format(hull))
    return ship_class_to_range(hull_classes[hull.lower()], jdc_skill)
    
def ship_class_to_range(ship_class, jdc_skill):
    """Returns the jump range of a provided ship class and Jump Drive Calibration skill"""
    if ship_class.lower() not in base_range:
        raise ValueError('Unknown ship class {}'.format(ship_class))
    base = base_range[ship_class]
    jump_range = base * (1 + (0.25 * jdc_skill))
    return jump_range


class Map(networkx.Graph):
    """
    A in-memory representation of the EVE Universe map, using NetworkX
    """

    def from_sde(self, db_conn):
        """Load map data from a EVE SDE Sqlite DB"""
        for id, name, region_name, x, y, z, security in db_conn.execute("""
            SELECT solarSystemID, solarSystemName, regionName, mapSolarSystems.x, mapSolarSystems.y, mapSolarSystems.z, mapSolarSystems.security
            FROM mapSolarSystems
            INNER JOIN mapRegions ON mapSolarSystems.regionID = mapRegions.regionID
            WHERE mapSolarSystems.regionID < 11000001"""):
            self.add_node(id, system_id=id, name=name, region=region_name, coords=(x, y, z), security=security)
        for from_id, to_id in db_conn.execute("SELECT fromSolarSystemID, toSolarSystemID FROM mapSolarSystemJumps"):
            self.add_edge(from_id, to_id, weight=1, link_type='gate')

    def build_jumps(self):
        """Constructs the possible jump network"""
        max_jump = 6.5 * (1 + (0.25 * 5))
        
        for source_id, source_data in self.nodes_iter(data=True):
            for destination_data, destination_range in self.neighbors_jump(source_id, max_jump):
                if destination_data['security'] < 0.5:
                    self.add_edge(source_id, destination_data['system_id'], weight=destination_range, link_type='jump')

    def add_jumpbridge(self, source_id, destination_id):
        self.add_edge(source_id, destination_id, weight=1, link_type='bridge')

    def to_json(self):
        """Dump map data to a Node Link JSON output"""
        return dumps(node_link_data(self))

    @staticmethod
    def from_json(json):
        """Load map data from a Node Link JSON output"""
        return Map(data=node_link_graph(loads(json)))

    def get_system_name(self, system_id):
        """Returns the name of the provided system id"""
        try:
            return self.node[system_id]['name']
        except KeyError:
            pass

    def get_system_id(self, name):
        """Returns the system id of the named system"""
        for k, v in self.nodes_iter(data=True):
            if 'name' in v and v['name'].lower() == name.lower():
                return k

    def get_systems(self, name):
        """Returns a list of systems by a partial system name"""
        return [k for k, v in self.nodes_iter(data=True) if name.lower() in v['name'].lower()]<commit_msg>Only match first part of the name.<commit_after>import math
import networkx
from networkx.readwrite.json_graph import node_link_data, node_link_graph
from json import loads, dumps

hull_classes = {
    'chimera': 'carrier',
    'archon': 'carrier',
    'nidhoggur': 'carrier',
    'thanatos': 'carrier',
    'wyvern': 'supercarrier',
    'aeon': 'supercarrier',
    'hel': 'supercarrier',
    'nyx': 'supercarrier',
    'revenant': 'supercarrier',
    'phoenix': 'dreadnought',
    'revelation': 'dreadnought',
    'naglfar': 'dreadnought',
    'moros': 'dreadnought',
    'widow': 'blackops',
    'redeemer': 'blackops',
    'panther': 'blackops',
    'sin': 'blackops',
    'charon': 'jumpfreighter',
    'ark': 'jumpfreighter',
    'nomad': 'jumpfreighter',
    'anshar': 'jumpfreighter',
    'leviathan': 'titan',
    'avatar': 'titan',
    'ragnarok': 'titan',
    'erebus': 'titan',
    'rorqual': 'industrial',
}

base_range = {
    'carrier': 6.5,
    'dreadnought': 5.0,
    'industrial': 5.0,
    'jumpfreighter': 5.0,
    'supercarrier': 4.0,
    'titan': 3.5,
    'blackops': 3.5,
}

isotope_usage = {
    'carrier': 1500,
    'dreadnought': 1500,
    'industrial': 1500,
    'jumpfreighter': 5000,
    'supercarrier': 1500,
    'titan': 1500,
    'blackops': 450,
}


EVE_LY = 9460000000000000  # EVE's definition of a ly in KM

def calc_distance(sys1, sys2):
    """Calculate the distance in light years between two sets of 3d coordinates"""
    return math.sqrt(sum((a - b)**2 for a, b in zip(sys1, sys2))) / EVE_LY

def hull_to_range(hull, jdc_skill):
    """Returns the jump range of a provided ship hull and Jump Drive Calibration skill"""
    if hull.lower() not in hull_classes:
        raise ValueError('Unknown hull class {}'.format(hull))
    return ship_class_to_range(hull_classes[hull.lower()], jdc_skill)
    
def ship_class_to_range(ship_class, jdc_skill):
    """Returns the jump range of a provided ship class and Jump Drive Calibration skill"""
    if ship_class.lower() not in base_range:
        raise ValueError('Unknown ship class {}'.format(ship_class))
    base = base_range[ship_class]
    jump_range = base * (1 + (0.25 * jdc_skill))
    return jump_range


class Map(networkx.Graph):
    """
    A in-memory representation of the EVE Universe map, using NetworkX
    """

    def from_sde(self, db_conn):
        """Load map data from a EVE SDE Sqlite DB"""
        for id, name, region_name, x, y, z, security in db_conn.execute("""
            SELECT solarSystemID, solarSystemName, regionName, mapSolarSystems.x, mapSolarSystems.y, mapSolarSystems.z, mapSolarSystems.security
            FROM mapSolarSystems
            INNER JOIN mapRegions ON mapSolarSystems.regionID = mapRegions.regionID
            WHERE mapSolarSystems.regionID < 11000001"""):
            self.add_node(id, system_id=id, name=name, region=region_name, coords=(x, y, z), security=security)
        for from_id, to_id in db_conn.execute("SELECT fromSolarSystemID, toSolarSystemID FROM mapSolarSystemJumps"):
            self.add_edge(from_id, to_id, weight=1, link_type='gate')

    def build_jumps(self):
        """Constructs the possible jump network"""
        max_jump = 6.5 * (1 + (0.25 * 5))
        
        for source_id, source_data in self.nodes_iter(data=True):
            for destination_data, destination_range in self.neighbors_jump(source_id, max_jump):
                if destination_data['security'] < 0.5:
                    self.add_edge(source_id, destination_data['system_id'], weight=destination_range, link_type='jump')

    def add_jumpbridge(self, source_id, destination_id):
        self.add_edge(source_id, destination_id, weight=1, link_type='bridge')

    def to_json(self):
        """Dump map data to a Node Link JSON output"""
        return dumps(node_link_data(self))

    @staticmethod
    def from_json(json):
        """Load map data from a Node Link JSON output"""
        return Map(data=node_link_graph(loads(json)))

    def get_system_name(self, system_id):
        """Returns the name of the provided system id"""
        try:
            return self.node[system_id]['name']
        except KeyError:
            pass

    def get_system_id(self, name):
        """Returns the system id of the named system"""
        for k, v in self.nodes_iter(data=True):
            if 'name' in v and v['name'].lower() == name.lower():
                return k

    def get_systems(self, name):
        """Returns a list of systems by a partial system name"""
        return [k for k, v in self.nodes_iter(data=True) if v['name'].lower().find(name.lower()) == 0]
{'fraction_non_alphanumeric': 0.12922876101381486, 'fraction_numerical': 0.018818666376590885, 'mean_word_length': 3.2154974782209997, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '566943', 'n_tokens_mistral': 3212, 'n_tokens_neox': 2986, 'n_words': 808}