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

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 Oct 19, 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 endolith October 19, 2022 18:51
Comment on lines -75 to +76
return np.asarray([x for x in dp.process_sequence(frames)])
return np.asarray(list(dp.process_sequence(frames)))

Copy link
Author

Choose a reason for hiding this comment

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

Function _dataprocessor_to_function refactored with the following changes:

Comment on lines -83 to +85
return np.asarray([x for x in dp])
return np.asarray(list(dp))

Copy link
Author

Choose a reason for hiding this comment

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

Function _source_to_function refactored with the following changes:

Comment on lines -94 to +102
if not funname in alldps:
if funname not in alldps:
if issubclass(cls, Source):
exec('%s = _source_to_function(%s)' % (funname, clsname))
exec(f'{funname} = _source_to_function({clsname})')
else:
exec('%s = _dataprocessor_to_function(%s)' % (funname, clsname))
exec(f'{funname} = _dataprocessor_to_function({clsname})')

__all__.append(clsname)
__all__.append(funname)
__all__.extend((clsname, funname))
Copy link
Author

Choose a reason for hiding this comment

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

Lines 94-101 refactored with the following changes:

if frame.ndim > 1:
mono_frame = frame.mean(1)
else:
mono_frame = frame
return mono_frame
return frame.mean(1) if frame.ndim > 1 else frame
Copy link
Author

Choose a reason for hiding this comment

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

Function Mono.process_frame refactored with the following changes:

Comment on lines -104 to +122
if not 'next' in dir(samples):
samples = (x for x in [samples])
if 'next' not in dir(samples):
samples = iter([samples])

# nhop cannot be less than 1 for normal behavior
noverlap = self.nwin - self.nhop

buf = samples.next().copy()
while len(buf) < self.nwin:
buf = np.concatenate((buf, samples.next()))

frame = buf[:self.nwin]
buf = buf[self.nwin:]

while True:
yield frame.copy()
frame[:noverlap] = frame[self.nhop:]

try:
while len(buf) < self.nhop:
buf = np.concatenate((buf, samples.next()))
except StopIteration:
break

Copy link
Author

Choose a reason for hiding this comment

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

Function Framer.process_sequence refactored with the following changes:

Comment on lines -78 to +77
mono_frames = np.array([x for x in gen])
mono_frames = np.array(list(gen))
Copy link
Author

Choose a reason for hiding this comment

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

Function TestSimpleComponents.test_mono refactored with the following changes:

Comment on lines -91 to +90
test_frames = np.array([x for x in gen])
test_frames = np.array(list(gen))
Copy link
Author

Choose a reason for hiding this comment

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

Function TestSimpleComponents.test_fft_ifft_perfect_reconstruction refactored with the following changes:

Comment on lines +12 to +18

class DP(DataProcessor):
def process_frame(self, frame):
return 2 * frame

frames = np.random.rand(50, 2);
dpframes = np.asarray([x for x in DP().process_sequence(frames)])
dpframes = np.asarray(list(DP().process_sequence(frames)))
Copy link
Author

Choose a reason for hiding this comment

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

Function TestDataProcessor.test_process_frame refactored with the following changes:

Comment on lines +26 to +33

class DP(DataProcessor):
def process_sequence(self, frames):
for frame in frames:
yield 2 * frame

frames = np.random.rand(50, 2);
dpframes = np.asarray([x for x in DP().process_sequence(frames)])
dpframes = np.asarray(list(DP().process_sequence(frames)))
Copy link
Author

Choose a reason for hiding this comment

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

Function TestDataProcessor.test_iter refactored with the following changes:

@@ -38,14 +40,15 @@ def process_sequence(self, frames):

class TestPipeline(unittest.TestCase):
def test_pipeline(self):

Copy link
Author

Choose a reason for hiding this comment

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

Function TestPipeline.test_pipeline refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Oct 19, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 2.41 ⭐ 2.33 ⭐ -0.08 👍
Method Length 45.43 ⭐ 45.06 ⭐ -0.37 👍
Working memory 7.06 🙂 6.96 🙂 -0.10 👍
Quality 76.49% 76.85% 0.36% 👍
Other metrics Before After Change
Lines 976 967 -9
Changed files Quality Before Quality After Quality Change
init.py 82.21% ⭐ 82.95% ⭐ 0.74% 👍
basic.py 78.69% ⭐ 78.49% ⭐ -0.20% 👎
chroma.py 65.05% 🙂 65.94% 🙂 0.89% 👍
dataprocessor.py 89.52% ⭐ 89.55% ⭐ 0.03% 👍
mfcc.py 74.29% 🙂 73.43% 🙂 -0.86% 👎
mock_sndfile.py 79.96% ⭐ 79.96% ⭐ 0.00%
sources.py 69.17% 🙂 69.07% 🙂 -0.10% 👎
tests/test_basic.py 76.59% ⭐ 77.02% ⭐ 0.43% 👍
tests/test_dataprocessor.py 79.80% ⭐ 82.47% ⭐ 2.67% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
chroma.py constantqfb 4 ⭐ 208 ⛔ 13 😞 48.64% 😞 Try splitting into smaller methods. Extract out complex expressions
basic.py Framer.process_sequence 8 ⭐ 205 ⛔ 10 😞 50.19% 🙂 Try splitting into smaller methods. Extract out complex expressions
chroma.py chromafb 1 ⭐ 227 ⛔ 12 😞 51.94% 🙂 Try splitting into smaller methods. Extract out complex expressions
mfcc.py melfb 2 ⭐ 178 😞 11 😞 56.31% 🙂 Try splitting into smaller methods. Extract out complex expressions
tests/test_basic.py TestFramer._test_framer 4 ⭐ 124 😞 10 😞 61.91% 🙂 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
0 participants