コード例 #1
0
def decode_match(match, series_code, height):
    component = {}
    component['Series'] = match.group(1)
    component['Note'] = series_code[match.group(2)]
    component['Case'] = dimension[match.group(3)]
    component['Height'] = height[match.group(4)]
    component['Dielectric Type'] = dielectric_type[match.group(5)]
    component['Voltage'] = voltage[match.group(6)]
    component['Capacitance'] = capacitor.farads_to_string(
        capacitanceStringToFarads(match.group(7)))
    component['Tolerance'] = tolerance[match.group(8)]
    component['Manufacturer'] = 'Murata'
    return component
コード例 #2
0
 def find_capacitor_by_parameters(self, part):
     """
     :param part: dictionary with fields:
             'Capacitance': int in Farads,
             'Case': string
             'Voltage': int in Volts
             'Dielectric Type': string ie.: X7R, NP0 etc.
     :return:
     """
     params = {
         'filter':
         '''[
                 {{"subfilters": [
                     {{"subfilters": [
                         {{"subfilters": [], "property": "description", "value": "%{0}%", "operator": "like"}}
                         ], "type": "OR"}},
                     {{"subfilters": [
                         {{"subfilters": [], "property": "description", "value": "%{1}%", "operator": "like"}}
                         ], "type": "OR"}}                       
                     ], "type": "AND"}},
                 {{"subfilters": [], "property": "category", "operator": "IN",
                         "value": ["/api/part_categories/9", "/api/part_categories/37",
                         "/api/part_categories/10", "/api/part_categories/12",
                         "/api/part_categories/11"]}}
                ]'''.format(capacitor.farads_to_string(part['Capacitance']),
                            part['Dielectric Type']).replace("\n",
                                                             "").replace(
                                                                 " ", "")
     }
     # print(params)
     response = self.__partkeepr_api_call('get',
                                          '/api/parts',
                                          params=params)
     response = response.json()
     if len(response["hydra:member"]) > 0:
         found = []
         for component in response["hydra:member"]:
             decoded_part = self.decode_product_dictionary(component)
             if "Voltage" in decoded_part['Parameters'] and part[
                     'Voltage'] is not None:
                 if decoded_part['Parameters']['Voltage'] >= part['Voltage']:
                     found.append(decoded_part)
             else:
                 found.append(decoded_part)
         return found
コード例 #3
0
def kemet(partname):
    voltage = {
        '9': '6.3V',
        '8': '10V',
        '4': '16V',
        '3': '25V',
        '6': '35V',
        '5': '50V',
        '1': '100V',
        '2': '200V',
        'A': '250V'
    }
    tolerance = {
        'B': '+-0.10pF',
        'C': '0.25pF',
        'D': '0.5pF',
        'F': '1%',
        'G': '2%',
        'J': '5%',
        'K': '10%',
        'M': '20%'
    }

    match = re.match(
        r'(C)(0201|0402|0603|0805|1206|1210|1808|1812|1825|2220|2225)(C)(\d{3})(B|C|D|F|G|J|K|M)(8|4|3|5|1|2|A)(G)',
        partname)
    if match:
        print('Capacitor mached: ' + partname)

        def capacitanceStringToFarads_kamet(string):
            value = Decimal(string[:2])
            mul = Decimal(string[2])
            if mul == Decimal(8):
                return value / Decimal(100) * Decimal(10**-12)
            if mul == Decimal(9):
                return value / Decimal(10) * Decimal(10**-12)
            return value * Decimal('10')**mul * Decimal('10')**Decimal('-12')

        component = {}
        component['series'] = 'C - Standard'
        component['Case'] = match.group(2)
        component['Dielectric Type'] = 'C0G'
        component['Voltage'] = voltage[match.group(6)]
        component['Capacitance'] = capacitor.farads_to_string(
            capacitanceStringToFarads_kamet(match.group(4)))
        component['Tolerance'] = tolerance[match.group(5)]
        component['Manufacturer'] = 'Kemet'
        return component

    match = re.match(
        r'(C)(0201|0402|0603|0805|1206|1210|1808|1812|1825|2220|2225)(C)(\d{3})(J|K|M)(9|8|4|3|6|5|1|2|A)(R)',
        partname)
    if match:
        print('Capacitor mached: ' + partname)
        component = {}
        component['series'] = 'C - Standard'
        component['Case'] = match.group(2)
        component['Dielectric Type'] = 'X7R'
        component['Voltage'] = voltage[match.group(6)]
        component['Capacitance'] = capacitor.farads_to_string(
            capacitanceStringToFarads(match.group(4)))
        component['Tolerance'] = tolerance[match.group(5)]
        component['Manufacturer'] = 'Kemet'
        return component
