Skip to content

Commit

Permalink
Merge pull request #266 from ptrnull/engineer_view
Browse files Browse the repository at this point in the history
Adding the engineer view
  • Loading branch information
adhil0 authored Mar 25, 2024
2 parents f7b79e2 + 3e58bd9 commit dd872e1
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 20 deletions.
35 changes: 30 additions & 5 deletions dashboard/src/t5gweb/libtelco5g.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ def create_cards(cfg, new_cases, action="none"):
"priority": {"name": priority},
"labels": cfg["labels"],
"summary": summary[:253] + ".." if len(summary) > 253 else summary,
"description": full_description[:253] + ".."
if len(full_description) > 253
else full_description,
"description": (
full_description[:253] + ".."
if len(full_description) > 253
else full_description
),
}

if assignee:
Expand Down Expand Up @@ -411,7 +413,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")
Expand All @@ -426,6 +428,23 @@ def generate_stats(account=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}
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
}

# get case number and assignee from cards so that we can determine which cases
# belong to the engineer
temp_cases = {}
for case, details in cases.items():
for card in cards:
if (
case == cards[card]["case_number"]
and cards[card]["assignee"]["displayName"] == engineer
):
temp_cases[case] = details
cases = temp_cases

today = datetime.date.today()

Expand Down Expand Up @@ -602,7 +621,7 @@ def plot_stats():
return x_values, y_values


def generate_histogram_stats(account=None):
def generate_histogram_stats(account=None, engineer=None):
"""
Calculates histogram statistics for resolved and relief times of cards.
Expand Down Expand Up @@ -654,6 +673,12 @@ def generate_histogram_stats(account=None):
logging.warning(f"filtering cards for {account}")
cards = {c: d for (c, d) in cards.items() if d["account"] == account}

if engineer is not None:
logging.warning(f"filtering cards for {engineer}")
cards = {
c: d for (c, d) in cards.items() if d["assignee"]["displayName"] == engineer
}

histogram_data = {
"Resolved": base_dictionary,
"Relief": base_dictionary,
Expand Down
7 changes: 6 additions & 1 deletion dashboard/src/t5gweb/t5gweb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""core CRUD functions for t5gweb"""

import logging
import re
from copy import deepcopy
Expand Down Expand Up @@ -34,11 +35,15 @@ def get_new_cases():
return new_cases


def get_new_comments(new_comments_only=True, account=None):
def get_new_comments(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:
cards = {
c: d for (c, d) in cards.items() if d["assignee"]["displayName"] == engineer
}
logging.warning("found %d JIRA cards" % (len(cards)))
time_now = datetime.now(timezone.utc)

Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/t5gweb/templates/macros/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h2>Statistics</h2>
<td class="align-middle text-center">{{ new_comments[account][status][card]['case_status'] }}</td>
<td class="align-middle text-center">{{ new_comments[account][status][card]['card_status'] }}</td>
<td class="align-middle text-center">
{{ new_comments[account][status][card]['assignee']['displayName'] }}
<a href="{{ url_for('ui.get_engineer', engineer=new_comments[account][status][card]['assignee']['displayName']) }}">{{ new_comments[account][status][card]['assignee']['displayName'] }}</a>
{% if new_comments[account][status][card]['contributor'] | length %}
<br>
<br>
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/t5gweb/templates/ui/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
charset="utf8"
src="{{ url_for('static', filename='node_modules/plotly.js-cartesian-dist-min/plotly-cartesian.min.js') }}"></script>
<div class="container-fluid copy mt-5">
{% if engineer_view == True %}
<h2>Engineer Stats: {{ account }}</h2>
{% else %}
<h2>Account Stats: {{ account }}</h2>
{% endif %}
<div class="row">
<div class="col-sm-6">
<table class="table table-bordered table-hover table-responsive w-100"
Expand Down Expand Up @@ -179,6 +183,7 @@ <h2>Account Stats: {{ account }}</h2>
</div>
</div>
<br>
{% if engineer_view != True %}
<div class="bug-table">
<h2>Bugs and JIRA Issues:</h2>
<table class="table table-bordered table-hover table-responsive mt-5 w-100"
Expand Down Expand Up @@ -237,6 +242,7 @@ <h2>Bugs and JIRA Issues:</h2>
</tbody>
</table>
</div>
{% endif %}
<br>
<h2>Cases:</h2>
{{ macros.cases_table(new_comments, jira_server) }}
Expand Down
38 changes: 25 additions & 13 deletions dashboard/src/t5gweb/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
from t5gweb.t5gweb import get_new_cases, get_new_comments, get_trending_cards, plots
from t5gweb.taskmgr import refresh_background
from t5gweb.utils import set_cfg
from t5gweb.utils import make_pie_dict, set_cfg

BP = Blueprint("ui", __name__, url_prefix="/")
login_manager = LoginManager()
Expand Down Expand Up @@ -386,18 +386,7 @@ def get_account(account):
load_data()
stats = generate_stats(account)
comments = get_new_comments(new_comments_only=False, account=account)

pie_stats = {
"by_severity": (
list(stats["by_severity"].keys()),
list(stats["by_severity"].values()),
),
"by_status": (
list(stats["by_status"].keys()),
list(stats["by_status"].values()),
),
}

pie_stats = make_pie_dict(stats)
histogram_stats = generate_histogram_stats(account)
return render_template(
"ui/account.html",
Expand All @@ -410,3 +399,26 @@ def get_account(account):
pie_stats=pie_stats,
histogram_stats=histogram_stats,
)


@BP.route("/engineer/<string:engineer>")
@login_required
def get_engineer(engineer):
"""show bugs, cases and stats by for a given engineer"""
load_data()
stats = generate_stats(engineer=engineer)
comments = get_new_comments(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=load_data.now,
stats=stats,
new_comments=comments,
jira_server=load_data.jira_server,
pie_stats=pie_stats,
histogram_stats=histogram_stats,
engineer_view=True,
)
14 changes: 14 additions & 0 deletions dashboard/src/t5gweb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,17 @@ def slack_notify(ini, blist):
)
except SlackApiError as slack_error:
logging.warning("failed to post to slack: %s", slack_error)


def make_pie_dict(stats):
"""get the code simplified"""
return {
"by_severity": (
list(stats["by_severity"].keys()),
list(stats["by_severity"].values()),
),
"by_status": (
list(stats["by_status"].keys()),
list(stats["by_status"].values()),
),
}

0 comments on commit dd872e1

Please sign in to comment.