Added new graph, users and mau by weeks
This commit is contained in:
pare
2e15307ce1
commit
19fb2a8185
S'han modificat 3 arxius amb 80 adicions i 4 eliminacions
|
@ -853,6 +853,12 @@ class Database():
|
|||
|
||||
global_mau = []
|
||||
|
||||
global_week = []
|
||||
|
||||
global_week_users = []
|
||||
|
||||
global_week_mau = []
|
||||
|
||||
conn = None
|
||||
|
||||
try:
|
||||
|
@ -887,6 +893,18 @@ class Database():
|
|||
|
||||
global_mau.append(row[3])
|
||||
|
||||
cur.execute("select distinct on (date_trunc('week', datetime)) datetime::TIMESTAMP::DATE, total_users, total_mau from totals group by date_trunc('week', datetime), datetime")
|
||||
|
||||
rows = cur.fetchall()
|
||||
|
||||
for row in rows:
|
||||
|
||||
global_week.append(row[0])
|
||||
|
||||
global_week_users.append(row[1])
|
||||
|
||||
global_week_mau.append(row[2])
|
||||
|
||||
cur.close()
|
||||
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
|
@ -899,7 +917,7 @@ class Database():
|
|||
|
||||
conn.close()
|
||||
|
||||
return (servers_plots, users_plots, mau_plots, global_day, global_servers, global_users, global_mau)
|
||||
return (servers_plots, users_plots, mau_plots, global_day, global_servers, global_users, global_mau, global_week, global_week_users, global_week_mau)
|
||||
|
||||
def get_server_data(self, server):
|
||||
|
||||
|
|
|
@ -24,7 +24,21 @@ class Graphit():
|
|||
|
||||
name = 'fediverse data graph library'
|
||||
|
||||
def __init__(self, servers=None, servers_max=None, users=None, users_max=None, mau=None, mau_max=None, global_day=None, global_servers=None, global_users=None, global_mau=None):
|
||||
def __init__(self,
|
||||
servers=None,
|
||||
servers_max=None,
|
||||
users=None,
|
||||
users_max=None,
|
||||
mau=None,
|
||||
mau_max=None,
|
||||
global_day=None,
|
||||
global_servers=None,
|
||||
global_users=None,
|
||||
global_mau=None,
|
||||
global_week=None,
|
||||
global_week_users=None,
|
||||
global_week_mau=None
|
||||
):
|
||||
|
||||
self.servers = servers
|
||||
self.servers_max = servers_max
|
||||
|
@ -37,6 +51,10 @@ class Graphit():
|
|||
self.global_users = global_users
|
||||
self.global_mau = global_mau
|
||||
|
||||
self.global_week = global_week
|
||||
self.global_week_users = global_week_users
|
||||
self.global_week_mau = global_week_mau
|
||||
|
||||
def graph(self):
|
||||
|
||||
# generate graphs
|
||||
|
@ -172,3 +190,39 @@ class Graphit():
|
|||
plt.savefig('app/graphs/global_mau.png')
|
||||
|
||||
plt.close()
|
||||
|
||||
def generate_weeks(self):
|
||||
|
||||
df = pd.DataFrame(
|
||||
{'week': np.array(self.global_week),
|
||||
'week_users': np.array(self.global_week_users),
|
||||
'week_mau': np.array(self.global_week_mau)})
|
||||
|
||||
df['week'] = pd.to_datetime(df['week'])
|
||||
|
||||
# weeks
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
ax.plot(df.week, df.week_users, label='users', color='green')
|
||||
|
||||
ax.plot(df.week, df.week_mau, label='users', color='blue')
|
||||
|
||||
ax.yaxis.set_major_formatter(StrMethodFormatter('{x:,.0f}'))
|
||||
|
||||
plt.tick_params(rotation=45)
|
||||
|
||||
ax.set_title("fediverse's weekly users & MAU")
|
||||
|
||||
ax.set_xlabel('week')
|
||||
|
||||
ax.set_ylabel('users')
|
||||
|
||||
ax.grid(visible=True)
|
||||
|
||||
plt.savefig('app/graphs/global_weeks.png')
|
||||
|
||||
plt.close()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -73,10 +73,12 @@ if __name__ == '__main__':
|
|||
|
||||
# get plots
|
||||
|
||||
graph.servers, graph.users, graph.mau, graph.global_day, graph.global_servers, graph.global_users, graph.global_mau = db.get_plots()
|
||||
graph.servers, graph.users, graph.mau, graph.global_day, graph.global_servers, graph.global_users, graph.global_mau, graph.global_week, graph.global_week_users, graph.global_week_mau = db.get_plots()
|
||||
|
||||
graph.generate()
|
||||
|
||||
graph.generate_weeks()
|
||||
|
||||
###############################################################################
|
||||
# P O S T !
|
||||
|
||||
|
@ -142,4 +144,6 @@ if __name__ == '__main__':
|
|||
|
||||
mau_image_id = mastodon.media_post('app/graphs/global_mau.png', "image/png", description='mau graph').id
|
||||
|
||||
mastodon.status_post(post_text, in_reply_to_id=None, media_ids={servers_image_id, users_image_id, mau_image_id})
|
||||
weeks_image_id = mastodon.media_post('app/graphs/global_weeks.png', "image/png", description='weeks graph').id
|
||||
|
||||
mastodon.status_post(post_text, in_reply_to_id=None, media_ids={servers_image_id, users_image_id, mau_image_id, weeks_image_id})
|
||||
|
|
Loading…
Referencia en una nova incidència