Esempio n. 1
0
    def _extract_metrics(self, page, status_code=200, id=None):
        if status_code != 200:
            if status_code == 404:
                return {}
            else:
                raise(self._get_error(status_code))
        data = provider._load_json(page)

        metrics_dict = {}
        for section in data["article"]["source"]:
            source = provider._lookup_json(section, ["source"])
            if (source == "Counter"):
                #drilldown_url = provider._lookup_json(section["citations"][0], ["citation", "uri"])
                html_sum = self._aggregate_monthly_stats("html_views", section)
                metrics_dict["html_views"] = html_sum
                pdf_sum = self._aggregate_monthly_stats("pdf_views", section)
                metrics_dict["pdf_views"] = pdf_sum
            elif (source == "PubMed Central Usage Stats"):
                #drilldown_url = provider._lookup_json(section["citations"][0], ["citation", "uri"])
                try:
                    first_month_stats = section["events"][0]
                except KeyError:
                    logger.debug("%20s no first_month_stats for %s" % (self.provider_name, id))
                    first_month_stats = []
                for metric_name in first_month_stats:
                    normalized_metric_name = "pmc_" + self._normalize_source(metric_name)
                    if (normalized_metric_name in self.static_meta_dict.keys()):
                        total = self._aggregate_monthly_stats(metric_name, section)
                        if total:
                            metrics_dict[normalized_metric_name] = total
            elif (self._normalize_source(source) in self.static_meta_dict.keys()):
                total = provider._lookup_json(section, ["count"])
                if total:
                    #drilldown_url = provider._lookup_json(section, ["public_url"])
                    #if not drilldown_url:
                    #    drilldown_url = ""
                    metrics_dict[source] = total

        rekeyed_dict = dict(("plosalm:"+self._normalize_source(k),v) for (k,v) in metrics_dict.iteritems())

        return rekeyed_dict
Esempio n. 2
0
 def test_lookup_json(self):
     page = self.TEST_JSON
     data = simplejson.loads(page)
     response = provider._lookup_json(data, ['repository', 'name'])
     assert_equals(response, u'gtd')
Esempio n. 3
0
 def test_lookup_json(self):
     page = self.TEST_JSON
     data = simplejson.loads(page)
     response = provider._lookup_json(data, ['repository', 'name'])
     assert_equals(response, u'gtd')
 def test_lookup_json(self):
     page = self.TEST_JSON
     data = simplejson.loads(page)
     response = provider._lookup_json(data, ["repository", "name"])
     assert_equals(response, u"gtd")