Exemple #1
0
 def _set_data_for_table(self):
     if hasattr(self, '_data_for_table'):
         return
     dbm = get_db_manager(
         server=settings.MANGROVE_DATABASES['default']['SERVER'],
         database=settings.MANGROVE_DATABASES['default']['DATABASE'])
     sector_to_facility = {
         'health': 'Health Clinic',
         'education': 'School',
         'water': 'Water Point'
     }
     facility_type = sector_to_facility[self._sector]
     facilities = get_entities_in(dbm, self._region_thing.entity.location_path, facility_type)
     slugs = [header.slug for header in self._headers]
     result = []
     for facility in facilities:
         data = facility.get_all_data()
         times = data.keys()
         times.sort()
         # get the latest data
         latest_data = data[times[-1]]
         self._add_calculated_sector_indicators(latest_data)
         d = dict([(slug, latest_data[slug]) for slug in slugs])
         d.update(
             {
                 'sector': self._sector,
                 'facility_type': facility_type,
                 'latlng': facility.geometry['coordinates'],
                 'img_id': latest_data['photo']
                 }
             )
         result.append(d)
     self._data_for_table = result
Exemple #2
0
 def _set_data_for_table(self):
     if hasattr(self, '_data_for_table'):
         return
     dbm = get_db_manager(
         server=settings.MANGROVE_DATABASES['default']['SERVER'],
         database=settings.MANGROVE_DATABASES['default']['DATABASE'])
     sector_to_facility = {
         'health': 'Health Clinic',
         'education': 'School',
         'water': 'Water Point'
     }
     facility_type = sector_to_facility[self._sector]
     facilities = get_entities_in(dbm,
                                  self._region_thing.entity.location_path,
                                  facility_type)
     slugs = [header.slug for header in self._headers]
     result = []
     for facility in facilities:
         data = facility.get_all_data()
         times = data.keys()
         times.sort()
         # get the latest data
         latest_data = data[times[-1]]
         self._add_calculated_sector_indicators(latest_data)
         d = dict([(slug, latest_data[slug]) for slug in slugs])
         d.update({
             'sector': self._sector,
             'facility_type': facility_type,
             'latlng': facility.geometry['coordinates'],
             'img_id': latest_data['photo']
         })
         result.append(d)
     self._data_for_table = result
Exemple #3
0
def load_nigeria_regions_to_file():
    dbm = DatabaseManager(
        server=settings.MANGROVE_DATABASES['default']['SERVER'],
        database=settings.MANGROVE_DATABASES['default']['DATABASE']
        )
    country = get_entities_by_type(dbm, 'Country')[0]
    country_name = country.aggregation_paths['_geo'][-1]
    country_slug = slugify(country_name)
    country_region_thing = RegionThing(
        name=country_name,
        slug=country_slug,
        entity_id=country.id,
        server=dbm.server,
        database=dbm.database_name
    )
    states = get_entities_in(dbm, country.aggregation_paths['_geo'], 'State')
    for state in states:
        state_name = state.aggregation_paths['_geo'][-1]
        state_slug = slugify(state_name)
        state_region_thing = RegionThing(
            name=state_name,
            slug=state_slug,
            entity_id=state.id,
            server=dbm.server,
            database=dbm.database_name
        )
        lgas = get_entities_in(dbm, state.aggregation_paths['_geo'], 'LGA')
        for lga in lgas:
            lga_name = lga.aggregation_paths['_geo'][-1]
            lga_slug = slugify(lga_name)
            lga_region_thing = RegionThing(
                name=lga_name,
                slug=lga_slug,
                entity_id=lga.id,
                server=dbm.server,
                database=dbm.database_name
            )
            state_region_thing._set_subregions([lga_region_thing])
        country_region_thing._set_subregions([state_region_thing])
    dict_repr = country_region_thing.export_to_dict()
    json_val = json.dumps(dict_repr)
    f = open(NIGERIA_REGION_CACHE, 'w')
    f.write(json_val)
    f.close()