def summary(start_date: date, end_date: date, region: str, df: pd.DataFrame): population = population_data[region] summary = Stats(population=population) filter = Filters() filter.add_interval(start_date, end_date) current_df = query(df, filter) casos = current_df.shape[0] filter.add_dead(True) muertes = query(current_df, filter).shape[0] summary.add_casos_muertes(casos, muertes) return summary
def summary_history(start_date: date, end_date: date, region: str, df: pd.DataFrame): population = population_data[region] current_date = start_date summaries = [StatsHistorial(date=current_date, population=population)] while current_date <= end_date: summary = StatsHistorial(date=current_date, population=population) summary.add_population(population) filter = Filters() filter.add_date(current_date) current_df = query(df, filter) casos = current_df.shape[0] filter.add_dead(True) muertes = query(current_df, filter).shape[0] summary.add_casos_muertes_acc(casos, summaries[-1].casos_acc + casos, muertes, summaries[-1].muertes_acc + muertes) summaries.append(summary) current_date = current_date + delta return summaries[1:]
def get(self): args = filters_get_args.parse_args() filters = Filters() filters.add_interval(start_date=args.get('desde'), end_date=args.get('hasta')) filters.add_icu(icu=args.get('cui')) filters.add_dead(dead=args.get('muertos')) filters.add_respirator(respirator=args.get('respirador')) filters.add_classification(classification=args.get('classificacion')) filters.add_gender(args.get('sexo')) filters.add_age_interval(args.get('min_edad'), args.get('max_edad')) filters.add_year_month(args.get('anios_meses')) filters.add_province(args.get('region')) return Cantidad(query(df, filters).shape[0])
def get(self): args = filters_get_args.parse_args() print(args) filters = Filters() filters.add_interval(start_date=args.get('desde'), end_date=args.get('hasta')) filters.add_icu(icu=args.get('cui')) filters.add_dead(dead=args.get('muertos')) filters.add_respirator(respirator=args.get('respirador')) filters.add_classification(classification=args.get('classificacion')) filters.add_gender(args.get('sexo')) filters.add_age_interval(args.get('min_edad'), args.get('max_edad')) filters.add_year_month(args.get('anios_meses')) filters.add_province(province=args.get('region')) result = query(df, filters) p_val = pUtf8[ filters. province] if filters.province is not None else pUtf8['nacional'] if filters.start_date is not None and filters.end_date is not None: ret = summary(filters.start_date, filters.end_date, p_val, result) else: ret = summary(date(year=2020, month=1, day=1), date.today(), p_val, result) return ret