From dd23506588e249e11d21f320f5d27f7913c679e1 Mon Sep 17 00:00:00 2001 From: npalchur Date: Thu, 28 Mar 2024 13:58:09 -0400 Subject: [PATCH 1/3] Remove redis_get/redis_set from functions where possible --- .vscode/settings.json | 3 +++ dashboard/src/t5gweb/t5gweb.py | 4 +-- dashboard/src/t5gweb/ui.py | 47 ++++++++++++++++++++-------------- 3 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b881eff --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.analysis.autoImportCompletions": true +} \ No newline at end of file diff --git a/dashboard/src/t5gweb/t5gweb.py b/dashboard/src/t5gweb/t5gweb.py index 5961c15..ba3b487 100644 --- a/dashboard/src/t5gweb/t5gweb.py +++ b/dashboard/src/t5gweb/t5gweb.py @@ -35,9 +35,9 @@ def get_new_cases(): return new_cases -def get_new_comments(new_comments_only=True, account=None, engineer=None): +def get_new_comments(cards,new_comments_only=True, account=None, engineer=None): # fetch cards from redis cache - cards = libtelco5g.redis_get("cards") + #cards = libtelco5g.redis_get("cards") if account is not None: cards = {c: d for (c, d) in cards.items() if d["account"] == account} if engineer is not None: diff --git a/dashboard/src/t5gweb/ui.py b/dashboard/src/t5gweb/ui.py index 0f661dd..77cedd3 100644 --- a/dashboard/src/t5gweb/ui.py +++ b/dashboard/src/t5gweb/ui.py @@ -79,7 +79,8 @@ def prepare_flask_request(request): "post_data": request.form.copy(), } - +def get_timestamp(): + return redis_get("time_stamp") def load_data(): """Load data for dashboard""" @@ -207,7 +208,7 @@ def index(): "ui/index.html", new_cases=get_new_cases(), values=list(plot_data.values()), - now=redis_get("timestamp"), + now=get_timestamp(), ) @@ -276,10 +277,11 @@ def refresh(): def report_view(): """Retrieves cards that have been updated within the last week and creates report""" cfg = set_cfg() + cards = redis_get("cards") return render_template( "ui/updates.html", - now=redis_get("timestamp"), - new_comments=get_new_comments(), + now=get_timestamp(), + new_comments=get_new_comments(cards), jira_server=cfg["server"], page_title="recent updates", ) @@ -290,10 +292,11 @@ def report_view(): def report_view_all(): """Retrieves all cards and creates report""" cfg = set_cfg() + cards = redis_get("cards") return render_template( "ui/updates.html", - now=redis_get("timestamp"), - new_comments=get_new_comments(new_comments_only=False), + now=get_timestamp(), + new_comments=get_new_comments(cards=cards,new_comments_only=False), jira_server=cfg["server"], page_title="all cards", ) @@ -306,10 +309,11 @@ def trends(): the previous quarter and creates report """ cfg = set_cfg() + cards = redis_get("cards") return render_template( "ui/updates.html", - now=redis_get("timestamp"), - new_comments=get_trending_cards(), + now=get_timestamp(), + new_comments=get_trending_cards(cards), jira_server=cfg["server"], page_title="trends", ) @@ -320,10 +324,11 @@ def trends(): def table_view(): """Sorts new cards by severity and creates table""" cfg = set_cfg() + cards = redis_get("cards") return render_template( "ui/table.html", - now=redis_get("timestamp"), - new_comments=get_new_comments(), + now=get_timestamp(), + new_comments=get_new_comments(cards), jira_server=cfg["server"], page_title="severity", ) @@ -334,10 +339,11 @@ def table_view(): def table_view_all(): """Sorts all cards by severity and creates table""" cfg = set_cfg() + cards = redis_get("cards") return render_template( "ui/table.html", - now=redis_get("timestamp"), - new_comments=get_new_comments(new_comments_only=False), + now=get_timestamp(), + new_comments=get_new_comments(cards=cards,new_comments_only=False), jira_server=cfg["server"], page_title="all-severity", ) @@ -350,10 +356,11 @@ def weekly_updates(): and distribution """ cfg = set_cfg() + cards = redis_get("cards") return render_template( "ui/weekly_report.html", - now=redis_get("timestamp"), - new_comments=get_new_comments(), + now=get_timestamp(), + new_comments=get_new_comments(cards), jira_server=cfg["server"], page_title="weekly-update", ) @@ -368,7 +375,7 @@ def get_stats(): histogram_stats = generate_histogram_stats() return render_template( "ui/stats.html", - now=redis_get("timestamp"), + now=get_timestamp(), stats=stats, x_values=x_values, y_values=y_values, @@ -383,14 +390,15 @@ def get_account(account): """show bugs, cases and stats by for a given account""" cfg = set_cfg() stats = generate_stats(account) - comments = get_new_comments(new_comments_only=False, account=account) + cards = redis_get("cards") + comments = get_new_comments(cards=cards,new_comments_only=False, account=account) pie_stats = make_pie_dict(stats) histogram_stats = generate_histogram_stats(account) return render_template( "ui/account.html", page_title=account, account=account, - now=redis_get("timestamp"), + now=get_timestamp(), stats=stats, new_comments=comments, jira_server=cfg["server"], @@ -404,15 +412,16 @@ def get_account(account): def get_engineer(engineer): """show bugs, cases and stats by for a given engineer""" cfg = set_cfg() + cards = redis_get("cards") stats = generate_stats(engineer=engineer) - comments = get_new_comments(new_comments_only=False, engineer=engineer) + comments = get_new_comments(cards=cards,new_comments_only=False, engineer=engineer) pie_stats = make_pie_dict(stats) histogram_stats = generate_histogram_stats(engineer=engineer) return render_template( "ui/account.html", page_title=engineer, account=engineer, - now=redis_get("timestamp"), + now=get_timestamp(), stats=stats, new_comments=comments, jira_server=cfg["server"], From b983badf8a7346bda49ba5f03a1d7283d3220441 Mon Sep 17 00:00:00 2001 From: npalchur Date: Thu, 28 Mar 2024 16:56:44 -0400 Subject: [PATCH 2/3] changes done as suggested --- .vscode/settings.json | 3 --- dashboard/src/t5gweb/t5gweb.py | 6 ++---- dashboard/src/t5gweb/ui.py | 31 +++++++++++++++---------------- 3 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b881eff..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.analysis.autoImportCompletions": true -} \ No newline at end of file diff --git a/dashboard/src/t5gweb/t5gweb.py b/dashboard/src/t5gweb/t5gweb.py index ba3b487..f7c30da 100644 --- a/dashboard/src/t5gweb/t5gweb.py +++ b/dashboard/src/t5gweb/t5gweb.py @@ -35,9 +35,8 @@ def get_new_cases(): return new_cases -def get_new_comments(cards,new_comments_only=True, account=None, engineer=None): +def get_new_comments(cards, new_comments_only=True, account=None, engineer=None): # fetch cards from redis cache - #cards = libtelco5g.redis_get("cards") if account is not None: cards = {c: d for (c, d) in cards.items() if d["account"] == account} if engineer is not None: @@ -81,9 +80,8 @@ def get_new_comments(cards,new_comments_only=True, account=None, engineer=None): return accounts -def get_trending_cards(): +def get_trending_cards(cards): # fetch cards from redis cache - cards = libtelco5g.redis_get("cards") # get a list of trending cards trending_cards = [card for card in cards if "Trends" in cards[card]["labels"]] diff --git a/dashboard/src/t5gweb/ui.py b/dashboard/src/t5gweb/ui.py index 77cedd3..71eeea4 100644 --- a/dashboard/src/t5gweb/ui.py +++ b/dashboard/src/t5gweb/ui.py @@ -79,8 +79,7 @@ def prepare_flask_request(request): "post_data": request.form.copy(), } -def get_timestamp(): - return redis_get("time_stamp") + def load_data(): """Load data for dashboard""" @@ -208,7 +207,7 @@ def index(): "ui/index.html", new_cases=get_new_cases(), values=list(plot_data.values()), - now=get_timestamp(), + now=redis_get("time_stamp"), ) @@ -280,7 +279,7 @@ def report_view(): cards = redis_get("cards") return render_template( "ui/updates.html", - now=get_timestamp(), + now=redis_get("time_stamp"), new_comments=get_new_comments(cards), jira_server=cfg["server"], page_title="recent updates", @@ -295,8 +294,8 @@ def report_view_all(): cards = redis_get("cards") return render_template( "ui/updates.html", - now=get_timestamp(), - new_comments=get_new_comments(cards=cards,new_comments_only=False), + now=redis_get("time_stamp"), + new_comments=get_new_comments(cards=cards, new_comments_only=False), jira_server=cfg["server"], page_title="all cards", ) @@ -312,7 +311,7 @@ def trends(): cards = redis_get("cards") return render_template( "ui/updates.html", - now=get_timestamp(), + now=redis_get("time_stamp"), new_comments=get_trending_cards(cards), jira_server=cfg["server"], page_title="trends", @@ -327,7 +326,7 @@ def table_view(): cards = redis_get("cards") return render_template( "ui/table.html", - now=get_timestamp(), + now=redis_get("time_stamp"), new_comments=get_new_comments(cards), jira_server=cfg["server"], page_title="severity", @@ -342,8 +341,8 @@ def table_view_all(): cards = redis_get("cards") return render_template( "ui/table.html", - now=get_timestamp(), - new_comments=get_new_comments(cards=cards,new_comments_only=False), + now=redis_get("time_stamp"), + new_comments=get_new_comments(cards=cards, new_comments_only=False), jira_server=cfg["server"], page_title="all-severity", ) @@ -359,7 +358,7 @@ def weekly_updates(): cards = redis_get("cards") return render_template( "ui/weekly_report.html", - now=get_timestamp(), + now=redis_get("time_stamp"), new_comments=get_new_comments(cards), jira_server=cfg["server"], page_title="weekly-update", @@ -375,7 +374,7 @@ def get_stats(): histogram_stats = generate_histogram_stats() return render_template( "ui/stats.html", - now=get_timestamp(), + now=redis_get("time_stamp"), stats=stats, x_values=x_values, y_values=y_values, @@ -391,14 +390,14 @@ def get_account(account): cfg = set_cfg() stats = generate_stats(account) cards = redis_get("cards") - comments = get_new_comments(cards=cards,new_comments_only=False, account=account) + comments = get_new_comments(cards=cards, new_comments_only=False, account=account) pie_stats = make_pie_dict(stats) histogram_stats = generate_histogram_stats(account) return render_template( "ui/account.html", page_title=account, account=account, - now=get_timestamp(), + now=redis_get("time_stamp"), stats=stats, new_comments=comments, jira_server=cfg["server"], @@ -414,14 +413,14 @@ def get_engineer(engineer): cfg = set_cfg() cards = redis_get("cards") stats = generate_stats(engineer=engineer) - comments = get_new_comments(cards=cards,new_comments_only=False, engineer=engineer) + comments = get_new_comments(cards=cards, new_comments_only=False, engineer=engineer) pie_stats = make_pie_dict(stats) histogram_stats = generate_histogram_stats(engineer=engineer) return render_template( "ui/account.html", page_title=engineer, account=engineer, - now=get_timestamp(), + now=redis_get("time_stamp"), stats=stats, new_comments=comments, jira_server=cfg["server"], From 2da892947a3a991b586b3ee4440d1b598cb3c7b7 Mon Sep 17 00:00:00 2001 From: npalchur Date: Thu, 28 Mar 2024 17:25:05 -0400 Subject: [PATCH 3/3] removed load_data function --- dashboard/src/t5gweb/ui.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/dashboard/src/t5gweb/ui.py b/dashboard/src/t5gweb/ui.py index 71eeea4..47d56a4 100644 --- a/dashboard/src/t5gweb/ui.py +++ b/dashboard/src/t5gweb/ui.py @@ -80,20 +80,6 @@ def prepare_flask_request(request): } -def load_data(): - """Load data for dashboard""" - - cfg = set_cfg() - load_data.new_cases = get_new_cases() - plot_data = plots() - load_data.y = list(plot_data.values()) - load_data.accounts = get_new_comments() - load_data.accounts_all = get_new_comments(new_comments_only=False) - load_data.trending_cards = get_trending_cards() - load_data.now = redis_get("timestamp") - load_data.jira_server = cfg["server"] - - @BP.route("/", methods=["GET", "POST"]) def login(): """Handles redirects back and forth from SAML Provider and user creation in Redis"""