Test Failed
Push — master ( 15d240...157f6a )
by Daniil
01:26 queued 18s
created

examples.plugin_examples.plugin_templates.general.plugin_template1   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 50 %

Importance

Changes 0
Metric Value
eloc 25
dl 30
loc 60
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A PluginTemplate1.__init__() 2 2 1
A PluginTemplate1.nInput_datasets() 2 2 1
A PluginTemplate1.nOutput_datasets() 2 2 1
A PluginTemplate1.pre_process() 2 2 1
A PluginTemplate1.process_frames() 5 5 1
A PluginTemplate1.post_process() 2 2 1
A PluginTemplate1.setup() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# Copyright 2014 Diamond Light Source Ltd.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
15
"""
16
.. module:: plugin_template1
17
   :platform: Unix
18
   :synopsis: A template to create a simple plugin that takes one dataset as\
19
   input and returns a similar dataset as output.
20
21
.. moduleauthor:: Developer Name <[email protected]>
22
23
"""
24
25
from savu.plugins.plugin import Plugin
26
from savu.plugins.driver.cpu_plugin import CpuPlugin
27
from savu.plugins.utils import register_plugin
28
29
30 View Code Duplication
@register_plugin
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
31
class PluginTemplate1(Plugin, CpuPlugin):
32
33
    def __init__(self):
34
        super(PluginTemplate1, self).__init__('PluginTemplate1')
35
36
    def nInput_datasets(self):
37
        return 1
38
39
    def nOutput_datasets(self):
40
        return 1
41
42
    def setup(self):
43
        in_dataset, out_dataset = self.get_datasets()
44
        out_dataset[0].create_dataset(in_dataset[0])
45
        in_pData, out_pData = self.get_plugin_datasets()
46
        in_pData[0].plugin_data_setup('SINOGRAM', 'single')
47
        out_pData[0].plugin_data_setup('SINOGRAM', 'single')
48
49
    def pre_process(self):
50
        pass
51
52
    def process_frames(self, data):
53
        # do some processing here
54
        # here is how to access a parameter defined in the tools file
55
        example = self.parameters['example']
56
        return data[0]*example
57
58
    def post_process(self):
59
        pass