Skip to content

Add control parameters to analytics dashboard - #145

Merged
Damonamajor merged 19 commits into
mainfrom
144-add-control-parameters-to-analytics-dashboard
Nov 6, 2025
Merged

Damonamajor merged 19 commits into
mainfrom
144-add-control-parameters-to-analytics-dashboard

Conversation

@Damonamajor

@Damonamajor Damonamajor commented Oct 31, 2025 •

Copy link
Copy Markdown
Contributor

This adds 5 params to the homeval report to help produce more refined queries.
They are implemented both in the initial download and caching stage as well as the report.

  • start_date: initial date of data or a defined date.
  • excluded_dates: List of dates which can be removed from the query.
  • end_date: date that default to today unless otherwise specified.
  • refresh_today: TRUE FALSE indicator whether to query todays data.
  • ip_addresses_to_filter: List of IPs which can be removed from the query.

There is also a lintr styler circular error again which I just added #nolint to.

@Damonamajor Damonamajor linked an issue Oct 31, 2025 that may be closed by this pull request
@Damonamajor
Damonamajor marked this pull request as ready for review October 31, 2025 18:34
Comment thread reports/analytics/analytics_dashboard.qmd
Comment thread reports/analytics/analytics_dashboard.qmd
dplyr::filter(
# End date filter
if (!is.null(params$end_date) &
nzchar(params$end_date)) { # nolint

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was giving a circular lint and styler error.

Comment thread reports/analytics/analytics_dashboard.qmd

@jeancochrane jeancochrane left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is trending in the right direction, but some of the code is a bit confusing and I'm not sure if it's working as intended. Let's get the intended behavior sorted out and then we can iron out the details.

Comment thread reports/analytics/analytics_dashboard.qmd Outdated
)
),
if (is.null(params$refresh_today) ||
isTRUE(params$refresh_today)) { # nolint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nitpick, required] Currently, this behavior makes it so that refresh_today controls whether we refresh the end date, regardless of whether that end date is the current day. Can we either adjust this behavior or change the name of the param? Regardless of what we choose, let's also make sure we add a comment above the param in the params section of the doc config so that the behavior is documented.

Our two options:

  1. Keep the current behavior and rename the param to refresh_end_date
  2. Keep the current param name and refactor the behavior to add an additional check such that we only apply the filter if the end date is today

I don't feel strongly about which approach to choose, so I leave it up to you!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have it so that it only uses the feature if the date is today's date, so that should help fix this behavior.

Comment thread reports/analytics/analytics_dashboard.qmd Outdated
Comment on lines +239 to +253
# Start date filter
if (!is.null(params$start_date) &
nzchar(params$start_date)) { # nolint
date >= as.Date(params$start_date)
} else {
TRUE
},

# Excluded dates filter
if (!is.null(params$excluded_dates) &
length(params$excluded_dates) > 0) { # nolint
!(date %in% as.Date(params$excluded_dates))
} else {
TRUE
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion, optional] It strikes me that we're adding a lot of extra logic to this filter() call to account for the possibility that these parameters are missing/empty, when the convert_params block has already defined fallback values for the missing/empty case. Why not update the convert_params block to process excluded_dates, have emtpy_dates fall back to an empty vector, and then simplify this filter so that it incorporates the fallback values? Then the filter would look something like:

filter(
    date >= start_date,
    date <= end_date,
    !(date %in% excluded_dates)
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I moved all the factoring up the the start to make everything work together. Good suggestion.

Comment thread reports/analytics/analytics_dashboard.qmd Outdated
setdiff(
all_dates[
(all_dates != end_date) |
(is.null(params$refresh_today) || isTRUE(params$refresh_today))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question, blocking] Am I right that this filter is duplicative with the logic on line 184? It seems to lead to duplicate end dates when I test it. Here's start_date == "2025-09-04" end_date == "2025-09-10" and refresh_today is null, note the two instances of 2025-09-10:

> dates_to_fetch
[1] "2025-09-04" "2025-09-05" "2025-09-06" "2025-09-07" "2025-09-08" "2025-09-09" "2025-09-10" "2025-09-10"

message("Target file: ", fs::path_abs(out_file))

if (fs::file_exists(out_file) && d != today_local) {
if (fs::file_exists(out_file) & d != end_date) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question, blocking] I'm finding it a bit confusing to wrap my head around how the filters in dates_to_fetch interact with this end_date filter. As far as I can tell, here's how it's currently working:

  • dates_to_fetch will only include end_date if refresh_today is null or true
  • If end_date is present in dates_to_fetch, it will always get refreshed, regardless of whether it is cached

Am I understanding the logic correctly? If so, I have two concerns about it:

  1. If end_date is not already in the logfile cache and refresh_today is false, we will not query data for end_date.
    • Perhaps this is intentional -- I could see an argument that it would be more intuitive for refresh_today to prevent us from querying data for end_date if it doesn't exist -- but it feels like an extension of the parameter's behavior outside the scope that I was imagining for it. I was expecting us to use refresh_today == false to fall back to cached data for the current date if we already have it, but if we don't have that cached data in the first place, then I don't think it makes sense for refresh_today to skip it.
  2. dates_to_fetch does not fully own the logic for determining which dates of logs to fetch, and if a code maintainer wants to alter the way it is defined, they have to remember that there is an interaction with end_date defined down here in the fetching logic itself.

I think there are a couple of ways we could resolve concern 2 to make the code easier to maintain, but the approach we choose will depend on the direction we want to take with the behavior described in concern 1. What do you think?

Comment thread reports/analytics/analytics_dashboard.qmd Outdated
Damonamajor and others added 6 commits November 3, 2025 18:05
Co-authored-by: Jean Cochrane <jeancochrane@users.noreply.github.com>
Co-authored-by: Jean Cochrane <jeancochrane@users.noreply.github.com>
Co-authored-by: Jean Cochrane <jeancochrane@users.noreply.github.com>
@Damonamajor

Damonamajor commented Nov 5, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. There is still the nolint included in the file, but I think cleaning the params up the script improves and simplified it a lot. I moved the refresh_today, to not query the cached data for today if the param does not equal false. That means that NULL TRUE or a random string should still query it.

@Damonamajor Damonamajor self-assigned this Nov 5, 2025
@Damonamajor

Copy link
Copy Markdown
Contributor Author

Something weird popped up, let me take a look.

message("Target file: ", fs::path_abs(out_file))

if (fs::file_exists(out_file) && d != today_local) {
message("Skipping ", format(d), " (already cached).")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem necessary.

@jeancochrane jeancochrane left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job here! I think the final code is nice and simple, and the filters worked great in every combination I tested.

@Damonamajor
Damonamajor merged commit e35f9ca into main Nov 6, 2025
1 check passed
@Damonamajor
Damonamajor deleted the 144-add-control-parameters-to-analytics-dashboard branch November 6, 2025 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add control parameters to analytics dashboard

2 participants