Example #1
0
    def merge(self):
        self.group()
        self.count()
        for category in self.categories:
            if category in self.table:
                for n, item in enumerate(self.table[category]):
                    self.table[category][n][self.TABLE_DESIGNATOR] = \
                        lib.order_designator(item[self.TABLE_DESIGNATOR], self.logger)

                # Convert all designator in a number to be ordered
                if category in ["R", "C", "L", "Y"]:
                    for m in self.table[category]:
                        m[self.TABLE_COMMENT] = lib.value_toFloat(
                            m[self.TABLE_COMMENT], category, self.logger)
                        # print m[COMMENT], key

                self.table[category] = sorted(
                    self.table[category], key=lambda x: x[
                        self.TABLE_COMMENT])

                # Convert all ORDERED designator in a numeric format
                if category in ["R", "C", "L", "Y"]:
                    for m in self.table[category]:
                        m[self.TABLE_COMMENT] = lib.value_toStr(
                            m[self.TABLE_COMMENT], self.logger)
                        # print m[self.TABLE_COMMENT], category

        return self.table
Example #2
0
    def test_floatToValue(self):
        test = [
            ((1000, "ohm", ""), (1500, "ohm", ""), (2200, "ohm", ""),
             (2210, "ohm", ""), (4700, "ohm", ""), (47000, "ohm", "")),
            ((1000000, "ohm", ""), (1500000, "ohm", ""), (860000, "ohm", ""),
             (8600000, "ohm", "")),
            ((1.2, "ohm", ""), (3.33, "ohm", ""), (0.12, "ohm", ""),
             (1.234, "ohm", ""), (0.33, "ohm", ""), (3.3e-8, "ohm", "")),
            ((0.000010, "F", ""), (1e-3, "F", ""), (10e-3, "H", "")),
            ((1.5e-6, "F", ""), (33e-12, "F", ""), (100e-9, "F", "")),
            ((1, "ohm", ""), (0.1, "ohm", ""), (10, "ohm", ""),
             (100, "ohm", ""), (12.5, "ohm", "")),
            ((11, "R", ""), (120, "R", ""), (50, "R", "")),
            ((32768.0, "Hz", ""), (1e6, "Hz", ""), (12134, "Hz", "")),
        ]
        check = [
            ("1k", "1k5", "2k2", "2k21", "4k7", "47k"),
            ("1M", "1M5", "860k", "8M6"),
            ("1.2R", "3.33R", "0.12R", "1.234R", "0.33R", "33nohm"),
            ("10uF", "1mF", "10mH"),
            ("1.5uF", "33pF", "100nF"),
            ("1R", "0.1R", "10R", "100R", "12.5R"),
            ("11R", "120R", "50R"),
            ("32.768kHz", "1MHz", "12.134kHz"),
        ]

        for k, l in enumerate(test):
            for n, m in enumerate(l):
                l = lib.value_toStr(m, self.logger)
                self.assertTrue(l)

                print l, "->", check[k][n]
                self.assertEqual(l, check[k][n])
                print "-" * 80
