def tweet_france_maps(): _, _, dates, _, _, _, _, df_incid, _ = data.import_data() df_incid = df_incid[df_incid["cl_age90"] == 0] lastday_df_incid = datetime.strptime(df_incid['jour'].max(), '%Y-%m-%d') ## TWEET2 df_incid_lastday = df_incid.loc[df_incid['jour'] == df_incid['jour'].max(), :] nb_dep = len(df_incid_lastday.loc[ df_incid_lastday['incidence_color'] == 'Alerte', :]) + len( df_incid_lastday.loc[df_incid_lastday['incidence_color'] == 'Alerte Renforcée', :] ) + len(df_incid_lastday.loc[df_incid_lastday['incidence_color'] == 'Alerte Maximale', :]) images_path2 = [ PATH + "images/charts/france/dep-map-incid-cat/latest.jpeg" ] media_ids2 = [] for filename in images_path2: res = api.media_upload(filename) media_ids2.append(res.media_id) tweet2 = "🔴 {} départements devraient être classés rouge, car ils dépassent le niveau d'alerte de 50 cas pour 100 000 habitants en 7 jours (données du {})\n➡️ Plus d'infos : covidtracker.fr/covidtracker-france".format( nb_dep, lastday_df_incid.strftime('%d/%m')) api.update_status(status=tweet2, media_ids=media_ids2)
def tweet_france(): #data.download_data() _, _, dates, df_new, _, _, _, df_incid, _ = data.import_data() df_new_france = df_new.groupby(["jour"]).sum().reset_index() df_incid_france = df_incid.groupby(["jour"]).sum().reset_index() lastday_df_new = datetime.strptime(df_new_france['jour'].max(), '%Y-%m-%d') hosp = df_new_france[df_new_france['jour']==lastday_df_new.strftime('%Y-%m-%d')]['incid_hosp'].values[-1] date_j7 = (lastday_df_new - timedelta(days=7)).strftime("%Y-%m-%d") hosp_j7 = df_new_france[df_new_france['jour'] == date_j7]['incid_hosp'].values[-1] deaths = df_new_france[df_new_france['jour']==lastday_df_new.strftime('%Y-%m-%d')]['incid_dc'].values[-1] deaths_j7 = df_new_france[df_new_france['jour'] == date_j7]['incid_dc'].values[-1] lastday_df_incid = datetime.strptime(df_incid_france['jour'].max(), '%Y-%m-%d') tests = df_incid_france[df_incid_france['jour']==lastday_df_incid.strftime('%Y-%m-%d')]['P'].values[-1] date_j7_incid = (lastday_df_incid - timedelta(days=7)).strftime("%Y-%m-%d") tests_j7 = df_incid_france[df_incid_france['jour'] == date_j7_incid]['P'].values[-1] date = datetime.strptime(dates[-1], '%Y-%m-%d').strftime('%d %B') hosp_tendance, hosp_sign = "en hausse", "+" if hosp_j7>hosp: hosp_tendance, hosp_sign = "en baisse", "" if hosp_j7==hosp: hosp_tendance, hosp_sign = "stable", "+" deaths_tendance, deaths_sign = "en hausse", "+" if deaths_j7>deaths: deaths_tendance, deaths_sign = "en baisse", "" if deaths_j7==deaths: deaths_tendance, deaths_sign = "stable", "+" tests_tendance, tests_sign = "en hausse", "+" if tests_j7>tests: tests_tendance, tests_sign = "en baisse", "" if tests_j7==tests: tests_tendance, tests_sign = "stable", "+" date_incid = datetime.strptime(sorted(list(dict.fromkeys(list(df_incid_france['jour'].values))))[-1], '%Y-%m-%d').strftime('%d %B') tweet ="Chiffres #Covid19 France :\n• {} personnes décédées en milieu hospitalier ({}), {} sur 7 jours ({}{})\n• {} admissions à l'hôpital ({}), {} sur 7 jours ({}{})\n• {} cas positifs ({}), {} sur 7 jours ({}{})\n➡️ Plus d'infos : covidtracker.fr/covidtracker-france".format(deaths, lastday_df_new.strftime('%d/%m'), deaths_tendance, deaths_sign, deaths-deaths_j7, hosp, lastday_df_new.strftime('%d/%m'), hosp_tendance, hosp_sign, hosp-hosp_j7, tests, lastday_df_incid.strftime('%d/%m'), tests_tendance, tests_sign, tests-tests_j7) # toDo images_path =["images/charts/france/var_journ_lines_recent.jpeg", "images/charts/france/entrees_sorties_hosp_rea_ROLLING_recent.jpeg", "images/charts/france/dc_new_bar.jpeg", "images/charts/france/reffectif.jpeg"] media_ids = [] for filename in images_path: res = api.media_upload(filename) media_ids.append(res.media_id) # to attach the media file api.update_status(status=tweet, media_ids=media_ids)
import json import locale import france_data_management as data import numpy as np import plotly.figure_factory as ff PATH="../../" locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') now = datetime.now() # In[3]: df, df_confirmed, dates, _, _, _, _, df_incid, df_tests_viros = data.import_data() # In[4]: deps_tests = list(dict.fromkeys(list(df_tests_viros['dep'].values))) deps_name = np.array(list(dict.fromkeys(list(df["departmentName"].values)))[:]) #df_tests_viros = df_tests_viros[df_tests_viros['cl_age90'] != 0] for (name, data, title, scale_txt, data_example, digits) in [("cas", '', "Taux d'<br>incidence", " cas", " cas", 1)]: for idx,dep in enumerate(deps_tests): #deps_tests.drop("975", "976", "977", "978") locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') df_tests_viros_dep = df_tests_viros[df_tests_viros["dep"] == dep]
from tqdm import tqdm import json import plotly.express as px from datetime import datetime import imageio import multiprocessing import locale import shutil import os locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') # In[3]: # Import data from Santé publique France _, _, _, _, _, _, _, df_incid, _ = data.import_data() df_incid = df_incid[df_incid["cl_age90"] == 0] with open('data/france/dep.geojson') as response: depa = json.load(response) # In[4]: def build_map( data_df, img_folder, date_val, date_str="date", dep_str="departement", color_str='indic_synthese',
import json import plotly.express as px from datetime import datetime import imageio import multiprocessing import locale import shutil import os locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') # ## Data import # In[3]: # Import data from Santé publique France df, df_confirmed, dates, _, _, df_deconf, df_sursaud, df_incid, _ = data.import_data( ) df_incid = df_incid[df_incid["cl_age90"] == 0] # In[4]: #df_incid["incidence"] = df_incid["P"]/df_incid["pop"]*100 #df_incid.loc[:,"incidence_color"] = ["white"] * len(df_incid) for dep in pd.unique(df_incid["dep"].values): df_incid.loc[df_incid["dep"] == dep, "incidence"] = df_incid["P"].rolling( window=7).sum() / df_incid["pop"] * 100000 df_incid.loc[:, "incidence_color"] = [ 'Rouge (>50)' if x >= 50 else 'Orange (25-50)' if x >= 25 else 'Vert (<25)' for x in df_incid['incidence'] ] # In[5]:
""" # In[2]: import pandas as pd import plotly.graph_objects as go import france_data_management as data from datetime import datetime from datetime import timedelta import plotly import math import os # In[3]: df, df_confirmed, dates, df_new, df_tests, df_deconf, df_sursaud, df_incid, df_tests_viros = data.import_data( ) # In[4]: df_regions = df.groupby(["jour", "regionName"]).sum().reset_index() df_incid_regions = df_incid[df_incid["cl_age90"] == 0].groupby( ["jour", "regionName"]).sum().reset_index() regions = list(dict.fromkeys(list(df_regions['regionName'].values))) dates_incid = list(dict.fromkeys(list(df_incid['jour'].values))) last_day_plot = (datetime.strptime(max(dates), '%Y-%m-%d') + timedelta(days=1)).strftime("%Y-%m-%d") df_new_regions = df_new.groupby(["jour", "regionName"]).sum().reset_index() # In[5]: