From cbd0b3de3aa5ca645ef78a3fc49b7e84cd3b01e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Ib=C3=A1=C3=B1ez?= Date: Wed, 13 Mar 2024 15:19:32 +0100 Subject: [PATCH] merging stats functions and account/engineer templates --- dashboard/src/t5gweb/libtelco5g.py | 142 +------- .../src/t5gweb/templates/ui/account.html | 6 + .../src/t5gweb/templates/ui/engineer.html | 322 ------------------ dashboard/src/t5gweb/ui.py | 8 +- 4 files changed, 12 insertions(+), 466 deletions(-) delete mode 100644 dashboard/src/t5gweb/templates/ui/engineer.html diff --git a/dashboard/src/t5gweb/libtelco5g.py b/dashboard/src/t5gweb/libtelco5g.py index 773145a..4438bd1 100755 --- a/dashboard/src/t5gweb/libtelco5g.py +++ b/dashboard/src/t5gweb/libtelco5g.py @@ -411,7 +411,7 @@ def get_case_from_link(jira_conn, card): return None -def generate_stats(account=None): +def generate_stats(account=None, engineer=None): """generate some stats""" logging.warning("generating stats") @@ -425,144 +425,8 @@ def generate_stats(account=None): if account is not None: logging.warning("filtering cases for {}".format(account)) cards = {c: d for (c, d) in cards.items() if d["account"] == account} - cases = {c: d for (c, d) in cases.items() if d["account"] == account} - - today = datetime.date.today() - - customers = [cards[card]["account"] for card in cards] - engineers = [cards[card]["assignee"]["displayName"] for card in cards] - severities = [cards[card]["severity"] for card in cards] - statuses = [cards[card]["case_status"] for card in cards] - - stats = { - "by_customer": {c: 0 for c in customers}, - "by_engineer": {e: 0 for e in engineers}, - "by_severity": {s: 0 for s in severities}, - "by_status": {s: 0 for s in statuses}, - "high_prio": 0, - "escalated": 0, - "watched": 0, - "open_cases": 0, - "weekly_closed_cases": 0, - "weekly_opened_cases": 0, - "daily_closed_cases": 0, - "daily_opened_cases": 0, - "no_updates": 0, - "no_bzs": 0, - "bugs": {"unique": 0, "no_target": 0}, - "crit_sit": 0, - "total_escalations": 0, - } - - for card, data in cards.items(): - account = data["account"] - engineer = data["assignee"]["displayName"] - severity = data["severity"] - status = data["case_status"] - - stats["by_status"][status] += 1 - - if status != "Closed": - stats["by_customer"][account] += 1 - stats["by_engineer"][engineer] += 1 - stats["by_severity"][severity] += 1 - if severity == "High" or severity == "Urgent": - stats["high_prio"] += 1 - if cards[card]["escalated"]: - stats["escalated"] += 1 - if cards[card]["watched"]: - stats["watched"] += 1 - if cards[card]["crit_sit"]: - stats["crit_sit"] += 1 - if ( - cards[card]["escalated"] - or cards[card]["watched"] - or cards[card]["crit_sit"] - ): - stats["total_escalations"] += 1 - if cards[card]["bugzilla"] is None and cards[card]["issues"] is None: - stats["no_bzs"] += 1 - - for case, data in cases.items(): - if data["status"] == "Closed": - if ( - today - - datetime.datetime.strptime( - data["closeddate"], "%Y-%m-%dT%H:%M:%SZ" - ).date() - ).days < 7: - stats["weekly_closed_cases"] += 1 - if ( - today - - datetime.datetime.strptime( - data["closeddate"], "%Y-%m-%dT%H:%M:%SZ" - ).date() - ).days <= 1: - stats["daily_closed_cases"] += 1 - else: - stats["open_cases"] += 1 - if ( - today - - datetime.datetime.strptime( - data["createdate"], "%Y-%m-%dT%H:%M:%SZ" - ).date() - ).days < 7: - stats["weekly_opened_cases"] += 1 - if ( - today - - datetime.datetime.strptime( - data["createdate"], "%Y-%m-%dT%H:%M:%SZ" - ).date() - ).days <= 1: - stats["daily_opened_cases"] += 1 - if ( - today - - datetime.datetime.strptime( - data["last_update"], "%Y-%m-%dT%H:%M:%SZ" - ).date() - ).days < 7: - stats["no_updates"] += 1 - - all_bugs = {} - no_target = {} - if bugs: - for case, bzs in bugs.items(): - if case in cases and cases[case]["status"] != "Closed": - for bug in bzs: - all_bugs[bug["bugzillaNumber"]] = bug - if is_bug_missing_target(bug): - no_target[bug["bugzillaNumber"]] = bug - - if issues: - for case, jira_bugs in issues.items(): - if case in cases and cases[case]["status"] != "Closed": - for issue in jira_bugs: - all_bugs[issue["id"]] = issue - if is_bug_missing_target(issue): - no_target[issue["id"]] = issue - - stats["bugs"]["unique"] = len(all_bugs) - stats["bugs"]["no_target"] = len(no_target) - - end = time.time() - logging.warning("generated stats in {} seconds".format((end - start))) - - return stats - -def generate_user_stats(engineer=None): - """generate user stats""" - - logging.warning("generating user stats") - start = time.time() - - cards = redis_get("cards") - cases = redis_get("cases") - bugs = redis_get("bugs") - issues = redis_get("issues") - - if engineer is not None: - logging.warning("filtering cases for {}".format(engineer)) - cards = {c: d for (c, d) in cards.items() if d["assignee"]["displayName"] == engineer} + if engineer is None: + cases = {c: d for (c, d) in cases.items() if d["account"] == account} today = datetime.date.today() diff --git a/dashboard/src/t5gweb/templates/ui/account.html b/dashboard/src/t5gweb/templates/ui/account.html index 858467e..3fbee77 100644 --- a/dashboard/src/t5gweb/templates/ui/account.html +++ b/dashboard/src/t5gweb/templates/ui/account.html @@ -31,7 +31,11 @@ charset="utf8" src="{{ url_for('static', filename='node_modules/plotly.js-cartesian-dist-min/plotly-cartesian.min.js') }}">
+ {% if engineer_view == True %} +

