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

Filter maintenance.timeline to return data from expected date range based on limit #960

Merged
merged 16 commits into from
Apr 14, 2023

Conversation

klai95
Copy link
Contributor

@klai95 klai95 commented Mar 22, 2023

Issue: #958

… end date for maintenance timeline to align parity with usage timelime
backend/api/model.py Outdated Show resolved Hide resolved
backend/api/model.py Outdated Show resolved Hide resolved
backend/api/model.py Outdated Show resolved Hide resolved
@klai95
Copy link
Contributor Author

klai95 commented Apr 13, 2023

I have tested locally to ensure that the data is correct, and edge cases are captured as well.

(get_metrics_for_plugin('zarpaint', '3', False))

{'usage': {'timeline': [{'timestamp': 1672531200000, 'installs': 2}, {'timestamp': 1675209600000, 'installs': 8}, {'timestamp': 1677628800000, 'installs': 6}], 'stats': {'total_installs': 220, 'installs_in_last_30_days': 4}}, 'maintenance': {'timeline': [{'timestamp': 1672531200000, 'commits': 0}, {'timestamp': 1675209600000, 'commits': 0}, {'timestamp': 1677628800000, 'commits': 0}], 'stats': {'latest_commit_timestamp': 1668955796000, 'total_commits': 35}}}

get_metrics_for_plugin('napari-bigfish', '3', False)

{'usage': {'timeline': [{'timestamp': 1672531200000, 'installs': 0}, {'timestamp': 1675209600000, 'installs': 0}, {'timestamp': 1677628800000, 'installs': 0}], 'stats': {'total_installs': 4, 'installs_in_last_30_days': 4}}, 'maintenance': {'timeline': [{'timestamp': 1672531200000, 'commits': 0}, {'timestamp': 1675209600000, 'commits': 0}, {'timestamp': 1677628800000, 'commits': 0}], 'stats': {'latest_commit_timestamp': None, 'total_commits': 0}}}

get_metrics_for_plugin('zarpaint', '0', False)

{'usage': {'timeline': [], 'stats': {'total_installs': 220, 'installs_in_last_30_days': 4}}, 'maintenance': {'timeline': [], 'stats': {'latest_commit_timestamp': 1668955796000, 'total_commits': 35}}}

get_metrics_for_plugin('zarpaint', 'foo', False)

{'usage': {'timeline': [], 'stats': {'total_installs': 220, 'installs_in_last_30_days': 4}}, 'maintenance': {'timeline': [], 'stats': {'latest_commit_timestamp': 1668955796000, 'total_commits': 35}}}

get_metrics_for_plugin('zarpaint', '-5', False)

{'usage': {'timeline': [], 'stats': {'total_installs': 220, 'installs_in_last_30_days': 4}}, 'maintenance': {'timeline': [], 'stats': {'latest_commit_timestamp': 1668955796000, 'total_commits': 35}}}

@@ -430,7 +429,7 @@ def _update_activity_timeline_data():
write_data(csv_string, "activity_dashboard_data/plugin_installs.csv")


def _process_for_timeline(plugin_df, limit):
def _process_usage_timeline(plugin_df, limit):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea renaming this one!

@@ -448,6 +447,18 @@ def _process_for_timeline(plugin_df, limit):
return result


def _process_maintenance_timeline(commit_activity, limit):
now = datetime.now()
end_date = datetime(now.year, now.month - 1, 1) if now.month > 1 else datetime(now.year - 1, 12, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find the way end_date is calculated in line 434 a lot more readable. Any particular reason you didn't want to do it that way?

Copy link
Contributor Author

@klai95 klai95 Apr 13, 2023

Choose a reason for hiding this comment

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

The original intention was to define start_date and end_date as type datetime.datetime, so that we could directly compare start_date <= item_date <= end_date without any conversions, since the implementation on line 434 and line 435 are type datetime.date.

That being said, after some thinking, I do agree the way that end_date is written here is a bit more complex than it needs to be, so I have decided to follow the logic in _process_usage_timeline to generate start_date and end_date.

I have also created the _process_for_dates method that returns start_date, end_date, dates, which is used by both _process_usage_timeline and _process_maintenance_timeline to avoid code duplication.

In order to do the minimal number of conversions, we compare the datetime.date objects like so in the PR: start_date <= item_datetime.date() <= end_date

I have locally tested the current implementation and it works as expected, in the same way outlined in #960 (comment)

@klai95 klai95 requested a review from edu-bob April 13, 2023 17:21
…used by both _process_usage_timeline and _process_maintenance_timeline to avoid code duplication
codemonkey800
codemonkey800 previously approved these changes Apr 13, 2023
….json contain data in which plugin is lower case to maintain parity with the implementation of install activity
@@ -448,6 +452,15 @@ def _process_for_timeline(plugin_df, limit):
return result


def _process_maintenance_timeline(commit_activity, limit):
start_date, end_date, dates = _process_for_dates(limit)
maintenance_dict = {item_datetime: item for item in commit_activity if
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a lot going on here and it's hard to follow in a single line. How about something similar to:

for commit in commit_activity:
    commit_date = ...
    if start_date <= commit_date <= end_date:
        add commit to list

@klai95 klai95 dismissed manasaV3’s stale review April 14, 2023 18:57

feedback has been addressed, and reviewer is unable to review this PR at this time

Copy link
Member

@kne42 kne42 left a comment

Choose a reason for hiding this comment

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

I like the function name updates since it makes them more self-explanatory!

@klai95 klai95 merged commit 129aee8 into main Apr 14, 2023
@klai95 klai95 deleted the timeline-data-fix branch April 14, 2023 19:35
@codemonkey800 codemonkey800 added bug-fix Release Label: Used for categorizing bug fixes in automated CI release notes improvement Release Label: Used for categorizing improvements in automated CI release notes and removed bug-fix Release Label: Used for categorizing bug fixes in automated CI release notes labels Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Release Label: Used for categorizing improvements in automated CI release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants