Example #1
0
 def report_config(self):
     config = dict(
         domain=self.domain,
         ppt_year=self.request.GET.get('year', ''),
         value_chain=self.request.GET.get('type_value_chain', ''),
         domains=tuple(self.request.GET.getlist('type_domain', [])),
         practices=tuple(self.request.GET.getlist('type_practice', [])),
         cbt_name=self.request.GET.get('cbt_name', ''),
         gender=self.request.GET.get('gender', ''),
         group_leadership=self.request.GET.get('group_leadership', ''),
         schedule=self.request.GET.getlist('farmer_social_category', []),
         none=0,
         some=1,
         all=2,
         test='test',
         duplicate='duplicate',
     )
     hierarchy_config = get_domain_configuration(
         self.domain).geography_hierarchy
     for k, v in sorted(hierarchy_config.iteritems(), reverse=True):
         req_prop = 'geography_%s' % v['prop']
         if self.request.GET.getlist(req_prop, []) not in [[], ['0']]:
             config.update(
                 {k: tuple(self.request.GET.getlist(req_prop, []))})
             break
     return config
Example #2
0
 def report_config(self):
     config = dict(
         domain=self.domain,
         ppt_year=self.request.GET.get('year', ''),
         value_chain=self.request.GET.get('type_value_chain', ''),
         domains=tuple(self.request.GET.getlist('type_domain', [])),
         practices=tuple(self.request.GET.getlist('type_practice', [])),
         cbt_name=self.request.GET.getlist('cbt_name', []),
         gender=self.request.GET.get('gender', ''),
         group_leadership=self.request.GET.get('group_leadership', ''),
         schedule=self.request.GET.getlist('farmer_social_category', []),
         none=0,
         some=1,
         all=2,
         test='test',
         duplicate='duplicate',
         real_or_test=self.request.GET.get('real_or_test', '')
     )
     hierarchy_config = get_domain_configuration(self.domain).geography_hierarchy
     for k, v in sorted(six.iteritems(hierarchy_config), reverse=True):
         req_prop = 'geography_%s' % v['prop']
         if self.request.GET.getlist(req_prop, []) not in [[], ['0']]:
             config.update({k: tuple(self.request.GET.getlist(req_prop, []))})
             break
     return config
Example #3
0
 def __init__(self, domain, config, request_params):
     self.domain = domain
     self.geography_config = get_domain_configuration(
         domain)['geography_hierarchy']
     self.config = config
     self.request_params = self.filter_request_params(request_params)
     super(CareSqlData, self).__init__(config=config)
Example #4
0
    def drilldown_map(self):
        hierarchy = helper = []
        hierarchy_config = sorted([
            k for k in get_domain_configuration(
                self.request.domain).geography_hierarchy.keys()
        ])
        data = GeographySqlData(self.request.domain).get_data()
        for val in data:
            for lvl in hierarchy_config:
                tmp = dict(val=val[lvl], text=val[lvl], next=[])
                tmp_next = []
                exist = False
                for item in hierarchy:
                    if item['val'] == val[lvl]:
                        exist = True
                        tmp_next = item['next']
                        break
                if not exist:
                    if not hierarchy:
                        hierarchy.append(dict(val='0', text='All', next=[]))
                    hierarchy.append(tmp)
                    hierarchy = tmp['next']
                else:
                    hierarchy = tmp_next
            hierarchy = helper

        return hierarchy
Example #5
0
    def drilldown_map(self):
        hierarchy_config = get_domain_configuration(self.request.domain)['by_type_hierarchy']
        for value_chain in hierarchy_config:
            value_chain.next.insert(0, ByTypeHierarchyRecord(val='0', text='All', next=[]))
            for domain in value_chain.next:
                domain.next.insert(0, ByTypeHierarchyRecord(val='0', text='All', next=[]))

        return hierarchy_config
