Passed
Push — master ( c217ce...d45644 )
by KAMI
02:43
created

osm_poi_matchmaker.dataproviders.hu_e-mobi_ev   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 72.84 %

Importance

Changes 0
Metric Value
eloc 64
dl 59
loc 81
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hu_emobi_ev.constains() 5 5 1
A hu_emobi_ev.types() 16 16 1
B hu_emobi_ev.process() 34 34 5

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 -*-
0 ignored issues
show
Coding Style Naming introduced by
Module name "hu_e-mobi_ev" doesn't conform to snake_case naming style ('[^\\W\\dA-Z][^\\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 module docstring
Loading history...
2
3
try:
4
    import traceback
5
    import logging
6
    import sys
7
    import os
8
    import pandas as pd
9
    from osm_poi_matchmaker.libs.pandas import save_downloaded_pd
0 ignored issues
show
Unused Code introduced by
Unused save_downloaded_pd imported from osm_poi_matchmaker.libs.pandas
Loading history...
10
    from osm_poi_matchmaker.libs.address import extract_street_housenumber_better_2, clean_city, clean_phone_to_str
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

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

Loading history...
Unused Code introduced by
Unused clean_phone_to_str imported from osm_poi_matchmaker.libs.address
Loading history...
11
    from osm_poi_matchmaker.libs.geo import check_hu_boundary
12
    from osm_poi_matchmaker.utils import config
13
    from osm_poi_matchmaker.libs.osm_tag_sets import POS_HU_GEN, PAY_CASH
0 ignored issues
show
Unused Code introduced by
Unused POS_HU_GEN imported from osm_poi_matchmaker.libs.osm_tag_sets
Loading history...
Unused Code introduced by
Unused PAY_CASH imported from osm_poi_matchmaker.libs.osm_tag_sets
Loading history...
14
    from osm_poi_matchmaker.utils.data_provider import DataProvider
15
    from osm_poi_matchmaker.utils.enums import FileType
16
except ImportError as err:
17
    logging.error('Error %s import module: %s', __name__, err)
18
    logging.error(traceback.print_exc())
0 ignored issues
show
Bug introduced by
The Class traceback does not seem to have a member named print_exc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
19
    sys.exit(128)
20
21
22 View Code Duplication
class hu_emobi_ev(DataProvider):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
Class name "hu_emobi_ev" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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 class docstring
Loading history...
23
24
    def constains(self):
25
        self.link = os.path.join(config.get_directory_cache_url(), 'hu_e-mobi_ev.csv')
26
        self.POI_COMMON_TAGS = ""
27
        self.filetype = FileType.csv
28
        self.filename = '{}.{}'.format(self.__class__.__name__, self.filetype.name)
29
30
    def types(self):
31
        self.__types = [{'poi_code': 'huemobichs', 'poi_name': 'e-töltőpont', 'poi_type': 'charging_station',
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...
32
                         'poi_tags': "{'amenity': 'charging_station', 'authentication:app': 'yes',"
33
                                     "'authentication:none': 'yes', 'authentication:membership_card': 'yes', "
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
34
                                     "'operator': 'e-Mobi Elektromobilitás Nonprofit Kft.', "
35
                                     "'operator:addr': '1037 Budapest, Montevideo utca 2/C', 'fee': 'yes',"
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

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

Loading history...
36
                                     "'parking:fee': 'no', 'opening_hours': '24/7', 'ref:vatin': 'HU25539431', "
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

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

Loading history...
37
                                     "'ref:vatin:hu': ' 25539431-2-41', 'ref:HU:company': '01 09 281052', "
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

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

Loading history...
38
                                     "'alt_name': 'e-mobi', 'contact:website': 'https://e-mobi.hu/hu',"
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...
39
                                     "'contact:email': '[email protected]', 'contact:phone': '+36 80 210 012', "
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/100).

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

Loading history...
40
                                     "'contact:facebook': 'https://www.facebook.com/elektromobilitas' }",
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

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

Loading history...
41
                         'poi_url_base': 'https://www.mobiliti.hu', 'poi_search_name': '(e-mobi|emobi|e-töltőpont)',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

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

Loading history...
42
                         'osm_search_distance_perfect': 50, 'osm_search_distance_safe': 30,
43
                         'osm_search_distance_unsafe': 10},
44
                        ]
45
        return self.__types
46
47
    def process(self):
48
        try:
49
            csv = pd.read_csv(self.link, encoding='UTF-8', sep=';', skiprows=1)
50
            if csv is not None:
51
                poi_dict = csv.to_dict('records')
52
                for poi_data in poi_dict:
53
                    self.data.name = 'e-töltőpont'
54
                    self.data.code = 'huemobichs'
55
                    self.data.ref = poi_data.get('Mobiliti azonosító')
56
                    self.data.branch = poi_data.get('Töltőpont neve')
57
                    self.data.postcode = poi_data.get('Irányító szám')
58
                    self.data.city = clean_city(poi_data.get('Település'))
59
                    self.data.street, self.data.housenumber, self.data.conscriptionnumber = \
60
                        extract_street_housenumber_better_2(poi_data.get('Cím'))
61
                    self.data.original = poi_data.get('Cím')
62
                    temp = poi_data.get('GPS koordináták')
63
                    if temp is None:
0 ignored issues
show
Unused Code introduced by
Unnecessary "else" after "continue"
Loading history...
64
                        continue
65
                    else:
66
                        self.data.lat, self.data.lon = temp.split(',')
67
                    self.data.lat, self.data.lon = check_hu_boundary(self.data.lat, self.data.lon)
68
                    self.data.socket_chademo = poi_data.get('Darab (CHAdeMO)')
69
                    self.data.socket_chademo_output = poi_data.get('Teljesítmény (CHAdeMO)')
70
                    self.data.socket_type2_combo = poi_data.get('Darab (CCS)')
71
                    self.data.socket_type2_combo_output = poi_data.get('Teljesítmény (CCS)')
72
                    self.data.socket_type2_cable = poi_data.get('Darab (Type 2)')
73
                    self.data.socket_type2_cable_output = poi_data.get('Teljesítmény (Type 2)')
74
                    self.data.manufacturer = poi_data.get('Töltő típusa')
75
                    self.data.model = None
76
                    self.data.capacity = poi_data.get('Kapacitás')
77
                    self.data.add()
78
        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...
79
            logging.error(traceback.print_exc())
80
            logging.error(e)
81