Skip to content
Snippets Groups Projects
Verified Commit b6759d92 authored by Marco Aceti's avatar Marco Aceti
Browse files

Add marker in trajectories map

parent 67d136ad
No related branches found
No related tags found
No related merge requests found
Pipeline #2809 passed
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1"
id="svg4619" inkscape:version="0.91+devel+osxmenu r12911" sodipodi:docname="triangle-15.svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="15px" height="15px"
viewBox="0 0 15 15" style="enable-background:new 0 0 15 15;" xml:space="preserve">
<path id="path21090-9" inkscape:connector-curvature="0" sodipodi:nodetypes="sscsssscss" d="M7.5385,2
C7.2437,2,7.0502,2.1772,6.9231,2.3846l-5.8462,9.5385C1,12,1,12.1538,1,12.3077C1,12.8462,1.3846,13,1.6923,13h11.6154
C13.6923,13,14,12.8462,14,12.3077c0-0.1538,0-0.2308-0.0769-0.3846L8.1538,2.3846C8.028,2.1765,7.7882,2,7.5385,2z"/>
</svg>
import itertools
import logging
import pathlib
import typing as t
import webbrowser
from collections import defaultdict
......@@ -47,6 +48,9 @@ for k in _color_map:
COLOR_MAP[k] = _color_map[k]
ASSETS_PATH = pathlib.Path("./src/analysis/assets/").resolve()
def fill_time(start: datetime, end: datetime) -> t.Generator[datetime, None, None]:
"""Generate a consecutive list of times between the 'start' and 'end' period.
......@@ -101,13 +105,8 @@ def train_stop_geojson(st: pd.DataFrame, train: pd.DataFrame) -> list[dict]:
# The station location can't be retrieved
continue
prev_time: datetime | None = prev.departure_expected
if prev.departure_actual:
prev_time = prev.departure_actual
curr_time: datetime | None = curr.arrival_expected
if curr.arrival_actual:
curr_time = curr.arrival_actual
prev_time: datetime | None = prev.departure_actual or prev.departure_expected
curr_time: datetime | None = curr.arrival_actual or curr.arrival_expected
# Sanity check: _time must be not null
if not prev_time or not curr_time:
......@@ -123,7 +122,8 @@ def train_stop_geojson(st: pd.DataFrame, train: pd.DataFrame) -> list[dict]:
continue
for timestamp in fill_time(prev_time, curr_time):
ret.append(
ret.extend(
[
{
"type": "Feature",
"geometry": {
......@@ -143,7 +143,40 @@ def train_stop_geojson(st: pd.DataFrame, train: pd.DataFrame) -> list[dict]:
else MIN_WEIGHT,
},
},
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": (curr_st.longitude, curr_st.latitude),
},
"properties": {
"icon": "marker",
"iconstyle": {
"iconUrl": str(ASSETS_PATH / "train-marker.svg"),
"iconSize": [24, 24],
"fillOpacity": 1,
},
"tooltip": (
f"<b>{curr.client_code}</b> &#8729; <b>{curr.category}</b> <b>{curr.number}</b>"
f"<dd>{prev_st.long_name} "
f"{f'({round(prev.departure_delay, 1):+g} min)' if not np.isnan(prev.departure_delay) else ''}"
f" &rarr; "
f"{curr_st.long_name} "
f"{f' ({round(prev.arrival_delay, 1):+g} min)' if not np.isnan(prev.arrival_delay) else ''}"
),
"name": "",
"times": [timestamp.isoformat()],
"style": {
"color": COLOR_MAP[curr.client_code],
"weight": int(curr.crowding / 10)
if not np.isnan(curr.crowding)
and curr.crowding > MIN_WEIGHT * 10
else MIN_WEIGHT,
},
},
},
]
)
return ret
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment