PositionUpdater   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 40
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 40
ccs 22
cts 22
cp 1
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set_initial_control_params() 0 10 2
A __init__() 0 2 1
A _fix_coordinates() 0 8 4
A update_position() 0 9 2
1
"""Contain mechanism for changing position."""
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 PositionUpdater:
7
    """Class responsible for moving objects.
8
9
        Attributes:
10
            stage (AbstractStage): Stage in which we are going to move.
11
            control_params (dict): Control params for stages.
12
    """
13
14 1
    def __init__(self, control_params):
15 1
        self.control_params = control_params
16
17 1
    @staticmethod
18
    def set_initial_control_params(control_params):
19
        """Set initial positions."""
20 1
        for stage in control_params:
21 1
            random = np.random.rand(len(control_params[stage]))
22 1
            delta = np.asarray(stage.upper_bounds) - np.asarray(
23
                stage.lower_bounds)
24 1
            new_control_params = np.asarray(stage.lower_bounds) + random * delta
25 1
            control_params[stage] = new_control_params.tolist()
26 1
        return control_params
27
28 1
    def update_position(self, velocities, control_params):
29
        """Update positions."""
30 1
        for stage in velocities:
31 1
            new_control_params = np.asarray(control_params[stage]) + np.asarray(
32
                velocities[stage])
33 1
            control_params[stage] = self._fix_coordinates(stage,
34
                                                          new_control_params) \
35
                .tolist()
36 1
        return control_params
37
38 1
    @staticmethod
39
    def _fix_coordinates(stage, control_params):
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...
40 1
        for index, single_param in enumerate(control_params):
41 1
            if single_param > stage.upper_bounds[index]:
42 1
                control_params[index] = stage.upper_bounds[index]
43 1
            elif single_param < stage.lower_bounds[index]:
44 1
                control_params[index] = stage.lower_bounds[index]
45
        return control_params
46