summaryrefslogtreecommitdiffstats
path: root/graph.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2024-04-13 01:08:10 -0700
committerPinapelz <yukais@pinapelz.com>2024-04-13 01:08:10 -0700
commit163e07adb573da8497c9ccf0ae97a6c261e7b14a (patch)
tree72c1763fbb76b8fc24b318ffa7c4028273ebf01b /graph.py
initial commit. Migration from GitLab
Diffstat (limited to 'graph.py')
-rw-r--r--graph.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/graph.py b/graph.py
new file mode 100644
index 0000000..f7d8716
--- /dev/null
+++ b/graph.py
@@ -0,0 +1,35 @@
+import plotly.graph_objects as go
+import plotly.express as px
+import pandas as pd
+import warnings
+from member_colors import member_color_map
+import random
+
+def plot_subscriber_count_over_time(server, table_name, gtitle="Subscriber Count Over Time for Phase Connect Members",
+ overrideQuery=None, markers="lines", exclude_channels=[]):
+ warnings.filterwarnings('ignore') # Ignore pandas warning regarding pyodbc
+ query = f"SELECT name, subscriber_count, timestamp, channel_id FROM {table_name} ORDER by timestamp DESC" if overrideQuery is None else overrideQuery
+ df = pd.read_sql_query(query, server.get_connection())
+ groups = df.groupby("name")
+ fig = go.Figure()
+ config = dict({'responsive': True, 'displaylogo': False, 'modeBarButtonsToAdd': ['pan2d', 'zoomIn2d', 'zoomOut2d']})
+
+ for channel, group in groups:
+ if len(exclude_channels) != 0 and group['channel_id'].iloc[0] in exclude_channels:
+ continue
+ color = None
+ color = member_color_map.get(channel, '#' + ''.join(random.choices('0123456789ABCDEF', k=6)))
+
+ fig.add_trace(go.Scattergl(
+ x=group["timestamp"], y=group["subscriber_count"], name=channel, mode=markers,
+ showlegend=True, line=dict(color=color)))
+
+ fig.update_layout(
+ title={'text': gtitle, 'x': 0.5, 'xanchor': 'center',
+ 'yanchor': 'top', 'font': {'family': 'Droid Sans', 'size': 30}},
+ xaxis_title="Date",
+ yaxis_title="Subscribers",
+ legend=dict(font=dict(size=16), title=dict(text="Channels")),
+ height=950,
+ )
+ return fig.to_html(config=config)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage