示例#1
0
 def _do_check(self, rdp):
     if rdp.metadata.publicationYear is None:
         return MetricResult(
             sys.float_info.min,
             "No publicationYear retrievable",
             False
         )
     return MetricResult(rdp.metadata.publicationYear, "", True)
示例#2
0
    def _do_check(self, rdp):
        factors = {
            "k": 2 ** 10,
            "m": 2 ** 20,
            "g": 2 ** 30,
            "t": 2 ** 40,
            "p": 2 ** 50,
            "e": 2 ** 60,
            "z": 2 ** 70,
            "y": 2 ** 80
        }
        size = 0

        # Try metadata fields
        for s in rdp.metadata.sizes:
            m = re.match(r"(^\d+)\s*(k|m|g|t|p|e|z|y){0,1}i{0,1}b$", s, re.IGNORECASE)
            # groups() allows to set a default value, but the index of the
            # returned tuple is 0-based!
            if m:
                size += int(m.group(1)) * factors.get(m.groups("")[1].lower(), 1)
        if size > 0:
            return MetricResult(size, "Used metadata", True)

        # Try headers
        try:
            for service_name in rdp.services:
                service  = rdp.services.get(service_name)
                if service.can(RetrieveDataHttpHeaders()):
                    for headers in service.get_headers(rdp.pid):
                        size += int(headers["Content-Length"])
                if size > 0:
                    return MetricResult(size, "Used headers", True)
        except ValueError as e:
            return MetricResult(-1, str(e), False)

        return MetricResult(sys.float_info.min, "Could not determine size", False)
示例#3
0
 def _do_check(self, rdp):
     for d in rdp.metadata.dates:
         if d.type == "Issued":
             return MetricResult(d.date.year, "", True)
     return MetricResult(sys.float_info.min, "No IssueDate retrievable", False)
示例#4
0
 def _do_check(self, rdp):
         return MetricResult(len(rdp.metadata.sizes), "", True)
示例#5
0
 def _do_check(self, rdp):
     return MetricResult(len(rdp.metadata.descriptions), "", True)
示例#6
0
 def _do_check(self, rdp):
     if not rdp.metadata.titles:
         msg = "No titles could be retrieved"
         return MetricResult(float(0), msg, True)
     return MetricResult(len(rdp.metadata.titles), "", True)