Passed
Pull Request — master (#2)
by Yang
02:09
created

Python.Integration.Intermediate_LORIS_LocalDB   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 31
dl 0
loc 68
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B findTimePointUpdateDatabase() 0 54 7
1
import logging
0 ignored issues
show
Coding Style Naming introduced by
The name Intermediate_LORIS_LocalDB does not conform to the module naming conventions ((([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This module 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...
2
from LocalDB.query import validateLocalTableAndSchema, check_value, update_entry, check_header_index
0 ignored issues
show
Bug introduced by
The name query does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.query'
Loading history...
3
from LORIS.timepoint import findLatestTimePoint
0 ignored issues
show
introduced by
Unable to import 'LORIS.timepoint'
Loading history...
4
from LocalDB.schema import CNBP_schema_keyfield
0 ignored issues
show
Bug introduced by
The name schema does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.schema'
Loading history...
introduced by
Imports from package LocalDB are not grouped
Loading history...
5
6
7
def findTimePointUpdateDatabase(token, DCCID, database_path, table_name):
0 ignored issues
show
Coding Style Naming introduced by
The name findTimePointUpdateDatabase does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style Naming introduced by
The name DCCID does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
8
    """
9
    Find the timepoint of the subject, IF they exist, then update the given database by finding its relevant MRN.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
10
    :param token:
11
    :param DCCID:
12
    :param database_path:
13
    :param table_name:
14
    :param ColumnName:
15
    :param ColumnValue:
16
    :return:
17
    """
18
19
    logger = logging.getLogger('Intermediate_findTimePointUpdateDatabase')
20
21
    MRN = -1
0 ignored issues
show
Coding Style Naming introduced by
The name MRN does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
22
23
24
    # todo: permission must be checked to ensure we are not geting 401 error! which is an access issue.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
25
    # todo: 2018-07-24 continue debug this code about entry creation.
26
    time_point = findLatestTimePoint(token, DCCID)
27
28
    # Timepoint Check
29
    if time_point is None:
30
        return False, "No timepoint found"
31
    else:
32
        logger.info("Timepoint retrieved okay:" + time_point)
33
34
    # Validate table and schema congruency
35
    success, reason = validateLocalTableAndSchema(database_path, table_name, "DCCID")
36
    if not success:
37
        return False, reason
38
39
    # Check local database for the rows with matching DCCID.
40
    success, subject_rows = check_value(database_path, table_name, "DCCID", DCCID)
41
    if not success:
42
        return False, "No entries with this DCCID!"
43
44
    # Recall each row WILL conform to schema.
45
    for row in subject_rows:
46
47
        # Get MRN:
48
        DCCID_table_index = check_header_index(database_path, table_name, "DCCID")
0 ignored issues
show
Coding Style Naming introduced by
The name DCCID_table_index does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
49
50
        assert (str(DCCID) == str(row[DCCID_table_index]))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
51
52
        # Need to update these rows with the new value.
53
        MRN = row[0] # the identifier of the record.
0 ignored issues
show
Coding Style Naming introduced by
The name MRN does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
54
55
        try:
56
            update_entry(database_path, table_name, CNBP_schema_keyfield, MRN, "Timepoint", time_point)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
57
        except IOError:
58
            return False, "Check the database is not read only. "
59
60
    return True, "Timepoint successfully updated in the local SQLite database."
61
62
63
if __name__ == '__main__':
64
65
    # Unit test
66
    from Integration.test_Integration import test_updateLocalTimepoint
0 ignored issues
show
introduced by
Unable to import 'Integration.test_Integration'
Loading history...
67
    test_updateLocalTimepoint()
68