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

Sourcery refactored master branch #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 16, 2022

Branch master refactored 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 master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from ErikBjare March 16, 2022 11:45
Comment on lines -73 to +75
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]:
Copy link
Author

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:

Comment on lines -186 to +190
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)
Copy link
Author

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:

Comment on lines -203 to +231
# 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"),
]

Copy link
Author

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:

Comment on lines -244 to +243
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"]})
Copy link
Author

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:

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):
Copy link
Author

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:

events = [e for e in events]
events = list(events)
Copy link
Author

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:

This removes the following comments ( why? ):

# FIXME: Only supports one tag

val = tag if tag else substance
val = tag or substance
Copy link
Author

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:

substances = set(s for s in df_src["substance"] if s)
substances = {s for s in df_src["substance"] if s}
Copy link
Author

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:

Comment on lines -146 to +148
set((d + timedelta(hours=-4)).date() for d in df["timestamp"])
{(d + timedelta(hours=-4)).date() for d in df["timestamp"]}
)

Copy link
Author

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:

assert (10e-6 <= series_nonzero).all()
assert (series_nonzero >= 10e-6).all()
Copy link
Author

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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 16, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.02%.

Quality metrics Before After Change
Complexity 5.27 ⭐ 5.24 ⭐ -0.03 👍
Method Length 60.77 ⭐ 60.33 ⭐ -0.44 👍
Working memory 8.11 🙂 8.15 🙂 0.04 👎
Quality 69.39% 🙂 69.41% 🙂 0.02% 👍
Other metrics Before After Change
Lines 635 632 -3
Changed files Quality Before Quality After Quality Change
src/quantifiedme/activitywatch.py 60.27% 🙂 60.30% 🙂 0.03% 👍
src/quantifiedme/influxdb.py 88.92% ⭐ 88.20% ⭐ -0.72% 👎
src/quantifiedme/load_toggl.py 59.04% 🙂 59.50% 🙂 0.46% 👍
src/quantifiedme/qslang.py 74.49% 🙂 74.68% 🙂 0.19% 👍
tests/test_load.py 82.29% ⭐ 82.29% ⭐ 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
src/quantifiedme/activitywatch.py load_complete_timeline 16 🙂 247 ⛔ 14 😞 33.94% 😞 Try splitting into smaller methods. Extract out complex expressions
src/quantifiedme/load_toggl.py _load_toggl 12 🙂 220 ⛔ 15 😞 37.62% 😞 Try splitting into smaller methods. Extract out complex expressions
src/quantifiedme/qslang.py load_df 13 🙂 191 😞 8 🙂 51.00% 🙂 Try splitting into smaller methods
src/quantifiedme/activitywatch.py create_fake_events 5 ⭐ 113 🙂 11 😞 60.41% 🙂 Extract out complex expressions
src/quantifiedme/load_toggl.py _load_toggl.entries_from_all_workspaces 1 ⭐ 77 🙂 10 😞 71.30% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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-commenter
Copy link

codecov-commenter commented Mar 16, 2022

Codecov Report

Merging #6 (722cb45) into master (77ea816) will decrease coverage by 0.14%.
The diff coverage is 50.00%.

@@            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              
Impacted Files Coverage Δ
src/quantifiedme/load_toggl.py 21.27% <0.00%> (ø)
src/quantifiedme/qslang.py 56.79% <33.33%> (ø)
src/quantifiedme/activitywatch.py 70.00% <83.33%> (-0.23%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77ea816...722cb45. Read the comment docs.

@ErikBjare ErikBjare force-pushed the master branch 3 times, most recently from f505855 to 3de8677 Compare May 23, 2023 17:31
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.

1 participant