Skip to content

Commit

Permalink
rangesider to datepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
cdolfi committed Jan 4, 2024
1 parent 9dc9193 commit e59b607
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 56 deletions.
71 changes: 43 additions & 28 deletions 8Knot/pages/contributions/visualizations/cntrb_pr_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@
[
dbc.Row(
[
dbc.Label(
"Date Interval:",
html_for=f"date-radio-{PAGE}-{VIZ_ID}",
width="auto",
),
dbc.Col(
[
dbc.RadioItems(
id=f"date-radio-{PAGE}-{VIZ_ID}",
options=[
{"label": "Trend", "value": "D"},
{"label": "Week", "value": "W"},
{"label": "Month", "value": "M"},
{"label": "Year", "value": "Y"},
],
value="W",
inline=True,
),
],
width=4,
),
dbc.Label(
"Total Assignments Required:",
html_for=f"assignments-required-{PAGE}-{VIZ_ID}",
Expand Down Expand Up @@ -81,25 +102,18 @@
),
dbc.Row(
[
dbc.Label(
"Date Interval:",
html_for=f"date-radio-{PAGE}-{VIZ_ID}",
width="auto",
),
dbc.Col(
[
dbc.RadioItems(
id=f"date-radio-{PAGE}-{VIZ_ID}",
options=[
{"label": "Trend", "value": "D"},
{"label": "Week", "value": "W"},
{"label": "Month", "value": "M"},
{"label": "Year", "value": "Y"},
],
value="W",
inline=True,
dcc.DatePickerRange(
id=f"date-picker-range-{PAGE}-{VIZ_ID}",
min_date_allowed=dt.date(2005, 1, 1),
max_date_allowed=dt.date.today(),
initial_visible_month=dt.date(dt.date.today().year, 1, 1),
start_date=dt.date(
dt.date.today().year - 2, dt.date.today().month, dt.date.today().day
),
]
clearable=True,
),
width="auto",
),
dbc.Col(
dbc.Button(
Expand All @@ -113,6 +127,7 @@
),
],
align="center",
justify="between",
),
]
),
Expand Down Expand Up @@ -142,11 +157,13 @@ def toggle_popover(n, is_open):
Input("repo-choices", "data"),
Input(f"date-radio-{PAGE}-{VIZ_ID}", "value"),
Input(f"assignments-required-{PAGE}-{VIZ_ID}", "value"),
Input(f"date-picker-range-{PAGE}-{VIZ_ID}", "start_date"),
Input(f"date-picker-range-{PAGE}-{VIZ_ID}", "end_date"),
Input("bot-switch", "value"),
],
background=True,
)
def cntrib_pr_assignment_graph(repolist, interval, assign_req, bot_switch):
def cntrib_pr_assignment_graph(repolist, interval, assign_req, start_date, end_date, bot_switch):
# wait for data to asynchronously download and become available.
while not_cached := cf.get_uncached(func_name=praq.__name__, repolist=repolist):
logging.warning(f"{VIZ_ID} - WAITING ON DATA TO BECOME AVAILABLE")
Expand Down Expand Up @@ -174,15 +191,15 @@ def cntrib_pr_assignment_graph(repolist, interval, assign_req, bot_switch):
if bot_switch:
df = df[~df["assignee"].isin(app.bots_list)]

df = process_data(df, interval, assign_req)
df = process_data(df, interval, assign_req, start_date, end_date)

fig = create_figure(df, interval)

logging.warning(f"{VIZ_ID} - END - {time.perf_counter() - start}")
return fig, False


def process_data(df: pd.DataFrame, interval, assign_req):
def process_data(df: pd.DataFrame, interval, assign_req, start_date, end_date):
# convert to datetime objects rather than strings
df["created"] = pd.to_datetime(df["created"], utc=True)
df["closed"] = pd.to_datetime(df["closed"], utc=True)
Expand Down Expand Up @@ -213,6 +230,12 @@ def process_data(df: pd.DataFrame, interval, assign_req):
if len(contributors) == 0:
return dash.no_update, True

# filter values based on date picker
if start_date is not None:
df = df[df.created >= start_date]
if end_date is not None:
df = df[df.created <= end_date]

# only include contributors that meet the criteria
df = df.loc[df["assignee"].isin(contributors)]

Expand Down Expand Up @@ -293,14 +316,6 @@ def create_figure(df: pd.DataFrame, interval):
# edit hover values
fig.update_traces(hovertemplate=hover + "<br>Prs Assigned: %{y}<br>")

fig.update_xaxes(
showgrid=True,
ticklabelmode="period",
dtick=period,
rangeslider_yaxis_rangemode="match",
range=x_r,
)

# layout specifics for both styles of plots
fig.update_layout(
xaxis_title="Time",
Expand Down
71 changes: 43 additions & 28 deletions 8Knot/pages/contributions/visualizations/cntrib_issue_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@
[
dbc.Row(
[
dbc.Label(
"Date Interval:",
html_for=f"date-radio-{PAGE}-{VIZ_ID}",
width="auto",
),
dbc.Col(
[
dbc.RadioItems(
id=f"date-radio-{PAGE}-{VIZ_ID}",
options=[
{"label": "Trend", "value": "D"},
{"label": "Week", "value": "W"},
{"label": "Month", "value": "M"},
{"label": "Year", "value": "Y"},
],
value="W",
inline=True,
),
],
width=4,
),
dbc.Label(
"Total Assignments Required:",
html_for=f"assignments-required-{PAGE}-{VIZ_ID}",
Expand Down Expand Up @@ -81,25 +102,18 @@
),
dbc.Row(
[
dbc.Label(
"Date Interval:",
html_for=f"date-radio-{PAGE}-{VIZ_ID}",
width="auto",
),
dbc.Col(
[
dbc.RadioItems(
id=f"date-radio-{PAGE}-{VIZ_ID}",
options=[
{"label": "Trend", "value": "D"},
{"label": "Week", "value": "W"},
{"label": "Month", "value": "M"},
{"label": "Year", "value": "Y"},
],
value="W",
inline=True,
dcc.DatePickerRange(
id=f"date-picker-range-{PAGE}-{VIZ_ID}",
min_date_allowed=dt.date(2005, 1, 1),
max_date_allowed=dt.date.today(),
initial_visible_month=dt.date(dt.date.today().year, 1, 1),
start_date=dt.date(
dt.date.today().year - 2, dt.date.today().month, dt.date.today().day
),
]
clearable=True,
),
width="auto",
),
dbc.Col(
dbc.Button(
Expand All @@ -113,6 +127,7 @@
),
],
align="center",
justify="between",
),
]
),
Expand Down Expand Up @@ -142,11 +157,13 @@ def toggle_popover(n, is_open):
Input("repo-choices", "data"),
Input(f"date-radio-{PAGE}-{VIZ_ID}", "value"),
Input(f"assignments-required-{PAGE}-{VIZ_ID}", "value"),
Input(f"date-picker-range-{PAGE}-{VIZ_ID}", "start_date"),
Input(f"date-picker-range-{PAGE}-{VIZ_ID}", "end_date"),
Input("bot-switch", "value"),
],
background=True,
)
def cntrib_issue_assignment_graph(repolist, interval, assign_req, bot_switch):
def cntrib_issue_assignment_graph(repolist, interval, assign_req, start_date, end_date, bot_switch):
# wait for data to asynchronously download and become available.
while not_cached := cf.get_uncached(func_name=iaq.__name__, repolist=repolist):
logging.warning(f"{VIZ_ID} - WAITING ON DATA TO BECOME AVAILABLE")
Expand All @@ -171,15 +188,15 @@ def cntrib_issue_assignment_graph(repolist, interval, assign_req, bot_switch):
if bot_switch:
df = df[~df["assignee"].isin(app.bots_list)]

df = process_data(df, interval, assign_req)
df = process_data(df, interval, assign_req, start_date, end_date)

fig = create_figure(df, interval)

logging.warning(f"{VIZ_ID} - END - {time.perf_counter() - start}")
return fig, False


def process_data(df: pd.DataFrame, interval, assign_req):
def process_data(df: pd.DataFrame, interval, assign_req, start_date, end_date):
# convert to datetime objects rather than strings
df["created"] = pd.to_datetime(df["created"], utc=True)
df["closed"] = pd.to_datetime(df["closed"], utc=True)
Expand Down Expand Up @@ -210,6 +227,12 @@ def process_data(df: pd.DataFrame, interval, assign_req):
if len(contributors) == 0:
return dash.no_update, True

# filter values based on date picker
if start_date is not None:
df = df[df.created >= start_date]
if end_date is not None:
df = df[df.created <= end_date]

# only include contributors that meet the criteria
df = df.loc[df["assignee"].isin(contributors)]

Expand Down Expand Up @@ -290,14 +313,6 @@ def create_figure(df: pd.DataFrame, interval):
# edit hover values
fig.update_traces(hovertemplate=hover + "<br>Issues Assigned: %{y}<br>")

fig.update_xaxes(
showgrid=True,
ticklabelmode="period",
dtick=period,
rangeslider_yaxis_rangemode="match",
range=x_r,
)

# layout specifics for both styles of plots
fig.update_layout(
xaxis_title="Time",
Expand Down

0 comments on commit e59b607

Please sign in to comment.