Completed
Branch master (9edffc)
by Jordi
04:36
created

bika.lims.exportimport.instruments.lifetechnologies.qubit.qubit   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 82
Duplicated Lines 76.83 %

Importance

Changes 0
Metric Value
wmc 12
eloc 57
dl 63
loc 82
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
D Import() 63 63 12

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
""" Life Technologies Qubit
9
"""
10
from bika.lims import bikaMessageFactory as _
11
from bika.lims.utils import t
12
from . import QuBitCSVParser, QuBitImporter
13
import json
14
import traceback
15
16
title = "Life Technolgies - Qubit"
17
18
19 View Code Duplication
def Import(context, request):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
20
    """ Read qubit analysis results
21
    """
22
    infile = request.form['filename']
23
    fileformat = request.form['format']
24
    artoapply = request.form['artoapply']
25
    override = request.form['override']
26
27
    instrument = request.form.get('instrument', None)
28
    errors = []
29
    logs = []
30
    warns = []
31
32
    # Load the suitable parser
33
    parser = None
34
    if not hasattr(infile, 'filename'):
35
        errors.append(_("No file selected"))
36
    elif fileformat == 'csv':
37
        analysis = request.form.get('analysis', None)
38
        if analysis:
39
            parser = QuBitCSVParser(infile, analysis)
40
        else:
41
            errors.append(t(_("No analysis selected")))
42
    else:
43
        errors.append(t(_("Unrecognized file format ${fileformat}",
44
                          mapping={"fileformat": fileformat})))
45
46
    if parser:
47
        # Load the importer
48
        status = ['sample_received', 'attachment_due', 'to_be_verified']
49
        if artoapply == 'received':
50
            status = ['sample_received']
51
        elif artoapply == 'received_tobeverified':
52
            status = ['sample_received', 'attachment_due', 'to_be_verified']
53
54
        over = [False, False]
55
        if override == 'nooverride':
56
            over = [False, False]
57
        elif override == 'override':
58
            over = [True, False]
59
        elif override == 'overrideempty':
60
            over = [True, True]
61
62
        importer = QuBitImporter(parser=parser,
63
                                 context=context,
64
                                 allowed_ar_states=status,
65
                                 allowed_analysis_states=None,
66
                                 override=over,
67
                                 instrument_uid=instrument)
68
69
        tbex = ''
70
        try:
71
            importer.process()
72
        except:
73
            tbex = traceback.format_exc()
74
        errors = importer.errors
75
        logs = importer.logs
76
        warns = importer.warns
77
        if tbex:
78
            errors.append(tbex)
79
80
    results = {'errors': errors, 'log': logs, 'warns': warns}
81
    return json.dumps(results)
82