def handle(self, *args, **options): geocodes = list(dict(dbdata.get_all_active_cities()).keys()) _static_root = os.path.abspath(settings.STATIC_ROOT) _static_dirs = os.path.abspath(settings.STATICFILES_DIRS[0]) path_root = ( _static_root if os.path.exists(_static_root) else _static_dirs ) f_geojson_path = os.path.join(path_root, 'geojson') f_shapefile_path = os.path.join(path_root, 'shapefile') if not os.path.exists(f_geojson_path): os.mkdir(f_geojson_path, mode=0o777) if not os.path.exists(f_shapefile_path): os.mkdir(f_shapefile_path, mode=0o777) geo_info = {} for geocode in geocodes: self.create_geojson(f_geojson_path, geocode) self.create_shapefile(path_root, geocode) geo_info.update(self.extract_geo_info_table( path_root, geocode )) with open(os.path.join(f_geojson_path, 'geo_info.json'), 'w') as f: json.dump(geo_info, f) print('[II] Geo Info JSON saved!') print('[II] DONE!')
def handle(self, *args, **options): geocodes = list(dict(dbdata.get_all_active_cities()).keys()) _static_root = os.path.abspath(settings.STATIC_ROOT) _static_dirs = os.path.abspath(settings.STATICFILES_DIRS[0]) path_root = (_static_root if os.path.exists(_static_root) else _static_dirs) f_geojson_path = os.path.join(path_root, 'geojson') f_geojson_simplified_path = os.path.join(path_root, 'geojson_simplified') f_shapefile_path = os.path.join(path_root, 'shapefile') if not os.path.exists(f_geojson_path): os.mkdir(f_geojson_path, mode=0o777) if not os.path.exists(f_shapefile_path): os.mkdir(f_shapefile_path, mode=0o777) geo_info = {} for geocode in geocodes: self.create_geojson(f_geojson_path, geocode) self.create_shapefile(path_root, geocode) self.simplify_geojson(path_root, geocode) geo_info.update(self.extract_geo_info_table(path_root, geocode)) self.create_geojson_by_state(f_geojson_simplified_path) with open(os.path.join(f_geojson_path, 'geo_info.json'), 'w') as f: json.dump(geo_info, f) print('[II] Geo Info JSON saved!') print('[II] DONE!')
def get_context_data(self, **kwargs): context = super(AlertaMainView, self).get_context_data(**kwargs) mundict = dict(dbdata.get_all_active_cities()) municipios, geocodigos = list(mundict.values()), list(mundict.keys()) alerta = {} case_series = {} total = np.zeros(52, dtype=int) for gc in geocodigos: dados = dbdata.get_city_alert(gc, 'dengue') alerta[gc] = int(dados[0]) case_series[str(gc)] = list(map(int, dados[2][-12:])) total += dados[2][-52:] context.update({ 'mundict': json.dumps(mundict), 'municipios': municipios, 'geocodigos': geocodigos, 'alerta': json.dumps(alerta), 'case_series': json.dumps(case_series), 'total': json.dumps(total.tolist()), }) return context
def get_context_data(self, **kwargs): context = super(AlertaMainView, self).get_context_data(**kwargs) mundict = dict(dbdata.get_all_active_cities()) municipios, geocodigos = list(mundict.values()), list(mundict.keys()) alerta = {} case_series = {} total = np.zeros(52, dtype=int) for gc in geocodigos: dados = dbdata.get_city_alert(gc, 'dengue') alerta[gc] = int(dados[0]) case_series[str(gc)] = list(map(int, dados[2][-12:])) total += dados[2][-52:] context.update({ 'mundict': json.dumps(mundict), 'num_mun': len(mundict), 'municipios': municipios, 'geocodigos': geocodigos, 'alerta': json.dumps(alerta), 'case_series': json.dumps(case_series), 'total': json.dumps(total.tolist()), }) return context
def handle(self, *args, **options): geo_ids = list(dict(dbdata.get_all_active_cities()).keys()) _static_root = os.path.abspath(settings.STATIC_ROOT) _static_dirs = os.path.abspath(settings.STATICFILES_DIRS[0]) path_root = (_static_root if os.path.exists(_static_root) else _static_dirs) f_geojson_path = os.path.join(path_root, 'geojson') f_shapefile_path = os.path.join(path_root, 'shapefile') if not os.path.exists(f_geojson_path): os.mkdir(f_geojson_path, mode=0o777) if not os.path.exists(f_shapefile_path): os.mkdir(f_shapefile_path, mode=0o777) for geo_id in geo_ids: self.create_geojson(f_geojson_path, geo_id) self.create_shapefile(path_root, geo_id) print('Done.')
def test_get_active_cities(self): muns = dbdata.get_all_active_cities() self.assertIsInstance(muns, list) self.assertGreater(len(muns), 0) self.assertIn((3303302, 'Niterói'), muns)
def get_context_data(self, **kwargs): context = super(AlertaMainView, self).get_context_data(**kwargs) diseases = ('dengue', 'chikungunya') n_alerts_chik = dbdata.get_n_chik_alerts() # today last_se = {} case_series = defaultdict(dict) case_series_state = defaultdict(dict) count_cities = defaultdict(dict) current_week = defaultdict(dict) estimated_cases_next_week = defaultdict(dict) variation_to_current_week = defaultdict(dict) variation_4_weeks = defaultdict(dict) v1_week_fixed = defaultdict(dict) v1_4week_fixed = defaultdict(dict) notif_resume = dbdata.NotificationResume mundict = dict(dbdata.get_all_active_cities()) # municipios, geocodigos = list(mundict.values()), list(mundict.keys()) # results[d] = dbdata.load_serie_cities(geocodigos, d) for d in diseases: case_series[d] = dbdata.get_series_by_UF(d) for s in self._state_names: df = case_series[d] # alias df_state = df[df.uf == s] cases = df_state.casos_s.values # cases estimation cases_est = df_state.casos_est_s.values case_series_state[d][s] = cases[:-52] if d == 'dengue': if not df_state.empty: last_se[s] = df_state.tail(1).data.iloc[0] else: last_se[s] = '' count_cities[d][s] = notif_resume.count_cities_by_uf(s, d) current_week[d][s] = { 'casos': cases[-1] if cases.size else 0, 'casos_est': cases_est[-1] if cases_est.size else 0 } estimated_cases_next_week[d][s] = gettext('Em breve') v1 = cases_est[-2] if cases_est.size else 0 v2 = cases_est[-1] if cases_est.size else 0 v1_week_fixed[d][s] = v1 == 0 and v2 != 0 variation_to_current_week[d][s] = variation_p(v1, v2) if cases_est.size < 55: variation_4_weeks[d][s] = 0 else: v2 = cases_est[-4:-1].sum() v1 = cases_est[-55:-52].sum() v1_4week_fixed[d][s] = v1 == 0 and v2 != 0 variation_4_weeks[d][s] = variation_p(v1, v2) context.update({ # 'mundict': json.dumps(mundict), 'num_mun': len(mundict), # 'municipios': municipios, # 'geocodigos': geocodigos, # 'alerta': json.dumps(alerta), 'diseases': diseases, 'case_series': case_series, #'total': json.dumps(total.tolist()), 'states': self._state_names, 'count_cities': count_cities, 'current_week': current_week, 'estimated_cases_next_week': estimated_cases_next_week, 'variation_to_current_week': variation_to_current_week, 'variation_4_weeks': variation_4_weeks, 'state_initials': self._state_initials, 'n_alerts_chik': n_alerts_chik, 'last_se': last_se }) return context