diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2023-06-20 02:15:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-20 02:15:12 -0700 |
| commit | 5b25b6e64140e02c244456973e9305fe43c355c6 (patch) | |
| tree | 6930d7ae771fb188fc6a3a0f7f1f81bad5bf84f2 /html_builders/graphs.py | |
| parent | c929c11f9006db67e10ddd7fa599124a6edeadeb (diff) | |
| parent | 70237b5a5d82e8425eb5870a975bde497a6def08 (diff) | |
Merge pull request #2 from pinapelz/develop-rewrite
Refactored entire codebase
Diffstat (limited to 'html_builders/graphs.py')
| -rw-r--r-- | html_builders/graphs.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/html_builders/graphs.py b/html_builders/graphs.py new file mode 100644 index 0000000..2770880 --- /dev/null +++ b/html_builders/graphs.py @@ -0,0 +1,32 @@ +import plotly.graph_objs as go +import pandas as pd +import warnings +import math +from datetime import datetime, timedelta +import numpy as np +import mysql.connector +from mysql.connector import errorcode + +def plot_subscriber_count_over_time(server, table_name, gtitle = "Subscriber Count Over Time for Nijisanji 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 + fig.add_trace(go.Scattergl( + x = group["timestamp"], y = group["subscriber_count"], name = channel, mode = markers, + showlegend = True)) + fig.update_layout( + title = {'text': gtitle, 'x': 0.5, 'xanchor': 'center', + 'yanchor': 'top', 'font': {'family': 'Arial', 'size': 30}}, + xaxis_title = "Timestamp", + yaxis_title = "Subscribers", + legend = dict(font = dict(size = 16), title = dict(text = "Channels")), + height = 950, + ) + return fig.to_html(config = config)
\ No newline at end of file |