Example #6
0
    def drilldown_map(self):
        hierarchy_config = get_domain_configuration(self.request.domain)['by_type_hierarchy']
        for value_chain in hierarchy_config:
            value_chain.next.insert(0, ByTypeHierarchyRecord(val='0', text='All', next=[]))
            for domain in value_chain.next:
                domain.next.insert(0, ByTypeHierarchyRecord(val='0', text='All', next=[]))

        return hierarchy_config
Example #7
0
 def value(self, case):
     config = get_domain_configuration(case.domain).by_type_hierarchy
     for chain in config:
         if chain.val == (case["crop_id"] or "").lower():
             for domain in chain.next:
                 for practice in domain.next:
                     ppt_prop = case.get_case_property(practice.val)
                     yield {
                         "date": case.opened_on,
                         "value": 1 if ppt_prop == "Y" else 0,
                         "group_by": [case.domain, chain.val, domain.val, practice.val],
                     }
Example #8
0
 def value(self, case):
     config = get_domain_configuration(case.domain).by_type_hierarchy
     for chain in config:
         if chain.val == (case['crop_id'] or '').lower():
             for domain in chain.next:
                 for practice in domain.next:
                     ppt_prop = case.get_case_property(practice.val)
                     yield {
                         'date': case.opened_on,
                         'value': 1 if ppt_prop == 'Y' else 0,
                         'group_by': [case.domain, chain.val, domain.val, practice.val]
                     }
Example #9
0
    def drilldown_map(self):
        hierarchy = helper = []
        hierarchy_config = sorted([k for k in get_domain_configuration(self.request.domain).geography_hierarchy.keys()])
        data = GeographySqlData(self.request.domain).get_data()
        for val in data:
            for lvl in hierarchy_config:
                tmp = dict(val=val[lvl], text=val[lvl], next=[])
                tmp_next = []
                exist = False
                for item in hierarchy:
                    if item['val'] == val[lvl]:
                        exist = True
                        tmp_next = item['next']
                        break
                if not exist:
                    hierarchy.append(tmp)
                    hierarchy = tmp['next']
                else:
                    hierarchy = tmp_next
            hierarchy = helper

        return hierarchy
Example #10
0
 def __init__(self, domain, config, request_params):
     self.domain = domain
     self.geography_config = get_domain_configuration(domain)['geography_hierarchy']
     self.config = config
     self.request_params = self.filter_request_params(request_params)
     super(CareSqlData, self).__init__(config=config)
Example #11
0
 def get_labels(self):
     return [(v['name'], v['prop']) for k, v in sorted(
         six.iteritems(
             get_domain_configuration(
                 self.request.domain).geography_hierarchy))]
Example #12
0
 def __init__(self, domain):
     self.geography_config = get_domain_configuration(
         domain)['geography_hierarchy']
     self.config = dict(domain=domain, empty='')
Example #13
0
def get_domains_with_next(case):
    configuration = get_domain_configuration(case.domain).by_type_hierarchy
    domains = []
    for chain in configuration:
        domains.extend(chain.next)
    return domains
Example #14
0
def get_mapping(case):
    value_chains = get_domain_configuration(case.domain).by_type_hierarchy
    return list({vc.val for vc in value_chains})
Example #15
0
def get_property(case, property):
    configuration = get_domain_configuration(case.domain)
    if property in configuration.geography_hierarchy:
        result = case.get_case_property(configuration.geography_hierarchy[property]["prop"])
        return result.lower() if result else result
    return None
Example #16
0
 def drilldown_map(self):
     hierarchy_config = get_domain_configuration(self.request.domain)['by_type_hierarchy']
     return hierarchy_config
Example #17
0
 def __init__(self, domain):
     self.geography_config = get_domain_configuration(domain)['geography_hierarchy']
     self.config = dict(domain=domain, empty='')
Example #18
0
 def get_labels(self):
     return [(v['name'], v['prop']) for k, v in sorted(get_domain_configuration(
         self.request.domain).geography_hierarchy.iteritems())]