From 451f9304fb83b0f2964dd5091e75a0dea9a767ef Mon Sep 17 00:00:00 2001 From: Lucidiot Date: Sat, 25 Jul 2020 19:29:03 +0200 Subject: [PATCH] Graphviz connection graph script --- connection_graph.sh | 13 +++++++++++++ jq/graphedges.jq | 26 ++++++++++++++++++++++++++ jq/graphnodes.jq | 11 +++++++++++ 3 files changed, 50 insertions(+) create mode 100755 connection_graph.sh create mode 100644 jq/graphedges.jq create mode 100644 jq/graphnodes.jq diff --git a/connection_graph.sh b/connection_graph.sh new file mode 100755 index 0000000..3b73ff3 --- /dev/null +++ b/connection_graph.sh @@ -0,0 +1,13 @@ +[ -e lines.json ] || wget "https://data.metromobilite.fr/api/lines/json?types=ligne&reseaux=SEM" -O lines.json +[ -e routes.json ] || wget "https://data.metromobilite.fr/api/routers/default/index/routes" -O routes.json + +cat > /tmp/connections <> /tmp/connections +jq -rf jq/graphedges.jq lines.json >> /tmp/connections + +echo '}' >> /tmp/connections +circo -Tpng /tmp/connections > connections.png diff --git a/jq/graphedges.jq b/jq/graphedges.jq new file mode 100644 index 0000000..ea40aef --- /dev/null +++ b/jq/graphedges.jq @@ -0,0 +1,26 @@ +[ + # Build (line, stop) tuples from each line + [ + .features[].properties + | . as $prop + | .ZONES_ARRET[] + | { line: $prop.id, stop: . } + ] + # Group everything by stop and only retrieve lines + # This gives us all connected lines on a given stop + | group_by(.stop)[] + | [ + .[].line + # Ignore buses acting as tramways + | select(startswith("SEM_8") | not) + ] + # Ignore stops with only one bus line + | select(length > 1) + # Get all combinations, ignoring edges pointing to themselves + | combinations(2) + | select(.[0] != .[1]) +] +# Remove duplicate edges like A-B and B-A +| unique_by(sort)[] +# Output as DOT edges +| join(" -- ") diff --git a/jq/graphnodes.jq b/jq/graphnodes.jq new file mode 100644 index 0000000..e07682b --- /dev/null +++ b/jq/graphnodes.jq @@ -0,0 +1,11 @@ +.[] +| select( + # Ignore non-TAG lines + (.id|startswith("SEM")) + # Ignore special lines for buses acting as tramways + and [.mode, .type] != ["BUS", "TRAM"] +) +# Replace IDs with the underscored IDs from edges +| .id |= sub(":"; "_") +# Node descriptions with colors +| "\(.id) [label=\"\(.shortName)\", fillcolor=\"#\(.color)\", fontcolor=\"#\(.textColor)\"]"