fix errors

This commit is contained in:
Alexis REVELLE 2024-03-20 08:33:56 +00:00
parent 0a41641956
commit 95c4c6c4bf
2 changed files with 28 additions and 12 deletions

View File

@ -17,7 +17,7 @@ S3_ENDPOINT_URL = "https://" + os.environ["AWS_S3_ENDPOINT"]
fs = s3fs.S3FileSystem(client_kwargs={'endpoint_url': S3_ENDPOINT_URL}) fs = s3fs.S3FileSystem(client_kwargs={'endpoint_url': S3_ENDPOINT_URL})
companies = {'musee' : ['1', '2', '3', '4'], # , '101' companies = {'musee' : ['1', '2', '3', '4'], # , '101'
'sport': ['5', '6', '7', '8', '9'], 'sport': ['5'],#, '6', '7', '8', '9'],
'musique' : ['10', '11', '12', '13', '14']} 'musique' : ['10', '11', '12', '13', '14']}

View File

@ -24,7 +24,7 @@ def load_files(nb_compagnie):
df_products_purchased_reduced = display_input_databases(directory_path, file_name = "products_purchased_reduced", datetime_col = ['purchase_date']) df_products_purchased_reduced = display_input_databases(directory_path, file_name = "products_purchased_reduced", datetime_col = ['purchase_date'])
df_target_information = display_input_databases(directory_path, file_name = "target_information") df_target_information = display_input_databases(directory_path, file_name = "target_information")
df_campaigns_kpi = campaigns_kpi_function(campaigns_information = df_campaigns_brut) df_campaigns_kpi = campaigns_kpi_function(campaigns_information = df_campaigns_brut, max_date=pd.Timestamp.now(tz='UTC'))
df_tickets_kpi = tickets_kpi_function(tickets_information = df_products_purchased_reduced) df_tickets_kpi = tickets_kpi_function(tickets_information = df_products_purchased_reduced)
df_customerplus_clean = customerplus_kpi_function(customerplus_clean = df_customerplus_clean_0) df_customerplus_clean = customerplus_kpi_function(customerplus_clean = df_customerplus_clean_0)
@ -231,15 +231,32 @@ def lazy_customer_plot(campaigns_kpi, type_of_activity):
def campaigns_effectiveness(customer, type_of_activity): def campaigns_effectiveness(customer, type_of_activity):
campaigns_effectiveness = customer.groupby("number_company")["opt_in"].mean().reset_index() campaigns_effectiveness = customer.groupby(["number_company", "has_purchased_target_period"])["opt_in"].mean().reset_index()
plt.bar(campaigns_effectiveness["number_company"], campaigns_effectiveness["opt_in"]) fig, ax = plt.subplots(figsize=(10, 6))
plt.xlabel('Company') categories = campaigns_effectiveness["number_company"].unique()
plt.ylabel("Number of Customers (thousands)") bar_width = 0.35
plt.title(f"Number of Customers of have bought or have received mails for {type_of_activity}") bar_positions = np.arange(len(categories))
plt.legend()
plt.xticks(campaigns_effectiveness["number_company"], ["{}".format(i) for i in campaigns_effectiveness["number_company"]]) # Grouper les données par label et créer les barres groupées
for label in campaigns_effectiveness["has_purchased_target_period"].unique():
label_data = campaigns_effectiveness[campaigns_effectiveness['has_purchased_target_period'] == label]
values = [label_data[label_data['number_company'] == category]['opt_in'].values[0]*100 for category in categories]
label_printed = "purchased" if label else "no purchase"
ax.bar(bar_positions, values, bar_width, label=label_printed)
# Mise à jour des positions des barres pour le prochain groupe
bar_positions = [pos + bar_width for pos in bar_positions]
# Ajout des étiquettes, de la légende, etc.
ax.set_xlabel('Company')
ax.set_ylabel('Consent')
ax.set_title(f"Number of Customers who have consent to received mails for {type_of_activity} dependy on target")
ax.set_xticks([pos + bar_width / 2 for pos in np.arange(len(categories))])
ax.set_xticklabels(categories)
ax.legend()
plt.show() plt.show()
save_file_s3("campaigns_effectiveness_", type_of_activity) save_file_s3("campaigns_effectiveness_", type_of_activity)
@ -304,10 +321,9 @@ def sale_dynamics(products, campaigns_brut, type_of_activity):
def tickets_internet(tickets, type_of_activity): def tickets_internet(tickets, type_of_activity):
nb_tickets_internet = tickets.groupby("number_company")[["nb_tickets", "nb_tickets_internet"]].sum().reset_index() nb_tickets_internet = tickets.groupby("number_company")['prop_purchases_internet'].mean().reset_index()
nb_tickets_internet["Share_ticket_internet"] = nb_tickets_internet["nb_tickets_internet"]*100 / nb_tickets_internet["nb_tickets"]
plt.bar(nb_tickets_internet["number_company"], nb_tickets_internet["Share_ticket_internet"]) plt.bar(nb_tickets_internet["number_company"], nb_tickets_internet["prop_purchases_internet"])
plt.xlabel('Company') plt.xlabel('Company')
plt.ylabel("Share of Tickets Bought Online") plt.ylabel("Share of Tickets Bought Online")