-
-
Notifications
You must be signed in to change notification settings - Fork 3
Sourcery refactored master branch #6
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
base: master
Are you sure you want to change the base?
Conversation
src/quantifiedme/activitywatch.py
Outdated
| data = random.choices( | ||
| if data := random.choices( | ||
| [d[1] for d in fakedata_weights], [d[0] for d in fakedata_weights] | ||
| )[0] | ||
| if data: | ||
| )[0]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function create_fake_events refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
src/quantifiedme/activitywatch.py
Outdated
| assert all([since <= e.timestamp for e in events]) | ||
| assert all(since <= e.timestamp for e in events) | ||
|
|
||
| # Verify that no events take place in the future | ||
| # FIXME: Doesn't work with fake data, atm | ||
| if "fake" not in datasources: | ||
| assert all([e.timestamp + e.duration <= now for e in events]) | ||
| assert all(e.timestamp + e.duration <= now for e in events) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function load_complete_timeline refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
src/quantifiedme/activitywatch.py
Outdated
| # TODO: Move to example config.toml | ||
| classes = [ | ||
| # (Social) Media | ||
| (r"Facebook|facebook.com", "Social Media", "Media"), | ||
| (r"Reddit|reddit.com", "Social Media", "Media"), | ||
| (r"Spotify|spotify.com", "Music", "Media"), | ||
| (r"subcategory without matching", "Video", "Media"), | ||
| (r"YouTube|youtube.com", "YouTube", "Video"), | ||
| (r"Plex|plex.tv", "Plex", "Video"), | ||
| (r"Fallout 4", "Games", "Media"), | ||
| # Work | ||
| (r"github.com|stackoverflow.com", "Programming", "Work"), | ||
| (r"[Aa]ctivity[Ww]atch|aw-.*", "ActivityWatch", "Programming"), | ||
| (r"[Qq]uantified[Mm]e", "QuantifiedMe", "Programming"), | ||
| (r"[Tt]hankful", "Thankful", "Programming"), | ||
| # School | ||
| (r"subcategory without matching", "School", "Work"), | ||
| (r"Duolingo|Brilliant|Khan Academy", "Self-directed", "School"), | ||
| (r"Analysis in One Variable", "Maths", "School"), | ||
| (r"Applied Machine Learning", "CS", "School"), | ||
| (r"Advanced Web Security", "CS", "School"), | ||
| ] | ||
|
|
||
| # Now load the classes from within the notebook, or from a CSV file. | ||
| load_from_file = True if personal else False | ||
| load_from_file = personal | ||
| if load_from_file: | ||
| # TODO: Move categories into config.toml itself | ||
| aw_research.classify._init_classes(filename=load_config()["data"]["categories"]) | ||
| else: | ||
| logger.info("Using example categories") | ||
| # TODO: Move to example config.toml | ||
| classes = [ | ||
| # (Social) Media | ||
| (r"Facebook|facebook.com", "Social Media", "Media"), | ||
| (r"Reddit|reddit.com", "Social Media", "Media"), | ||
| (r"Spotify|spotify.com", "Music", "Media"), | ||
| (r"subcategory without matching", "Video", "Media"), | ||
| (r"YouTube|youtube.com", "YouTube", "Video"), | ||
| (r"Plex|plex.tv", "Plex", "Video"), | ||
| (r"Fallout 4", "Games", "Media"), | ||
| # Work | ||
| (r"github.com|stackoverflow.com", "Programming", "Work"), | ||
| (r"[Aa]ctivity[Ww]atch|aw-.*", "ActivityWatch", "Programming"), | ||
| (r"[Qq]uantified[Mm]e", "QuantifiedMe", "Programming"), | ||
| (r"[Tt]hankful", "Thankful", "Programming"), | ||
| # School | ||
| (r"subcategory without matching", "School", "Work"), | ||
| (r"Duolingo|Brilliant|Khan Academy", "Self-directed", "School"), | ||
| (r"Analysis in One Variable", "Maths", "School"), | ||
| (r"Applied Machine Learning", "CS", "School"), | ||
| (r"Advanced Web Security", "CS", "School"), | ||
| ] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function classify refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Simplify boolean if expression (
boolean-if-exp-identity)
src/quantifiedme/activitywatch.py
Outdated
| all_categories = list(set(t for e in events for t in e.data["$tags"])) | ||
| all_categories = list({t for e in events for t in e.data["$tags"]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function load_category_df refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| bucket_api = client.buckets_api() | ||
| existing_bucket = bucket_api.find_bucket_by_name(bucket_name_influx) | ||
| if existing_bucket: | ||
| if existing_bucket := bucket_api.find_bucket_by_name(bucket_name_influx): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function init_influxdb refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| if events is None: | ||
| events = load_events() | ||
| events = [e for e in events] | ||
| events = list(events) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function load_df refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension) - Unwrap a constant iterable constructor. (
unwrap-iterable-construction)
This removes the following comments ( why? ):
# FIXME: Only supports one tag
| assert tag or substance | ||
| key = "tag" if tag else "substance" | ||
| val = tag if tag else substance | ||
| val = tag or substance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function to_series refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity)
src/quantifiedme/qslang.py
Outdated
| df[f"tag:{tag}"] = to_series(df_src, tag=tag) | ||
|
|
||
| substances = set(s for s in df_src["substance"] if s) | ||
| substances = {s for s in df_src["substance"] if s} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function to_df_daily refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
src/quantifiedme/qslang.py
Outdated
| set((d + timedelta(hours=-4)).date() for d in df["timestamp"]) | ||
| {(d + timedelta(hours=-4)).date() for d in df["timestamp"]} | ||
| ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _missing_dates refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
|
|
||
| # More than 10mg | ||
| assert (10e-6 <= series_nonzero).all() | ||
| assert (series_nonzero >= 10e-6).all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_load_qslang refactored with the following changes:
- Ensure constant in comparison is on the right (
flip-comparison)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.02%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Codecov Report
@@ Coverage Diff @@
## master #6 +/- ##
==========================================
- Coverage 60.14% 60.00% -0.15%
==========================================
Files 4 4
Lines 281 280 -1
==========================================
- Hits 169 168 -1
Misses 112 112
Continue to review full report at Codecov.
|
f505855 to
3de8677
Compare
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!