Created
September 2, 2022 15:48
-
-
Save Zmey56/919f524574b33d2229057ed31576158b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_plot(data_feed, data_msg, data_dau_all, data_new_users): | |
data = pd.merge(data_feed, data_msg, on='date') | |
data = pd.merge(data, data_dau_all, on='date') | |
data = pd.merge(data, data_new_users, on='date') | |
data['events_app'] = data['events']+data['msg'] | |
plt_obj_all = [] | |
fig, axes = plt.subplots(3, figsize = (10, 14)) | |
fig.suptitle('Statistics for the entire application for 7 days') | |
app_dict = {0:{'y': ['events_app'], 'title': 'Events'}, | |
1:{'y': ['users', 'users_ios', 'users_and'], 'title': 'DAU'}, | |
2:{'y': ['users', 'new_users_ads', 'new_users_organic'], 'title': 'New users'} | |
} | |
for i in range(3): | |
for y in app_dict[i]['y']: | |
sns.lineplot(ax=axes[i], data=data, x='date', y=y) | |
axes[i].set_title(app_dict[(i)]['title']) | |
axes[i].set_xlabel(None) | |
axes[i].set_ylabel(None) | |
axes[i].legend(app_dict[i]['y']) | |
for ind, label in enumerate(axes[i].get_xticklabels()): | |
if ind % 3 == 0: | |
label.set_visible(True) | |
else: | |
label.set_visible(False) | |
plt_obj = io.BytesIO() | |
plt.savefig(plt_obj) | |
plt_obj.name = 'app_stat.png' | |
plt_obj.seek(0) | |
plt.close() | |
plt_obj_all.append(plt_obj) | |
#feed | |
fig, axes = plt.subplots(2, 2, figsize=(15, 14)) | |
fig.suptitle('Statistics on the application feed for 7 days') | |
plot_dict = {(0, 0): {'y': 'users_feed', 'title': 'Unique users'}, | |
(0, 1): {'y': 'likes', 'title': 'Likes'}, | |
(1, 0): {'y': 'views', 'title': 'Views'}, | |
(1, 1): {'y': 'CTR', 'title': 'CTR'}} | |
for i in range(2): | |
for j in range(2): | |
sns.lineplot(ax=axes[i, j], data=data, x='date', y=plot_dict[(i, j)]['y']) | |
axes[i, j].set_title(plot_dict[(i, j)]['title']) | |
axes[i, j].set_xlabel(None) | |
axes[i, j].set_ylabel(None) | |
for ind, label in enumerate(axes[i, j].get_xticklabels()): | |
if ind % 3 == 0: | |
label.set_visible(True) | |
else: | |
label.set_visible(False) | |
plt_obj = io.BytesIO() | |
plt.savefig(plt_obj) | |
plt_obj.name = 'feed_stat.png' | |
plt_obj.seek(0) | |
plt.close() | |
plt_obj_all.append(plt_obj) | |
#messenger | |
fig, axes = plt.subplots(3, figsize=(10, 14)) | |
fig.suptitle('Messenger app statistics for 7 days') | |
msg_dict = {0: {'y': 'users_msg', 'title': 'DAU'}, | |
1: {'y': 'msg', 'title': 'Messages'}, | |
2: {'y': 'mpu', 'title': 'Messages per user'} | |
} | |
for i in range(3): | |
sns.lineplot(ax=axes[i], data=data, x='date', y=msg_dict[i]['y']) | |
axes[i].set_title(msg_dict[(i)]['title']) | |
axes[i].set_xlabel(None) | |
axes[i].set_ylabel(None) | |
for ind, label in enumerate(axes[i].get_xticklabels()): | |
if ind % 3 == 0: | |
label.set_visible(True) | |
else: | |
label.set_visible(False) | |
plt_obj = io.BytesIO() | |
plt.savefig(plt_obj) | |
plt_obj.name = 'msg_stat.png' | |
plt_obj.seek(0) | |
plt.close() | |
plt_obj_all.append(plt_obj) | |
return plt_obj_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment