forked from Olav63/outils_OSM
ajout d'une barre de progression
This commit is contained in:
parent
6d288c1672
commit
e6b432af4e
@ -142,7 +142,8 @@ class Utils:
|
|||||||
def geocodage(self, data):
|
def geocodage(self, data):
|
||||||
"""Renseigne une adresse pour chaque élément de data"""
|
"""Renseigne une adresse pour chaque élément de data"""
|
||||||
|
|
||||||
for element in data["elements"]:
|
for element in self.progress_bar(data["elements"], prefix="Géocodage"):
|
||||||
|
|
||||||
if element["type"] == "node":
|
if element["type"] == "node":
|
||||||
rev_geocode = self.run_reverse_geocoding(element["lat"], element["lon"])
|
rev_geocode = self.run_reverse_geocoding(element["lat"], element["lon"])
|
||||||
else:
|
else:
|
||||||
@ -208,3 +209,43 @@ class Utils:
|
|||||||
element["tags"][tag] = dictionnaire[element["tags"][tag]]
|
element["tags"][tag] = dictionnaire[element["tags"][tag]]
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def progress_bar(
|
||||||
|
# pylint:disable=C0330
|
||||||
|
self,
|
||||||
|
iterable,
|
||||||
|
decimals=1,
|
||||||
|
length=50,
|
||||||
|
prefix="",
|
||||||
|
fill="█",
|
||||||
|
print_end="\r",
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Call in a loop to create terminal progress bar
|
||||||
|
@params:
|
||||||
|
iterable - Required : iterable object (Iterable)
|
||||||
|
decimals - Optional : positive number of decimals in percent complete (Int)
|
||||||
|
length - Optional : character length of bar (Int)
|
||||||
|
prefix - Optional : prefix string (Str)
|
||||||
|
fill - Optional : bar fill character (Str)
|
||||||
|
print_end - Optional : end character (e.g. "\r", "\r\n") (Str)
|
||||||
|
"""
|
||||||
|
total = len(iterable)
|
||||||
|
|
||||||
|
if total == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Initial Call
|
||||||
|
print(f"\r{prefix} |{'-' * length}| {0}%", end=print_end)
|
||||||
|
# Update Progress Bar
|
||||||
|
for i, item in enumerate(iterable):
|
||||||
|
yield item
|
||||||
|
percent = ("{0:." + str(decimals) + "f}").format(
|
||||||
|
100 * ((i + 1) / float(total))
|
||||||
|
)
|
||||||
|
filled = int(length * (i + 1) // total)
|
||||||
|
progress = fill * filled + "-" * (length - filled)
|
||||||
|
print(f"\r{prefix} |{progress}| {percent}%", end=print_end)
|
||||||
|
|
||||||
|
# Print New Line on Complete
|
||||||
|
print()
|
||||||
|
Loading…
Reference in New Issue
Block a user