Skip to content

Sourcery refactored master branch - #32

Open
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master
Open

Sourcery refactored master branch#32
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master

Conversation

@sourcery-ai

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

Copy link
Copy Markdown

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 thread src/eegclassify/clean.py
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
Copy Markdown
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))

y = np.empty((n_trials))

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
Copy Markdown
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:

Comment thread src/eegclassify/util.py
c = np.array(range(2, 12))
sa, sb, sc = unison_shuffled_copies(a, b, c)
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
Copy Markdown
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 thread src/eegclassify/util.py
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
Copy Markdown
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:

Comment thread src/eegwatch/load.py
info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
raw = mne.io.RawArray(eeg_data, info)
return raw
return mne.io.RawArray(eeg_data, info)

Copy link
Copy Markdown
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:

checked = _check_samples(data.T, channel_names, max_uv_abs=max_uv_abs) # type: ignore
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

sourcery-ai Bot commented Mar 16, 2022

Copy link
Copy Markdown
Author

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

codecov Bot commented Mar 16, 2022

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.16667% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.53%. Comparing base (b927849) to head (bf732a7).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/eegwatch/main.py 0.00% 8 Missing ⚠️
src/eegwatch/devices/muse.py 0.00% 5 Missing ⚠️
src/eegwatch/lslutils.py 0.00% 2 Missing ⚠️
src/eegwatch/devices/_brainflow.py 66.66% 1 Missing ⚠️
src/eegwatch/util.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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