Example #1
0
    def stock(self, country, month=None):
        stockout_yes = stockout_no = 0

        sections_with_medicines = self._get_medicine_sections_with_medicine_available(country, month)
        stockout_values = [section.medicine_available for section in sections_with_medicines]
        stocked_yes = count(stockout_values, lambda x : x.lower() == "yes")
        stocked_no = count(stockout_values, lambda x : x.lower() == "no")

        #Note all integer math. Will be percentage rounded down to whole.
        return self._perc_yes(stocked_yes, stocked_no)
Example #2
0
    def stockout_days(self, country, month=None):
        sections_with_packs = self._get_medicine_sections_with_packs(country, month)
        is_stockout = lambda section : int(section.packs_available) == 0
        zero_levels = filter(is_stockout, sections_with_packs)

        total_days = sum(VALUE_TO_DAYS[section.stockout_duration] for section in zero_levels)
        facilities = count(zero_levels, lambda section : VALUE_TO_DAYS[section.stockout_duration] > 0)

        return self._safe_div(total_days, facilities)
Example #3
0
    def level(self, country, month=None):
        total_level = facilities = 0
        sections_with_packs = self._get_medicine_sections_with_packs(country, month)
        packs_available_values = [int(section.packs_available) for section in sections_with_packs]

        total_level = sum(v for v in packs_available_values if v not in [8888, 9999] )
        facilities = count(packs_available_values, lambda x : x > 0)

        return self._safe_div(total_level, facilities)
Example #4
0
    def stocked(self, country, month=None):
        stocked_yes = stocked_no = 0
        forms = self._medicines_by_country_and_month(country, month)
        tag_name = self._medicine_tag_name().replace("medicine-", "")

        stocked_sections = [
            getattr(form.submission.content, "section_stocked")
            for form in forms
            if form.submission.content and hasattr(form.submission.content, "section_stocked")
        ]

        stock_values = [
            getattr(section, tag_name)
            for section in stocked_sections
            if hasattr(section, tag_name)
        ] 

        stocked_yes = count(stock_values, lambda x : x.lower() == "yes")
        stocked_no = count(stock_values, lambda x : x.lower() == "no")
        
        return self._perc_yes(stocked_yes, stocked_no)