Example #1
0
    def __init__(self):

        print "\nreading NEW standards"
        self.new_AsnStandards = StdDocument(new_asnpath)
        self.new_asn_ids = self.new_AsnStandards.keys()

        print "\nreading OLD standards"
        self.old_AsnStandards = StdDocument(old_asnpath)
        self.old_asn_ids = self.old_AsnStandards.keys()
Example #2
0
    def __init__(self, url):
        self.url = url
        XmlRecord.__init__(self, xml=self.getUrl(url))
        self.mapped_ids = self._getMappedIds()

        print "\nreading NEW standards"
        self.new_AsnStandards = StdDocument(new_asnpath)
        self.new_asn_ids = self.new_AsnStandards.keys()

        print "\nreading OLD standards"
        self.old_AsnStandards = StdDocument(old_asnpath)
        self.old_asn_ids = self.old_AsnStandards.keys()
Example #3
0
class NSESStandardsSetup(UserDict):
    def __init__(self, path):
        UserDict.__init__(self)
        self.NSES = StdDocument(NSESpath)
        self.groups = SubjectGroupMap()
        self._init_pool()

        # for i in range(10):
        # std = self.pool[i]
        # # print "%s: %s" % (getBand(std), std.description)
        # print self._get_std_domain (std)

    def add(self, item):
        self[item.id] = item
        self.groups.add(item)

    def _init_pool(self):

        for asnStd in self.NSES.values():
            if asnStd.level == 3:
                std_domain = self._get_std_domain(asnStd)
                if std_domain:
                    self.add(NSESStandard(asnStd, std_domain))

    def _get_std_domain(self, std):
        # print "getBand(): " + std.description
        domains = nses_std_domains.keys()
        node = std
        while node and node.description not in domains:
            node = self.NSES[node.parent]
        if node and node.description in domains:
            return nses_std_domains[node.description]

    def __repr__(self):
        s = []
        add = s.append

        add("NSES_stds_pool = {")
        for group_name in domain_groups_keys:
            add('\t"%s": {' % group_name)

            group = self.groups[group_name]
            for band_name in group.keys():
                add('\t\t"%s" : [' % band_name)

                band = group[band_name]
                for std in band:
                    add('\t\t\t"%s",' % std.numId)
                add('\t\t],')
            add('\t},')
        add('}')
        return string.join(s, "\n")
Example #4
0
class AsnCompare:
    def __init__(self):

        print "\nreading NEW standards"
        self.new_AsnStandards = StdDocument(new_asnpath)
        self.new_asn_ids = self.new_AsnStandards.keys()

        print "\nreading OLD standards"
        self.old_AsnStandards = StdDocument(old_asnpath)
        self.old_asn_ids = self.old_AsnStandards.keys()

    def set_diff(self, set1, set2):
        ids = []
        add = ids.append
        for id in set1:
            if id not in set2:
                add(id)
        return ids

    def new_asn_not_in_old_asn(self):
        ids = self.set_diff(self.new_asn_ids, self.old_asn_ids)
        return self.filter_ids_by_level(ids, self.new_AsnStandards)

    def old_asn_not_in_new_asn(self):
        ids = self.set_diff(self.old_asn_ids, self.new_asn_ids)
        return self.filter_ids_by_level(ids, self.old_AsnStandards)

    def report_asn_diff(self):
        ids = self.new_asn_not_in_old_asn()
        if 1:
            print "\nNEW ASN stds not in OLD ASN stds (%d)" % len(ids)
            for id in ids:
                std = self.new_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)

        ids = self.old_asn_not_in_new_asn()
        if 1:
            print "\nOLD ASN stds not in NEW ASN stds (%d)" % len(ids)
            for id in ids:
                std = self.old_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)

    def filter_ids_by_level(self, ids, standardsDoc, threshold=None):
        """
			1 - sort the ids as strings (just to put them in some consistent order)
			2 - filter out the standards for level less than threshold (if provided)
			3 - sort by level (in standards hierarchy)
		"""
        filtered = []
        ids.sort()
        for id in ids:
            level = standardsDoc[id].level + 1
            if threshold:
                if level > threshold:
                    filtered.append(id)
            else:
                filtered.append(id)
        return self.sort_by_level(filtered, standardsDoc)

    def sort_by_level(self, ids, standardsDoc):
        bins = {}
        for id in ids:
            level = standardsDoc[id].level + 1
            if not bins.has_key(level):
                bins[level] = []
            items = bins[level]
            items.append(id)
            bins[level] = items
        sorted_ids = []
        add = sorted_ids.append
        for level in bins.keys():
            items = bins[level]
            for id in items:
                add(id)
        return sorted_ids

    def report(self):

        self.report_asn_diff()
Example #5
0
    def __init__(self, dir):
        self.data_dir = dir

        NSESDocPath = os.path.join(self.asnDocDir, self.nsesDoc)
        self.NSES = StdDocument(NSESDocPath)
