Completed
Pull Request — master (#43)
by Wojtek
03:06
created

VelocityCalculator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
ccs 21
cts 21
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A _s2() 0 4 1
A _s0() 0 2 1
A _s1() 0 4 1
A calculate_initial_velocity() 0 5 1
A __init__() 0 6 1
A calculate() 0 6 1
1
"""Contains things related to calculating velocity."""
2
3 1
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
5
6 1
class VelocityCalculator:
7
    """Calculate Velocity for single stage.
8
9
    Attributes:
10
        current_velocity (list) : list of coordinates of speed for current stage
11
        """
12
13 1
    def __init__(self, stage):
14 1
        self.stage = stage
15 1
        self.c_1 = 0.5
16 1
        self.c_2 = 0.5
17 1
        self.w_factor = 0.8
18 1
        self.current_velocity = None
19
20 1
    def calculate_initial_velocity(self):
21
        """Calculate initial velocity."""
22 1
        velocity = 0.02 * np.random.rand(len(self.stage.control_params)) - 0.01
23 1
        self.current_velocity = velocity
24 1
        return velocity
25
26 1
    def calculate(self, particle_best_position, leader_best_position):
27
        """Calculate velocity."""
28 1
        velocity = self._s0() + self.c_1 * self._s1(
29
            leader_best_position) + self.c_2 * self._s2(particle_best_position)
30 1
        self.current_velocity = velocity
31 1
        return velocity
32
33 1
    def _s2(self, particle_best_position):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
34 1
        return np.random.rand(len(self.stage.control_params)) * (
35
            np.asarray(particle_best_position) - np.asarray(
36
                self.stage.control_params))
37
38 1
    def _s1(self, leader_best_position):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
39 1
        return np.random.rand(len(self.stage.control_params)) * (
40
            np.asarray(leader_best_position) - np.asarray(
41
                self.stage.control_params))
42
43 1
    def _s0(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
44
        return self.w_factor * self.current_velocity
45