mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-30 17:36:27 +02:00
Rename text; add voltage and frequency processing.
This commit is contained in:
parent
bbf96a5b33
commit
93b7883f99
2 changed files with 55 additions and 7 deletions
|
@ -5,7 +5,7 @@ import numpy as np
|
||||||
import svgwrite
|
import svgwrite
|
||||||
from colour import Color
|
from colour import Color
|
||||||
|
|
||||||
from roentgen.address import get_address
|
from roentgen.text import get_address, get_text
|
||||||
from roentgen.color import is_bright
|
from roentgen.color import is_bright
|
||||||
from roentgen.icon import Icon
|
from roentgen.icon import Icon
|
||||||
from roentgen.osm_reader import Tagged
|
from roentgen.osm_reader import Tagged
|
||||||
|
@ -91,6 +91,10 @@ def construct_text(
|
||||||
if draw_captions == "main":
|
if draw_captions == "main":
|
||||||
return texts
|
return texts
|
||||||
|
|
||||||
|
for text in get_text(tags): # type: str
|
||||||
|
if text:
|
||||||
|
texts.append(TextStruct(text))
|
||||||
|
|
||||||
if "route_ref" in tags:
|
if "route_ref" in tags:
|
||||||
texts.append(TextStruct(tags["route_ref"].replace(";", " ")))
|
texts.append(TextStruct(tags["route_ref"].replace(";", " ")))
|
||||||
tags.pop("route_ref", None)
|
tags.pop("route_ref", None)
|
||||||
|
@ -167,8 +171,8 @@ class Point(Tagged):
|
||||||
if painted:
|
if painted:
|
||||||
self.y += 16
|
self.y += 16
|
||||||
|
|
||||||
if not self.icon_set.extra_icons or \
|
if (not self.icon_set.extra_icons or
|
||||||
(self.icon_set.main_icon and not painted):
|
(self.icon_set.main_icon and not painted)):
|
||||||
return
|
return
|
||||||
|
|
||||||
is_place_for_extra: bool = True
|
is_place_for_extra: bool = True
|
||||||
|
@ -189,7 +193,8 @@ class Point(Tagged):
|
||||||
svg, shape_ids, self.point + np.array((left, self.y)),
|
svg, shape_ids, self.point + np.array((left, self.y)),
|
||||||
Color("#888888"), occupied)
|
Color("#888888"), occupied)
|
||||||
left += 16
|
left += 16
|
||||||
self.y += 16
|
if self.icon_set.extra_icons:
|
||||||
|
self.y += 16
|
||||||
|
|
||||||
def draw_point_shape(
|
def draw_point_shape(
|
||||||
self, svg: svgwrite.Drawing, icons: List[Icon], position,
|
self, svg: svgwrite.Drawing, icons: List[Icon], position,
|
||||||
|
@ -260,7 +265,7 @@ class Point(Tagged):
|
||||||
|
|
||||||
if occupied:
|
if occupied:
|
||||||
is_occupied: bool = False
|
is_occupied: bool = False
|
||||||
for i in range(-int(length / 2), int(length/ 2)):
|
for i in range(-int(length / 2), int(length / 2)):
|
||||||
if occupied.check((int(point[0] + i), int(point[1] - 4))):
|
if occupied.check((int(point[0] + i), int(point[1] - 4))):
|
||||||
is_occupied = True
|
is_occupied = True
|
||||||
break
|
break
|
||||||
|
@ -290,4 +295,3 @@ class Point(Tagged):
|
||||||
font_family=DEFAULT_FONT, fill=fill.hex))
|
font_family=DEFAULT_FONT, fill=fill.hex))
|
||||||
|
|
||||||
self.y += 11
|
self.y += 11
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ def get_address(tags: Dict[str, Any], draw_captions_mode: str) -> List[str]:
|
||||||
"""
|
"""
|
||||||
address: List[str] = []
|
address: List[str] = []
|
||||||
|
|
||||||
if draw_captions_mode != "main":
|
if draw_captions_mode == "address":
|
||||||
if "addr:postcode" in tags:
|
if "addr:postcode" in tags:
|
||||||
address.append(tags["addr:postcode"])
|
address.append(tags["addr:postcode"])
|
||||||
tags.pop("addr:postcode", None)
|
tags.pop("addr:postcode", None)
|
||||||
|
@ -37,3 +37,47 @@ def get_address(tags: Dict[str, Any], draw_captions_mode: str) -> List[str]:
|
||||||
tags.pop("addr:housenumber", None)
|
tags.pop("addr:housenumber", None)
|
||||||
|
|
||||||
return address
|
return address
|
||||||
|
|
||||||
|
|
||||||
|
def format_voltage(value: str) -> str:
|
||||||
|
"""
|
||||||
|
Format voltage value to more human-readable form.
|
||||||
|
|
||||||
|
:param value: presumably string representation of integer, in Volts
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
int_value: int = int(value)
|
||||||
|
if int_value % 1000 == 0:
|
||||||
|
return f"{int(int_value / 1000)} kV"
|
||||||
|
return f"{value} V"
|
||||||
|
except ValueError:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def format_frequency(value: str) -> str:
|
||||||
|
try:
|
||||||
|
int_value: int = int(value)
|
||||||
|
return f"{value} Hz"
|
||||||
|
except ValueError:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def get_text(tags: Dict[str, Any]) -> List[str]:
|
||||||
|
|
||||||
|
texts: List[str] = []
|
||||||
|
|
||||||
|
values: List[str] = []
|
||||||
|
if "voltage:primary" in tags:
|
||||||
|
values.append(tags["voltage:primary"])
|
||||||
|
if "voltage:secondary" in tags:
|
||||||
|
values.append(tags["voltage:secondary"])
|
||||||
|
if "voltage" in tags:
|
||||||
|
values = tags["voltage"].split(";")
|
||||||
|
texts.append(", ".join(map(format_voltage, values)))
|
||||||
|
|
||||||
|
if "frequency" in tags:
|
||||||
|
texts.append(", ".join(map(
|
||||||
|
format_frequency, tags["frequency"].split(";"))))
|
||||||
|
|
||||||
|
return texts
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue