osm_poi_matchmaker.libs.export   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 12

4 Functions

Rating   Name   Duplication   Size   Complexity  
B export_grouped_poi_data_with_postcode_groups() 0 28 6
A export_raw_poi_data_xml() 0 3 2
A export_grouped_poi_data() 0 14 3
A export_raw_poi_data() 0 5 1
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
    import os
7
    from osm_poi_matchmaker.libs.file_output import save_csv_file, generate_osm_xml
8
    from osm_poi_matchmaker.utils import config
9
except ImportError as err:
10
    logging.error('Error %s import module: %s', __name__, err)
11
    logging.exception('Exception occurred')
12
13
    sys.exit(128)
14
15
16
def export_raw_poi_data(addr_data, comm_data, postfix=''):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
17
    logging.info('Exporting CSV files ...')
18
    # And merge and them into one Dataframe and save it to a CSV file
19
    save_csv_file(config.get_directory_output(), 'poi_common{}.csv'.format(postfix), comm_data, 'poi_common')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

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

Loading history...
20
    save_csv_file(config.get_directory_output(), 'poi_address{}.csv'.format(postfix), addr_data, 'poi_address')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

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

Loading history...
21
22
23
def export_raw_poi_data_xml(addr_data, postfix=''):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
24
    with open(os.path.join(config.get_directory_output(), 'poi_address{}.osm'.format(postfix)), 'wb') as oxf:
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

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

Loading history...
25
        oxf.write(generate_osm_xml(addr_data))
26
27
28
def export_grouped_poi_data(data):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
29
    try:
30
        # Generating CSV files group by poi_code
31
        output_dir = data[0]
32
        filename = data[1]
33
        rows = data[2]
34
        table = data[3]
35
        # Generating CSV files group by poi_code
36
        save_csv_file(output_dir, '{}.csv'.format(filename), rows, table)
37
        with open(os.path.join(output_dir, '{}.osm'.format(filename)), 'wb') as oxf:
38
            oxf.write(generate_osm_xml(rows))
39
    except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
Variable name "e" 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...
40
        logging.error(e)
41
        logging.exception('Exception occurred')
42
43
44
def export_grouped_poi_data_with_postcode_groups(data):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
45
    try:
46
        # Generating CSV files group by poi_code and postcode
47
        output_dir = data[0]
48
        filename = data[1]
49
        rows = data[2]
50
        # Maximum number of items in one file
51
        batch = 100
52
        # Minimum difference between postcode grouped data sets
53
        postcode_gap = 200
54
        # Postcode minimum value
55
        postcode_start = 1000
56
        # Postcode maximum value
57
        postcode_stop = 9999
58
        if len(rows) > batch:
59
            # Create sliced data output
60
            i = postcode_start
61
            for i in range(postcode_start, postcode_stop, postcode_gap):
62
                stop = i + postcode_gap - 1
63
                xml_export = rows[rows['poi_postcode'].between(i, stop)]
64
                print(xml_export.to_string())
65
                if len(xml_export) != 0:
66
                    with open(os.path.join(output_dir, '{}_{:04d}-{:04d}.osm'.format(filename, i, stop)), 'wb') as oxf:
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

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

Loading history...
67
                        oxf.write(generate_osm_xml(xml_export))
68
                i += postcode_gap
69
    except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
Variable name "e" 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...
70
        logging.error(e)
71
        logging.exception('Exception occurred')
72