Example #6
0
class Validator(XmlRecord):
    def __init__(self, url):
        self.url = url
        XmlRecord.__init__(self, xml=self.getUrl(url))
        self.mapped_ids = self._getMappedIds()

        print "\nreading NEW standards"
        self.new_AsnStandards = StdDocument(new_asnpath)
        self.new_asn_ids = self.new_AsnStandards.keys()

        print "\nreading OLD standards"
        self.old_AsnStandards = StdDocument(old_asnpath)
        self.old_asn_ids = self.old_AsnStandards.keys()

    def _getMappedIds(self):
        mappings = self.selectNodes(self.dom, "Adn-to-Asn-mappings:mapping")

        print "%d mappings found" % len(mappings)
        ids = map(lambda a: a.getAttribute("asnIdentifier"), mappings)
        ## 		for id in ids:
        ## 			print "\t", id
        ids.sort()
        return ids

    def set_diff(self, set1, set2):
        ids = []
        add = ids.append
        for id in set1:
            if id not in set2:
                add(id)
        return ids

    def new_asn_not_in_old_asn(self):
        ids = self.set_diff(self.new_asn_ids, self.old_asn_ids)
        return self.filter_ids_by_level(ids, self.new_AsnStandards)

    def old_asn_not_in_new_asn(self):
        ids = self.set_diff(self.old_asn_ids, self.new_asn_ids)
        return self.filter_ids_by_level(ids, self.old_AsnStandards)

    # filter threshold for mapping files is 2, since mapping contains only levels 3 and 4
    def mapping_not_in_new_asn(self):
        ids = self.set_diff(self.mapped_ids, self.new_asn_ids)
        return self.filter_ids_by_level(ids, self.old_AsnStandards, 2)

    # filter threshold for mapping files is 2, since mapping contains only levels 3 and 4
    def mapping_not_in_old_asn(self):
        ids = self.set_diff(self.mapped_ids, self.old_asn_ids)
        return self.filter_ids_by_level(ids, self.old_AsnStandards, 2)

    # filter threshold for mapping files is 2, since mapping contains only levels 3 and 4
    def new_asn_not_in_mapping(self):
        ids = self.set_diff(self.new_asn_ids, self.mapped_ids)
        return self.filter_ids_by_level(ids, self.new_AsnStandards, 2)

    # filter threshold for mapping files is 2, since mapping contains only levels 3 and 4
    def old_asn_not_in_mapping(self):
        ids = self.set_diff(self.old_asn_ids, self.mapped_ids)
        return self.filter_ids_by_level(ids, self.old_AsnStandards, 2)

    def report_new(self):
        ids = self.mapping_not_in_new_asn()
        if ids:
            print "\nIds in Mapping but not in NEW ASN doc (%d)" % len(ids)
            for id in ids:
                std = self.old_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)
        else:
            print "\nAll Ids in mapping are present in NEW ASN doc"

        ids = self.new_asn_not_in_mapping()
        if ids:
            print "\nIds in NEW ASN but not in Mapping (%d)" % len(ids)
            for id in ids:
                std = self.new_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)
        else:
            print "\nAll NEW ASN Ids are present in mapping doc"

    def report_old(self):
        ids = self.mapping_not_in_old_asn()
        if ids and 0:
            print "\nIds in Mapping but not in OLD ASN doc (%d)" % len(ids)
            for id in ids:
                std = self.old_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)

        ids = self.old_asn_not_in_mapping()
        if ids:
            print "\nIds in OLD ASN but not in Mapping (%d)" % len(ids)
            for id in ids:
                std = self.old_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)

    def report_asn_diff(self):
        ids = self.new_asn_not_in_old_asn()
        if 1:
            print "\nNEW ASN stds not in OLD ASN stds (%d)" % len(ids)
            for id in ids:
                std = self.new_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)

        ids = self.old_asn_not_in_new_asn()
        if 1:
            print "\nOLD ASN stds not in NEW ASN stds (%d)" % len(ids)
            for id in ids:
                std = self.old_AsnStandards[id]
                print "\t%s level: %d" % (getNumId(id), std.level + 1)

    def filter_ids_by_level(self, ids, standardsDoc, threshold=None):
        """
			1 - sort the ids as strings (just to put them in some consistent order)
			2 - filter out the standards for level less than threshold (if provided)
			3 - sort by level (in standards hierarchy)
		"""
        filtered = []
        ids.sort()
        for id in ids:
            level = standardsDoc[id].level + 1
            if threshold:
                if level > threshold:
                    filtered.append(id)
            else:
                filtered.append(id)
        return self.sort_by_level(filtered, standardsDoc)

    def sort_by_level(self, ids, standardsDoc):
        bins = {}
        for id in ids:
            level = standardsDoc[id].level + 1
            if not bins.has_key(level):
                bins[level] = []
            items = bins[level]
            items.append(id)
            bins[level] = items
        sorted_ids = []
        add = sorted_ids.append
        for level in bins.keys():
            items = bins[level]
            for id in items:
                add(id)
        return sorted_ids

    def report(self):
        self.report_new()
        self.report_old()
        self.report_asn_diff()

    def getUrl(self, url):
        try:
            data = urllib.urlopen(url)  # open file by url
            return data.read()

        except IOError, error_code:  # catch the error
            if error_code[0] == "http error":
                print "error: ", error_code[1]
Example #7
0
 def __init__(self, path):
     UserDict.__init__(self)
     self.NSES = StdDocument(NSESpath)
     self.groups = SubjectGroupMap()
     self._init_pool()