def decide_if_assigned_threshold(self, person, threshold):
        countries = []

        total_geo_located_posts = 0.0
        total_global_south_posts = 0.0

        for my_product in person.products:
            for country_iso, count in my_product.post_counts_by_country.iteritems():
                total_geo_located_posts += count
                country_name = get_name_from_iso(country_iso)
                if country_name:
                    try:
                        if country_info[country_name]["is_global_south"]:
                            total_global_south_posts += count
                            self.candidate_badge.add_product(my_product)
                            countries.append(country_name)
                    except KeyError:
                        print u"ERROR: Nothing in dict for country name {}".format(country_name)
                        raise # don't keep going

        if total_geo_located_posts >= 3:
            # print u"PERCENT GLOBAL SOUTH {} / {} = {}".format(
            #     total_global_south_posts,
            #     total_geo_located_posts,
            #     (total_global_south_posts / total_geo_located_posts)
            # )
            # print u"global south countries: {}".format(countries)

            ratio = (total_global_south_posts / total_geo_located_posts)
            if ratio > threshold:
                self.assigned = True
                self.candidate_badge.value = 100.0 * ratio
                self.candidate_badge.support = "Countries include: {}.".format(
                    ", ".join(countries))
Beispiel #2
0
    def post_counts_by_country_using_mendeley(self):
        posts_by_country = {}

        if self.mendeley_api_raw and self.mendeley_api_raw["reader_count_by_country"]:
            for mendeley_country_name, count in self.mendeley_api_raw["reader_count_by_country"].iteritems():
                country_name = map_mendeley_countries.get(mendeley_country_name, mendeley_country_name)
                posts_by_country[country_name] = count

        try:
            for iso_country, count in self.altmetric_api_raw["demographics"]["geo"]["twitter"].iteritems():
                country_name = get_name_from_iso(iso_country)
                if country_name in posts_by_country:
                    posts_by_country[country_name] += count
                else:
                    posts_by_country[country_name] = count
        except (KeyError, TypeError):
            pass
        return posts_by_country
Beispiel #3
0
    def post_counts_by_country_using_mendeley(self):
        posts_by_country = {}

        if self.mendeley_api_raw and self.mendeley_api_raw["reader_count_by_country"]:
            for mendeley_country_name, count in self.mendeley_api_raw["reader_count_by_country"].iteritems():
                country_name = map_mendeley_countries.get(mendeley_country_name, mendeley_country_name)
                posts_by_country[country_name] = count

        try:
            for iso_country, count in self.altmetric_api_raw["demographics"]["geo"]["twitter"].iteritems():
                country_name = get_name_from_iso(iso_country)
                if country_name in posts_by_country:
                    posts_by_country[country_name] += count
                else:
                    posts_by_country[country_name] = count
        except (KeyError, TypeError):
            pass
        return posts_by_country
Beispiel #4
0
 def countries(self):
     return [get_name_from_iso(my_country) for my_country in self.post_counts_by_iso_country.keys()]
Beispiel #5
0
 def countries(self):
     return [
         get_name_from_iso(my_country)
         for my_country in self.post_counts_by_iso_country.keys()
     ]