Test Failed
Pull Request — master (#862)
by Daniil
03:30
created

examples.plugin_examples.plugin_templates.general.plugin_template1_with_detailed_notes   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 114
Duplicated Lines 71.05 %

Importance

Changes 0
Metric Value
eloc 24
dl 81
loc 114
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A PluginTemplate1WithDetailedNotes.__init__() 2 2 1
A PluginTemplate1WithDetailedNotes.process_frames() 13 13 1
A PluginTemplate1WithDetailedNotes.nOutput_datasets() 3 3 1
A PluginTemplate1WithDetailedNotes.nInput_datasets() 3 3 1
A PluginTemplate1WithDetailedNotes.post_process() 4 4 1
A PluginTemplate1WithDetailedNotes.pre_process() 5 5 1
A PluginTemplate1WithDetailedNotes.setup() 39 39 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
# the information below is used in the auto-API creation for documentation
17
# and the synopsis appears in the configurator.
18
"""
19
.. module:: plugin_template1_with_detailed_notes
20
   :platform: Unix
21
   :synopsis: A template to create a simple plugin that takes one dataset as\
22
   input and returns a similar dataset as output.
23
24
.. moduleauthor:: Developer Name <[email protected]>
25
26
"""
27
28
from savu.plugins.plugin import Plugin
29
from savu.plugins.driver.cpu_plugin import CpuPlugin
30
from savu.plugins.utils import register_plugin
31
32
# this decorator is required for the configurator to recognise the plugin
33 View Code Duplication
@register_plugin
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
34
class PluginTemplate1WithDetailedNotes(Plugin, CpuPlugin):
35
# Each class must inherit from the Plugin class and a driver
36
    def __init__(self):
37
        super(PluginTemplate1WithDetailedNotes, self).__init__('PluginTemplate1WithDetailedNotes')
38
39
    def nInput_datasets(self):
40
        # Called immediately after the plugin is loaded in to the framework
41
        return 1
42
43
    def nOutput_datasets(self):
44
        # Called immediately after the plugin is loaded in to the framework
45
        return 1
46
47
    def setup(self):
48
        # This method is called after the number of in/out datasets associated
49
        # with the plugin has been established.  It tells the framework all
50
        # the information it needs to know about the data transport to-and-from
51
        # the plugin.
52
53
54
        #================== Input and output datasets =========================
55
        # in_datasets and out_datasets are instances of the Data class.
56
        # in_datasets were either created in the loader or as output from
57
        # previous plugins.  out_datasets objects have already been created at
58
        # this point, but they are empty and need to be populated.
59
60
        # Get the Data instances associated with this plugin
61
        in_dataset, out_dataset = self.get_datasets()
62
63
        # see https://savu.readthedocs.io/en/latest/api/savu.data.data_structures.data_create/
64
        # for more information on creating datasets.
65
66
        # Populate the output dataset(s)
67
        out_dataset[0].create_dataset(in_dataset[0])
68
69
70
        #================== Input and output plugin datasets ==================
71
        # in_pData and out_pData are instances of the PluginData class.
72
        # All in_datasets and out_datasets above have an in/out_pData object
73
        # attached to them temporarily for the duration of the plugin,
74
        # giving access to additional plugin-specific dataset details. At this
75
        # point they have been created but not yet populated.
76
77
        # Get the PluginData instances attached to the Data instances above
78
        in_pData, out_pData = self.get_plugin_datasets()
79
80
        # Each plugin dataset must call this method and define the data access
81
        # pattern and number of frames required.
82
        in_pData[0].plugin_data_setup('SINOGRAM', 'single')
83
84
        # 'single', 'multiple' or an int (should only be used if essential)
85
        out_pData[0].plugin_data_setup('SINOGRAM', 'single')
86
        
87
        # All dataset information can be accessed via the Data and PluginData
88
        # instances
89
90
    def pre_process(self):
91
        # This method is called once before any processing has begun.
92
        # Access parameters from the doc string in the parameters dictionary
93
        # e.g. self.parameters['example']
94
        pass
95
96
    def process_frames(self, data):
97
        # This function is called in a loop by the framework until all the
98
        # data has been processed.
99
    
100
        # Each iteration of the loop will receive a list of numpy arrays
101
        # (data) containing nInput_datasets with the data sliced as requested
102
        # in the setup method (SINOGRAM in this case).  If 'multiple' or an 
103
        # integer number of max_frames are requested the array with have an
104
        # extra dimension.
105
106
        # This plugin has one output dataset, so a single numpy array (a
107
        # SINOGRAM in this case) should be returned to the framework.
108
        return data[0]
109
110
    def post_process(self):
111
        # This method is called once after all processing has completed
112
        # (after an MPI barrier).
113
        pass