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 #32

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:44
Comment on lines -115 to +119
bads = []
for i, row in df.iterrows():
# print(_row_stats(row))
if not _check_row_signal_quality(row, max_uv_abs, max_std):
bads.append(i)
bads = [
i
for i, row in df.iterrows()
if not _check_row_signal_quality(row, max_uv_abs, max_std)
]
Copy link
Author

Choose a reason for hiding this comment

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

Function _clean_signal_quality refactored with the following changes:

This removes the following comments ( why? ):

# print(_row_stats(row))

catmap = dict(((cls, i) for i, cls in enumerate(df["class"].cat.categories)))
catmap = {cls: i for i, cls in enumerate(df["class"].cat.categories)}
Copy link
Author

Choose a reason for hiding this comment

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

Function signal_ndarray refactored with the following changes:

assert all([v1 == v2 - 1 == v3 - 2 for v1, v2, v3 in zip(sa, sb, sc)])
assert all(v1 == v2 - 1 == v3 - 2 for v1, v2, v3 in zip(sa, sb, sc))
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_unison_shuffled_copies refactored with the following changes:

Comment on lines -117 to +120
votes.append(vote > 0.5)
else:
# Use the mean probability
vote = np.mean(predicted_proba[test][i_start : i_stop + 1, 1])
votes.append(vote > 0.5)

votes.append(vote > 0.5)
Copy link
Author

Choose a reason for hiding this comment

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

Function aggregate_windows_to_epochs refactored with the following changes:

raw = mne.io.RawArray(eeg_data, info)
return raw
return mne.io.RawArray(eeg_data, info)
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_demo refactored with the following changes:

bads = [ch for ch, ok in checked.items() if not ok]
return bads
return [ch for ch, ok in checked.items() if not ok]
Copy link
Author

Choose a reason for hiding this comment

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

Function BrainflowDevice.check refactored with the following changes:

Comment on lines -204 to -210
# Subtract five seconds of settling time from beginning
# total_data = total_data[5 * self.sfreq :]
df = pd.DataFrame(
return pd.DataFrame(
total_data,
columns=["timestamps"] + ch_names + (["stim"] if self.markers else []),
)
return df
Copy link
Author

Choose a reason for hiding this comment

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

Function BrainflowDevice.get_data refactored with the following changes:

This removes the following comments ( why? ):

# total_data = total_data[5 * self.sfreq :]
# Subtract five seconds of settling time from beginning

if self.stream_process:
return self.stream_process.exitcode is None
return False
return self.stream_process.exitcode is None if self.stream_process else False
Copy link
Author

Choose a reason for hiding this comment

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

Function MuseDevice.started refactored with the following changes:

Comment on lines -126 to +131
for i in range(5):
for _ in range(5):
for inlet in inlets:
inlet.pull(timeout=0.5) # type: ignore
inlets = [inlet for inlet in inlets if inlet.buffer.any()] # type: ignore
if inlets:
break
else:
logger.info("No inlets with data, trying again in a second...")
sleep(1)
logger.info("No inlets with data, trying again in a second...")
sleep(1)
Copy link
Author

Choose a reason for hiding this comment

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

Function MuseDevice._read_buffer refactored with the following changes:

Comment on lines -152 to +149
bads = [ch for ch, ok in checked.items() if not ok]
return bads
return [ch for ch, ok in checked.items() if not ok]
Copy link
Author

Choose a reason for hiding this comment

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

Function MuseDevice.check 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.06%.

Quality metrics Before After Change
Complexity 5.78 ⭐ 5.61 ⭐ -0.17 👍
Method Length 52.96 ⭐ 52.60 ⭐ -0.36 👍
Working memory 8.81 🙂 8.84 🙂 0.03 👎
Quality 68.75% 🙂 68.81% 🙂 0.06% 👍
Other metrics Before After Change
Lines 1170 1155 -15
Changed files Quality Before Quality After Quality Change
src/eegclassify/clean.py 79.76% ⭐ 79.91% ⭐ 0.15% 👍
src/eegclassify/transform.py 56.46% 🙂 56.67% 🙂 0.21% 👍
src/eegclassify/util.py 68.38% 🙂 69.02% 🙂 0.64% 👍
src/eegwatch/load.py 74.86% 🙂 75.31% ⭐ 0.45% 👍
src/eegwatch/lslutils.py 69.50% 🙂 69.45% 🙂 -0.05% 👎
src/eegwatch/main.py 52.78% 🙂 53.49% 🙂 0.71% 👍
src/eegwatch/util.py 84.52% ⭐ 84.88% ⭐ 0.36% 👍
src/eegwatch/devices/_brainflow.py 72.25% 🙂 72.25% 🙂 0.00%
src/eegwatch/devices/muse.py 74.68% 🙂 73.92% 🙂 -0.76% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
src/eegwatch/main.py connect 23 😞 276 ⛔ 21 ⛔ 21.30% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/eegwatch/devices/_brainflow.py BrainflowDevice._init_brainflow 17 🙂 214 ⛔ 11 😞 39.84% 😞 Try splitting into smaller methods. Extract out complex expressions
src/eegwatch/lslutils.py _get_inlets 16 🙂 125 😞 15 😞 43.02% 😞 Try splitting into smaller methods. Extract out complex expressions
src/eegclassify/util.py aggregate_windows_to_epochs 8 ⭐ 181 😞 14 😞 45.48% 😞 Try splitting into smaller methods. Extract out complex expressions
src/eegwatch/devices/muse.py MuseDevice.start 11 🙂 133 😞 15 😞 46.32% 😞 Try splitting into smaller methods. 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
Copy link

codecov bot commented Mar 16, 2022

Codecov Report

Merging #32 (bf732a7) into master (b927849) will decrease coverage by 0.39%.
The diff coverage is 29.16%.

@@            Coverage Diff             @@
##           master      #32      +/-   ##
==========================================
- Coverage   65.93%   65.53%   -0.40%     
==========================================
  Files          22       22              
  Lines        1224     1213      -11     
==========================================
- Hits          807      795      -12     
- Misses        417      418       +1     
Impacted Files Coverage Δ
src/eegwatch/devices/muse.py 35.52% <0.00%> (+1.34%) ⬆️
src/eegwatch/lslutils.py 28.04% <0.00%> (ø)
src/eegwatch/main.py 26.56% <0.00%> (ø)
src/eegwatch/util.py 41.17% <0.00%> (+2.28%) ⬆️
src/eegwatch/devices/_brainflow.py 65.42% <66.66%> (-0.64%) ⬇️
src/eegclassify/clean.py 64.13% <100.00%> (-1.14%) ⬇️
src/eegclassify/transform.py 77.14% <100.00%> (ø)
src/eegclassify/util.py 100.00% <100.00%> (ø)
src/eegwatch/load.py 100.00% <100.00%> (ø)
src/eegclassify/load.py 87.94% <0.00%> (-2.84%) ⬇️
... and 1 more

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 b927849...bf732a7. Read the comment docs.

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.

0 participants