示例#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
示例#2
0
    def test_orderRef(self):
        test = [
            "C0, C103, C1, C3001, C12",
            "TR100, TR1, TR0, TR10, TR10",
            "RES100, RES1, RES0, RES1001, RES10",
            "SW1",
            "RN1A, RN0B, RN1000, RN3",
        ]
        check = [
            "C0, C1, C12, C103, C3001",
            "TR0, TR1, TR10, TR10, TR100",
            "RES0, RES1, RES10, RES100, RES1001",
            "SW1",
            "RN0B, RN1A, RN3, RN1000",
        ]

        for n, i in enumerate(test):
            l = lib.order_designator(i, self.logger)
            self.assertEqual(l, check[n])
示例#3
0
    def test_orderRef(self):
        test = [
            "C0, C103, C1, C3001, C12",
            "TR100, TR1, TR0, TR10, TR10",
            "RES100, RES1, RES0, RES1001, RES10",
            "SW1",
            "RN1A, RN0B, RN1000, RN3",
        ]
        check = [
            "C0, C1, C12, C103, C3001",
            "TR0, TR1, TR10, TR10, TR100",
            "RES0, RES1, RES10, RES100, RES1001",
            "SW1",
            "RN0B, RN1A, RN3, RN1000",
        ]

        for n, i in enumerate(test):
            l = lib.order_designator(i, self.logger)
            self.assertEqual(l, check[n])
示例#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
示例#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()