Example #3
0
    def test_floatToValue(self):
        test = [
            ((1000, "ohm", ""), (1500, "ohm", ""), (2200, "ohm", ""), (2210, "ohm", ""), (4700, "ohm", ""), (47000, "ohm", "")),
            ((1000000, "ohm", ""), (1500000, "ohm", ""), (860000, "ohm", ""), (8600000, "ohm", "")),
            ((1.2, "ohm", ""), (3.33, "ohm", ""), (0.12, "ohm", ""), (1.234, "ohm", ""), (0.33, "ohm", ""), (3.3e-8, "ohm", "")),
            ((0.000010, "F", ""), (1e-3, "F", ""), (10e-3, "H", "")),
            ((1.5e-6, "F", ""), (33e-12, "F", ""), (100e-9, "F", "")),
            ((1, "ohm", ""), (0.1, "ohm", ""), (10, "ohm", ""), (100, "ohm", ""), (12.5, "ohm", "")),
            ((11, "R", ""), (120, "R", ""), (50, "R", "")),
            ((32768.0, "Hz", ""), (1e6,"Hz", ""), (12134,"Hz", "")),
        ]
        check = [
            ("1k", "1k5", "2k2", "2k21", "4k7", "47k"),
            ("1M", "1M5", "860k", "8M6"),
            ("1.2R", "3.33R", "0.12R", "1.234R", "0.33R", "33nohm"),
            ("10uF", "1mF", "10mH"),
            ("1.5uF", "33pF", "100nF"),
            ("1R", "0.1R", "10R", "100R", "12.5R"),
            ("11R", "120R", "50R"),
            ("32.768kHz", "1MHz", "12.134kHz"),
        ]

        for k, l in enumerate(test):
            for n, m in enumerate(l):
                l = lib.value_toStr(m, self.logger)
                self.assertTrue(l)

                print l, "->", check[k][n]
                self.assertEqual(l, check[k][n])
                print "-" * 80
Example #4
0
    def merge(self):
        self.group()
        self.count()
        for category in self.categories:
            if category in self.table:
                for n, item in enumerate(self.table[category]):
                    self.table[category][n][self.TABLE_DESIGNATOR] = \
                        lib.order_designator(item[self.TABLE_DESIGNATOR], self.logger)

                # Convert all designator in a number to be ordered
                if category in ["R", "C", "L", "Y"]:
                    d = {}
                    for item in self.table[category]:
                        if item[self.TABLE_FOOTPRINT] in d:
                            d[item[self.TABLE_FOOTPRINT]].append(item)
                        else:
                            d[item[self.TABLE_FOOTPRINT]] = [item]
                    for x in d.values():
                        self.table[category] = x
                        for m in self.table[category]:
                            m[self.TABLE_COMMENT] = lib.value_toFloat(
                                m[self.TABLE_COMMENT], category, self.logger)

                        self.table[category] = sorted(
                            self.table[category],
                            key=lambda x: x[self.TABLE_COMMENT])
                        # Convert all ORDERED designator in a numeric format
                        for m in self.table[category]:
                            m[self.TABLE_COMMENT] = lib.value_toStr(
                                m[self.TABLE_COMMENT], self.logger)
                        x = self.table[category]
                    self.table[category] = []
                    for x in d.values():
                        for y in x:
                            self.table[category].append(y)
        return self.table
