Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redis_get/redis_set from functions where possible##274 #280

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions dashboard/src/t5gweb/t5gweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ 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")
if account is not None:
cards = {c: d for (c, d) in cards.items() if d["account"] == account}
if engineer is not None:
Expand Down Expand Up @@ -81,9 +80,8 @@ def get_new_comments(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"]]
Expand Down
58 changes: 26 additions & 32 deletions dashboard/src/t5gweb/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -207,7 +193,7 @@ def index():
"ui/index.html",
new_cases=get_new_cases(),
values=list(plot_data.values()),
now=redis_get("timestamp"),
now=redis_get("time_stamp"),
)


Expand Down Expand Up @@ -276,10 +262,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=redis_get("time_stamp"),
new_comments=get_new_comments(cards),
jira_server=cfg["server"],
page_title="recent updates",
)
Expand All @@ -290,10 +277,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=redis_get("time_stamp"),
new_comments=get_new_comments(cards=cards, new_comments_only=False),
jira_server=cfg["server"],
page_title="all cards",
)
Expand All @@ -306,10 +294,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=redis_get("time_stamp"),
new_comments=get_trending_cards(cards),
adhil0 marked this conversation as resolved.
Show resolved Hide resolved
jira_server=cfg["server"],
page_title="trends",
)
Expand All @@ -320,10 +309,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=redis_get("time_stamp"),
new_comments=get_new_comments(cards),
jira_server=cfg["server"],
page_title="severity",
)
Expand All @@ -334,10 +324,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=redis_get("time_stamp"),
new_comments=get_new_comments(cards=cards, new_comments_only=False),
jira_server=cfg["server"],
page_title="all-severity",
)
Expand All @@ -350,10 +341,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=redis_get("time_stamp"),
new_comments=get_new_comments(cards),
jira_server=cfg["server"],
page_title="weekly-update",
)
Expand All @@ -368,7 +360,7 @@ def get_stats():
histogram_stats = generate_histogram_stats()
return render_template(
"ui/stats.html",
now=redis_get("timestamp"),
now=redis_get("time_stamp"),
stats=stats,
x_values=x_values,
y_values=y_values,
Expand All @@ -383,14 +375,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=redis_get("time_stamp"),
stats=stats,
new_comments=comments,
jira_server=cfg["server"],
Expand All @@ -404,15 +397,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=redis_get("time_stamp"),
stats=stats,
new_comments=comments,
jira_server=cfg["server"],
Expand Down