Engineer Stats: {{ account }}

+ {% else %}

Account Stats: {{ account }}

+ {% endif %}
Account Stats: {{ account }}
+ {% if engineer_view != True %}

Bugs and JIRA Issues:

Bugs and JIRA Issues:
+ {% endif %}

Cases:

{{ macros.cases_table(new_comments, jira_server) }} diff --git a/dashboard/src/t5gweb/templates/ui/engineer.html b/dashboard/src/t5gweb/templates/ui/engineer.html deleted file mode 100644 index 6027a31..0000000 --- a/dashboard/src/t5gweb/templates/ui/engineer.html +++ /dev/null @@ -1,322 +0,0 @@ -{% extends "skeleton.html" %} -{% import 'macros/macros.html' as macros %} -{% block title %}{{ page_title }}{% endblock %} -{% block content %} - - - - - - - - - - -
-

Engineer Stats: {{ engineer }}

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MetricCount
Open Cases{{ stats['open_cases'] }}
Cases On Prio-list{{ stats['escalated'] }}
Cases On WatchList{{ stats['watched'] }}
Crit Sit Cases{{ stats['crit_sit'] }}
Total Escalations{{ stats['total_escalations'] }}
High Priority Cases{{ stats['high_prio'] }}
Cases Opened in the Last Day / Week{{ stats['daily_opened_cases'] }} / {{ stats['weekly_opened_cases'] }}
Cases Closed in the Last Day / Week{{ stats['daily_closed_cases'] }} / {{ stats['weekly_closed_cases'] }}
Cases With No Updates In The Last Week{{ stats['no_updates'] }}
Cases With No Bugs Associated{{ stats['no_bzs'] }}
Unique Bugs{{ stats['bugs']['unique'] }}
Bugs With No Target{{ stats['bugs']['no_target'] }}
-
{{ macros.outcomes_table(histogram_stats) }}
-
-
-
-
-
- - -
-
-
-
-
-
- - -
-
-
-
-
-
-
- -
-

Cases:

- {{ macros.cases_table(new_comments, jira_server) }} - -{% endblock %} diff --git a/dashboard/src/t5gweb/ui.py b/dashboard/src/t5gweb/ui.py index a84831f..f413243 100644 --- a/dashboard/src/t5gweb/ui.py +++ b/dashboard/src/t5gweb/ui.py @@ -23,7 +23,6 @@ from t5gweb.libtelco5g import ( generate_histogram_stats, generate_stats, - generate_user_stats, plot_stats, redis_get, redis_set, @@ -417,8 +416,7 @@ def get_account(account): def get_engineer(engineer): """show bugs, cases and stats by for a given engineer""" load_data() - stats = generate_user_stats(engineer) - #comments = get_new_comments(new_comments_only=False, account=engineer) + stats = generate_stats(engineer=engineer) comments = get_new_comments(new_comments_only=False, engineer=engineer) pie_stats = { @@ -432,10 +430,9 @@ def get_engineer(engineer): ), } - # TODO: remove closed cards histogram_stats = generate_histogram_stats(engineer=engineer) return render_template( - "ui/engineer.html", + "ui/account.html", page_title=engineer, account=engineer, now=load_data.now, @@ -444,4 +441,5 @@ def get_engineer(engineer): jira_server=load_data.jira_server, pie_stats=pie_stats, histogram_stats=histogram_stats, + engineer_view=True, ) \ No newline at end of file