Example #5
0
    def count(self):
        """
        grouped items format
        'U': ['bom_due.xls', 1, u'U3000', u'Lan transformer', u'LAN TRANFORMER WE 7490100111A', u'LAN_TR_1.27MM_SMD']
        'U': ['test.xlsx', 1, u'U2015', u'DC/DC switch converter', u'LM22671MR-ADJ', u'SOIC8_PAD']
        'U': ['test.xlsx', 1, u'U2002', u'Dual Low-Power Operational Amplifier', u'LM2902', u'SOIC14']
        'U': ['bom_uno.xls', 1, u'U7', u'Temperature sensor', u'LM75BIM', u'SOIC8']
        """

        self.table = {}

        # Finally Table layout
        self.TABLE_TOTALQTY = 0
        self.TABLE_DESIGNATOR = len(self.files) + 1
        self.TABLE_COMMENT = self.TABLE_DESIGNATOR + 1
        self.TABLE_FOOTPRINT = self.TABLE_COMMENT + 1
        self.TABLE_DESCRIPTION = self.TABLE_FOOTPRINT + 1

        self.stats['total'] = 0
        for category in self.categories:
            if category in self.grouped_items:
                tmp = {}
                self.stats[category] = 0
                for item in self.grouped_items[category]:

                    # Fix Designator
                    if category in ["R", "C", "L", "Y"]:
                        tmp_comment = lib.value_toFloat(item[COMMENT], category, self.logger)
                        item[COMMENT] = lib.value_toStr(tmp_comment, self.logger)

                    # Fix Not poluate string in list
                    for rexp in cfg.NOT_POPULATE_KEY:
                        item[COMMENT] = re.sub(rexp, 'NP ', item[COMMENT])

                    if category == 'J':
                        # Avoid merging for NP componets
                        skip_merge = False
                        m = re.findall(cfg.NP_REGEXP, item[COMMENT])
                        if m:
                            skip_merge = True
                            self.logger.error(
                                "Not Populate connector, leave unmerged..[%s] [%s] match%s\n" %
                                (item[COMMENT], item[DESIGNATOR], m))
                            item[COMMENT] = "NP Connector"

                        if skip_merge:
                            key = item[DESCRIPTION] + \
                                item[COMMENT] + item[FOOTPRINT]
                        else:
                            key = item[DESCRIPTION] + item[FOOTPRINT]
                            item[COMMENT] = "Connector"

                        self.logger.warning("Merged key: %s (%s)\n" %
                                            (key, item[COMMENT]))

                    if category == 'D' and "LED" in item[FOOTPRINT]:
                        key = item[DESCRIPTION] + item[FOOTPRINT]
                        item[COMMENT] = "LED"
                        self.logger.warning("Merged key: %s (%s)\n" % (key, item[COMMENT]))

                    if category == 'S' and "TACTILE" in item[FOOTPRINT]:
                        key = item[DESCRIPTION] + item[FOOTPRINT]
                        item[COMMENT] = "Tactile Switch"
                        self.logger.warning("Merged key: %s (%s)\n" % (key, item[COMMENT]))

                    elif category == 'U' and re.findall("rele|relay", item[DESCRIPTION].lower()):
                        key = item[DESCRIPTION] + item[FOOTPRINT]
                        item[COMMENT] = u"Relay, Rele'"
                        self.logger.warning("Merged key: %s (%s)\n" % (key, item[COMMENT]))
                    else:
                        key = item[DESCRIPTION] + \
                            item[COMMENT] + item[FOOTPRINT]

                    # print key
                    # print "<<", item[DESIGNATOR]
                    self.stats[category] += 1
                    self.stats['total'] += 1

                    # First colum is total Qty
                    curr_file_index = self.files[
                        item[FILENAME]] + self.TABLE_TOTALQTY + 1

                    if key in tmp:
                        tmp[key][self.TABLE_TOTALQTY] += item[QUANTITY]
                        tmp[key][curr_file_index] += item[QUANTITY]
                        tmp[key][
                            self.TABLE_DESIGNATOR] += ", " + item[DESIGNATOR]
                        tmp[key][self.TABLE_DESIGNATOR] = lib.order_designator(
                            tmp[key][self.TABLE_DESIGNATOR], self.logger)

                        for ex in self.extra_column:
                            # We add 1 because the table now contain also the
                            # file name, see init function in code that import
                            # data.
                            col_id = ex[1] + 1
                            try:
                                raw_value = item[col_id].strip()
                                if tmp[key][col_id] == "":
                                    tmp[key][col_id] = raw_value
                                else:
                                    if raw_value != "":
                                        words = re.findall(r'\b\S+\b', tmp[key][col_id])
                                        if not raw_value in words:
                                            tmp[key][col_id] += "; " + raw_value

                            except IndexError:
                                print "Error! Impossible to update extra column. This as bug!"
                                sys.exit(1)
                    else:
                        row = [item[QUANTITY]] + \
                            [0] * len(self.files) + \
                            [
                                item[DESIGNATOR],
                                item[COMMENT],
                                item[FOOTPRINT],
                                item[DESCRIPTION]
                            ]

                        row[curr_file_index] = item[QUANTITY]

                        # Add extra column to row if they are present in source
                        # file
                        for ex in self.extra_column:
                            # We add 1 because the table now contain also the
                            # file name, see init function in code that import
                            # data.
                            row.append(item[ex[1] + 1])


                        tmp[key] = row
                        # print "NEW", tmp[key], curr_file_index,
                        # item[FILENAME]

                self.table[category] = tmp.values()