osm_poi_matchmaker.libs.gis.closest_point()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
try:
4
    import logging
5
    import sys
6
    from scipy.spatial import distance
7
except ImportError as err:
8
    logging.error('Error %s import module: %s', __name__, err)
9
    logging.exception('Exception occurred')
10
11
    sys.exit(128)
12
13
14
def closest_point(point, points):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
15
    # Find closest point from a list of points
16
    pt = points[distance.cdist([point], points).argmin()]
0 ignored issues
show
Coding Style Naming introduced by
Variable name "pt" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
17
    return pt
18
19
20
def closest_point_distance(point, points):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
21
    # Find closest point from a list of points
22
    pt = points[distance.cdist([point], points).argmin()]
0 ignored issues
show
Coding Style Naming introduced by
Variable name "pt" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
23
    pt_dist = '{:10.8f}'.format(distance.euclidean(point, pt))
24
    return pt_dist
25
26
27
def match_value(df, col1, x, col2):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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
Argument name "x" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
28
    # Match value x from col1 row to value in col2
29
    return df[df[col1] == x][col2].values[0]
30
31
32
def finding_closest(data1, data2):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
33
    # Add stop_id and stop_name to the closest point
34
    logging.info('Finding closest coordinates')
35
    data2['closest'] = [closest_point(x, list(data1['point'])) for x in data2['point']]
36
    logging.info('Calculating closest coordinates distances')
37
    data2['dist_closest'] = [closest_point_distance(x, list(data1['point'])) for x in data2['point']]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

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

Loading history...
38
    logging.info('Selecting matching stop_id')
39
    data2['stop_id'] = [match_value(data1, 'point', x, 'stop_id') for x in data2['closest']]
40
    logging.info('Selecting matching name')
41
    data2['stop_name'] = [match_value(data1, 'point', x, 'stop_name') for x in data2['closest']]
42
    return data2
43