Exemplo n.º 1
0
 def combine(vals):
     nums = [v for v in vals if isinstance(v, int)]
     if nums:
         res = sum(nums)
         return fdd(res, res)
     else:
         return fdd(vals[0], vals[0])
Exemplo n.º 2
0
 def combine(vals):
     nums = [v for v in vals if isinstance(v, int)]
     if nums:
         res = sum(nums)
         return fdd(res, res)
     else:
         val = vals[0]
         if val is None:
             val = NO_VALUE
         return fdd(val, val)
Exemplo n.º 3
0
    def rows(self):
        reduce_fn = fn.sum()
        startkey, endkey = self.start_and_end_keys

        row_dict = {}

        for key in self.keys:
            row = get_db().view("care_benin/danger_signs",
                                startkey=key + [startkey],
                                endkey=key + [endkey, {}],
                                reduce=True,
                                wrapper=lambda r: r['value']
            )

            row = row.first()
            val = reduce_fn(row)

            cols = row_dict.setdefault(
                key[1],
                {
                    'danger_sign_count_pregnancy': [],
                    'danger_sign_count_accouchee': [],
                    'danger_sign_count_birth': [],
                }
            )
            if val != NO_VALUE:
                cols[key[0]].append(val)

        for sign, cols in row_dict.items():
            pregnancy = sum(cols['danger_sign_count_pregnancy'])
            accouchee = sum(cols['danger_sign_count_accouchee'])
            birth = sum(cols['danger_sign_count_birth'])
            yield [
                sign,
                fdd(pregnancy, pregnancy),
                fdd(accouchee, accouchee),
                fdd(birth, birth)
            ]
Exemplo n.º 4
0
    def rows(self):
        reduce_fn = fn.sum()
        startkey, endkey = self.start_and_end_keys

        for key in self.keys:
            row = get_db().view("care_benin/danger_signs",
                                startkey=['danger_sign', key, startkey],
                                endkey=['danger_sign', key, endkey, {}],
                                reduce=True,
                                wrapper=lambda r: r['value']
            )

            row = row.first()
            val = reduce_fn(row)
            yield [key, fdd(val, val)]
Exemplo n.º 5
0
 def rows(self):
     db = get_db()
     startkey, endkey = self.start_and_end_keys
     for row in self.row_list:
         value = row["view"].get_value([], startkey=startkey, endkey=endkey, couch_view=self.couch_view, db=db)
         yield [row["name"], fdd(value, value)]