Skip to content

Commit

Permalink
Remove code using non existing column
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Dec 23, 2023
1 parent 9476be3 commit 423cb29
Showing 1 changed file with 0 additions and 167 deletions.
167 changes: 0 additions & 167 deletions analysers/analyser_merge_charging_station_FR.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
## ##
###########################################################################

import unittest
from modules.OsmoseTranslation import T_
from .Analyser_Merge import Analyser_Merge_Point, Source, CSV, Load_XY, Conflate, Select, Mapping
import re


class Analyser_Merge_Charging_station_FR(Analyser_Merge_Point):
Expand All @@ -36,88 +34,6 @@ class Analyser_Merge_Charging_station_FR(Analyser_Merge_Point):
"lidl": "Q115764851",
}

def remove_trailing_zeros(input_string):
"""
Removes all trailing zeros from a string.
Args:
input_string (str): The input string to remove trailing zeros from.
Returns:
str: The input string with all trailing zeros removed.
"""
input_string = str(input_string).replace(',', '.').replace(' ', '').strip()
return re.sub(r'[.,]0+$', '', input_string)

@staticmethod
def is_float(str):
"""
Returns True if the input string can be converted to a float, False otherwise.
"""
pattern = r"^-?\d+(\.\d+)?$"
return bool(re.match(pattern, str))

def socket_output_find_correspondances(self, power: str):
"""
convert the number of Watts to kiloWatts
output example:
- "400 kW"
- "7 kW"
- "50.6 kW"
"""

power = power.replace(',', '.')

# remove extremely high values or the ones containing letters
max_output_kw = 1999
# we take an upper limit of 400 kW
max_kw = 401

# values under the max expected kW are used as is,
# upper values are Watts, which we should divide by 1000 to get kW

if not power:
return None
if re.search(r"[a-zA-Z]+", power):
return None

if not self.is_float(power) and int(power) > max_output_kw:
power = int(power) / 1000

if not self.is_float(power) or float(power) < 1:
return None

# clean the values of power
string_power = str(round(float(power), 2))
cleaned_power = self.remove_trailing_zeros(string_power)
if float(power) < max_output_kw:
return '{0} kW'.format(cleaned_power)

else:
if float(power) > (max_kw * 1000):
return None

if float(cleaned_power) > max_output_kw and float(cleaned_power) < (
max_kw * 1000):
cleaned_power = self.remove_trailing_zeros(
float(cleaned_power) / 1000)
if float(cleaned_power) > max_output_kw:
return None
else:
if float(cleaned_power) > max_kw:
return '{0} kW'.format(
self.remove_trailing_zeros(float(power) / 1000))
else:
cleaned_power = float(cleaned_power) / 1000

if float(cleaned_power) > max_kw:
return None

if cleaned_power != 0:
return '{0} kW'.format(cleaned_power)
else:
return None

def __init__(self, config, logger=None):
Analyser_Merge_Point.__init__(self, config, logger)
doc = dict(
Expand Down Expand Up @@ -170,7 +86,6 @@ def __init__(self, config, logger=None):
"operator:email": "contact_operateur",
"start_date": "date_mise_en_service",
"capacity": "nbre_pdc",
"charging_station:output": lambda fields: self.socket_output_find_correspondances(fields["puissance_nominale"]) if fields["puissance_nominale"] else None,
"bicycle": lambda fields: "yes" if fields["station_deux_roues"] == "true" else None,
"motorcycle": lambda fields: "yes" if fields["station_deux_roues"] == "true" else None,
"moped": lambda fields: "yes" if fields["station_deux_roues"] == "true" else None,
Expand All @@ -183,90 +98,8 @@ def __init__(self, config, logger=None):
"wheelchair": lambda fields: "yes" if fields["accessibilite_pmr_grouped"] == "Accessible mais non réservé PMR" else ("no" if fields["accessibilite_pmr_grouped"] == "Non accessible" else None),
"socket:typee": lambda fields: fields["nb_EF_grouped"] if fields["nb_EF_grouped"] != "0" else None,
"socket:type2": lambda fields: fields["nb_T2_grouped"] if fields["nb_T2_grouped"] != "0" else None,
"socket:type2_cable": lambda fields: fields["cable_t2_attache"] if fields["cable_t2_attache"] == "1" else None,
"socket:type2_combo": lambda fields: fields["nb_combo_ccs_grouped"] if fields["nb_combo_ccs_grouped"] != "0" else None,
"socket:chademo": lambda fields: fields["nb_chademo_grouped"] if fields["nb_chademo_grouped"] != "0" else None,
"wikimedia:network": lambda fields: self.WIKIDATA_MAP.get(fields["nom_enseigne"].lower(), None) if fields["nom_enseigne"] != "0" else None,
},
text=lambda tags, fields: {"en": "{0}, {1}, {2}".format(fields["nom_station"], fields["adresse_station"], fields["observations"] if fields["observations"] != "null" else "-")})))


###########################################################################


class Test(unittest.TestCase):
def test_output_kw_bad_input(self):
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, 'bonjour'), None)
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '0'), None)
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, ''), None)
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, 'Non applicable'), None)
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '132456789'), None)

def test_output_watts(self):
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '3,6'), '3.6 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '50000'), '50 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '400000'), '400 kW')

def test_output_kw_round(self):
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '150'), '150 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '300'), '300 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '50'), '50 kW')

def test_output_kw_float(self):
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '50.7'), '50.7 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '1001.000'), '1001 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '100.01'), '100.01 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '50.0'), '50 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '50.00'), '50 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '1.00'), '1 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '1.0'), '1 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '1'), '1 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '7.40'), '7.4 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR,
'7.00000000000'),
'7 kW')
self.assertEqual(
Analyser_Merge_Charging_station_FR.socket_output_find_correspondances(
Analyser_Merge_Charging_station_FR, '3.6'), '3.6 kW')

0 comments on commit 423cb29

Please sign in to comment.