ratp: Handle more disruptions cases
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2024-06-07 09:53:26 +02:00
parent 452a6097e3
commit b985ea7a92

View File

@ -194,8 +194,16 @@ class IDFMAPI:
def get_line_weather(self, res, disruptions, mode, line):
for l in res["lines"]:
if l["id"] == "line:IDFM:" + IDFMAPI.lines[mode][line]:
disruptionIds = []
disruptionTypes = {}
for impactedObject in l["impactedObjects"]:
for disruptionId in impactedObject["disruptionIds"]:
if disruptionId not in disruptionIds:
disruptionTypes[disruptionId] = impactedObject["type"]
disruptionIds.append(disruptionId)
for disruptionId in disruptionIds:
impactType = disruptionTypes[disruptionId]
status = "past"
for ap in disruptions[disruptionId]["applicationPeriods"]:
end = datetime.strptime(ap["end"], "%Y%m%dT%H%M%S")
@ -209,7 +217,12 @@ class IDFMAPI:
status = "active"
break
if "cause" in disruptions and disruptions["cause"] == "INFORMATION":
continue
disruptions[disruptionId]["status"] = status
disruptions[disruptionId]["scope"] = impactType
yield disruptions[disruptionId]
return None
@ -217,12 +230,17 @@ class IDFMAPI:
def get_line_icon(config, mode, line, size, fill="gray", state=""):
if mode == "M" or mode == "metros":
icon_mode = "metro"
mode = "metros"
line = line.replace("B", "bis")
elif mode == "T" or mode == "tramways":
icon_mode = "tram"
mode = "tramways"
line = line.replace("T", "").lower()
elif mode == "R" or mode == "rers":
icon_mode = "RER"
mode = "rers"
elif mode == "B":
mode = "buses"
img_line = None
if mode == "rers" and fill != "white":
@ -415,15 +433,20 @@ class RATPWeatherModule:
state = ""
fill = "darkgray"
if "NO_SERVICE" in states:
if disruption["scope"] == "line" and ("NO_SERVICE" in states or "BLOQUANTE" in states):
fill = "black"
state = "_trafic_grand"
elif "REDUCED_SERVICE" in states or "UNKNOWN_EFFECT" in states or "OTHER_EFFECT" in states:
elif "PERTURBEE" in states:
fill = "brown"
state = "_trafic_moyen"
elif "REDUCED_SERVICE" in states or "UNKNOWN_EFFECT" in states or "OTHER_EFFECT" in states or "NO_SERVICE" in states or "BLOQUANTE" in states:
fill = "teal"
state = "_trafic_moyen"
elif "BLOQUANTE TRAVAUX" in states:
fill = "teal"
state = "_travaux_moyen"
elif "INFORMATION" in states:
state = "_travaux_petit"
elif len(states) > 0:
fill = "gray"
state = "_trafic_petit"
@ -518,6 +541,8 @@ class RATPNextStopModule:
})
align -= int(line_height * 0.33)
if align < 0:
align = 0
image = image.crop((0,0,width, min(align, height)))
return image, alerts