コード例 #4
0
def find_component(components_group, group, tme_config):
    def to_string(case):
        if case:
            return case
        return 'None'

    from distributor_connector import tme
    from distributor_connector import partkeepr
    distributors = [
        tme.TME(tme_config['token'], tme_config['app_secret']),
        partkeepr.Partkeepr("https://partkeepr.locallan", "auto", "auto")
    ]

    for shop in distributors:
        for component in components_group:
            if 'Manufacturer Part Number' in component and component[
                    'Manufacturer Part Number'] != "":
                print("Request for " + component['Manufacturer Part Number'])
                found = shop.find_component(
                    component['Manufacturer Part Number'])
            else:
                if group == "Capacitors":
                    print("Request for " +
                          to_string(component['Capacitance']) + " " +
                          to_string(component['Voltage']) + ' ' +
                          to_string(component['Case']))
                    try:
                        capacitor_parameters = {
                            'Capacitance':
                            capacitor.convert_capacitance_co_farads(
                                component['Capacitance']),
                            'Case':
                            to_string(component['Case']),
                            'Voltage':
                            voltage.string_to_voltage(component['Voltage']),
                            'Dielectric Type':
                            component['Dielectric Type']
                        }
                        found = shop.find_capacitor_by_parameters(
                            capacitor_parameters)
                        if found:
                            for part in found:
                                if 'Voltage' in part['Parameters']:
                                    part['Parameters'][
                                        'Voltage'] = voltage.volts_to_string(
                                            part['Parameters']['Voltage'])
                                if 'Capacitance' in part['Parameters']:
                                    part['Parameters'][
                                        'Capacitance'] = capacitor.farads_to_string(
                                            part['Parameters']['Capacitance'])
                    except InvalidOperation:
                        print(component)
                        raise
                elif group == "Resistors":
                    print("Request for " + to_string(component['Resistance']) +
                          ' ' + to_string(component['Case']) + ' ' +
                          to_string(component['Tolerance']))
                    if component['Resistance'] is None:
                        print("Skipping...")
                        component["Distributors"] = []
                        continue
                    try:
                        resistor_parameters = {
                            'Resistance':
                            resistor.convert_resistance_to_ohms(
                                component['Resistance']),
                            'Case':
                            component['Case'],
                            'Tolerance':
                            tolerance.string_to_tolerance(
                                component['Tolerance'])
                        }
                        found = shop.find_resistor_by_parameters(
                            resistor_parameters)
                        if found:
                            for part in found:
                                if 'Resistance' in part['Parameters']:
                                    part['Parameters'][
                                        'Resistance'] = resistor.ohms_to_string(
                                            part['Parameters']['Resistance'])
                                if 'Tolerance' in part['Parameters']:
                                    part['Parameters'][
                                        'Tolerance'] = tolerance.tolerance_to_string(
                                            part['Parameters']['Tolerance'])
                    except TypeError:
                        print(component)
                        raise
                elif group in ["IntegratedCircuits"
                               ] and component['Comment'] != '':
                    print("Request for " + to_string(component['Comment']))
                    found = shop.find_component(component['Comment'])
                else:
                    found = None

            if "Distributors" not in component:
                component["Distributors"] = []
            if found:
                component["Distributors"].append({
                    "Name": shop.name,
                    "Components": found
                })
コード例 #5
0
def decodeCapacitor(component):
    def getCapacitance(component):
        import re
        for field in ['Capacitance', 'capacitance', 'Value']:
            if field in component:
                if component[field] != '':
                    return component[field].replace(" ", "").replace(",", ".")

        for field in ['Comment', 'Description']:
            fieldContent = component[field]
            match = re.search(r'(\d+(F|m|u|n|p)\d+)',
                              fieldContent)  # try to match 4p7 4n7 4F1 etc.
            if match:
                return match.group(1).replace(" ", "").replace(",", ".")
            match = re.search(
                r'(\d+([.,]\d+)?[ ]?(F|mF|uF|nF|pF|m|u|n|p))',
                fieldContent)  # try to match 4.7F 4,7F 4.7nF etc.
            if match:
                return match.group(1).replace(" ", "").replace(",", ".")

    def getVoltage(component):
        import re
        for field in ['Voltage', 'voltage']:
            if field in component:
                if component[field] != '':
                    return component[field]

        for field in ['Comment', 'Description']:
            if field in component:
                fieldContent = component[field]
                match = re.search(r'(\d+ ?(V|v))', fieldContent)
                if match:
                    return match.group(1).replace(" ", "").upper()

    def getManufacturer(component):
        manufacturerList = ['Murata', 'AVX', 'Kemet']
        if 'Comment' in component:
            for word in component['Comment'].split():
                for manufacturer in manufacturerList:
                    if manufacturer.lower() == word.lower():
                        return manufacturer
        return ''

    def getDielectricType(component):
        dielectricsList = ['X5R', 'X7R', 'Y5V', 'C0G', 'NP0']
        if 'Dielectric Type' in component:
            if component['Dielectric Type'] is not None and component[
                    'Dielectric Type'] != "":
                return component['Dielectric Type']
        for field in ['Comment', 'Description']:
            if field in component:
                for word in component[field].split():
                    for dielectric in dielectricsList:
                        if dielectric.lower() == word.lower():
                            return dielectric
        return ''

    def getManufacturerPartNumber(component):
        capacitorFamilyList = [r'(GCM[A-Za-z0-9]+)', r'C0603', r'C0805']
        for field in ['Comment', 'Description']:
            if field in component:
                for word in component[field].split():
                    for capacitorRegexpr in capacitorFamilyList:
                        if re.compile(capacitorRegexpr).match(word):
                            return word
        return ''

    part = {}
    part['Capacitance'] = capacitor.farads_to_string(
        capacitor.convert_capacitance_co_farads(getCapacitance(component)))
    part['Voltage'] = getVoltage(component)
    part['Case'] = getCase(component)
    part['Manufacturer'] = getManufacturer(component)
    part['Manufacturer Part Number'] = getManufacturerPartNumber(component)
    part['Dielectric Type'] = getDielectricType(component)
    part['Quantity'] = getQuantity(component)
    part['Designator'] = component['Designator']
    part['Tolerance'] = getTolerance(component)
    return part