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)]
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) ]