Passed
Pull Request — master (#946)
by Mofenyi
10:09 queued 03:58
created

bika.lims.exportimport.instruments.taqman.dna212bs   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 65.33 %

Importance

Changes 0
Metric Value
wmc 10
eloc 49
dl 49
loc 75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TaqMan96DNA212BSCSVParser.parse_data_line() 28 28 3
A TaqMan96DNA212BSCSVParser._parseline() 11 11 5
A TaqMan96DNA212BSCSVParser.__init__() 7 7 1
A TaqMan96DNA212BSImporter.__init__() 0 8 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
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE
4
#
5
# Copyright 2018 by it's authors.
6
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
7
8
""" Beckman Couter Access
9
"""
10
from datetime import datetime
11
from bika.lims.exportimport.instruments.resultsimport import \
12
    AnalysisResultsImporter, InstrumentCSVResultsFileParser
13
14
15 View Code Duplication
class TaqMan96DNA212BSCSVParser(InstrumentCSVResultsFileParser):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
16
    def __init__(self, csv):
17
        InstrumentCSVResultsFileParser.__init__(self, csv)
18
        self._columns = []  # The different columns names
19
        self._values = {}  # The analysis services from the same resid
20
        self._resid = ''  # A stored resid
21
        self._rownum = None
22
        self._end_header = False
23
24
    def _parseline(self, line):
25
        sline = line.split(',')
26
        if len(sline) > 0 and not self._end_header:
27
            self._columns = sline
28
            self._end_header = True
29
            return 0
30
        elif sline > 0 and self._end_header:
31
            self.parse_data_line(sline)
32
        else:
33
            self.err("Unexpected data format", numline=self._numline)
34
            return -1
35
36
    def parse_data_line(self, sline):
37
        """
38
        Parses the data line and builds the dictionary.
39
        :param sline: a split data line to parse
40
        :returns: the number of rows to jump and parse the next data line or return the code error -1
41
        """
42
        # if there are less values founded than headers, it's an error
43
        if len(sline) != len(self._columns):
44
            self.err("One data line has the wrong number of items")
45
            return -1
46
        #print self._columns
47
        rawdict = {}
48
        for idx, result in enumerate(sline):
49
            rawdict[self._columns[idx]] = result
50
        # Getting key values
51
        resid = rawdict['Sample ID']
52
        del rawdict['Sample ID']
53
        testname = rawdict['Test']
54
        del rawdict['Test']
55
56
        # Building the new dict
57
        rawdict['DefaultResult'] = 'Result'
58
        rawdict['Remarks'] = rawdict['Comment']
59
        del rawdict['Comment']
60
        print rawdict
61
62
        self._addRawResult(resid, {testname: rawdict}, False)
63
        return 0
64
65
66
class TaqMan96DNA212BSImporter(AnalysisResultsImporter):
67
    def __init__(self, parser, context, idsearchcriteria, override,
68
                 allowed_ar_states=None, allowed_analysis_states=None,
69
                 instrument_uid=None):
70
        AnalysisResultsImporter.__init__(self, parser, context,
71
                                         idsearchcriteria, override,
72
                                         allowed_ar_states,
73
                                         allowed_analysis_states,
74
                                         instrument_uid)
75