Graphviz connection graph script

This commit is contained in:
Lucidiot 2020-07-25 19:29:03 +02:00
parent 865e3a0e6c
commit 451f9304fb
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
3 changed files with 50 additions and 0 deletions

13
connection_graph.sh Executable file
View File

@ -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 <<EOF
graph connections {
node [style=filled, fontsize=20, fontname="sans-serif"]
EOF
jq -rf jq/graphnodes.jq routes.json >> /tmp/connections
jq -rf jq/graphedges.jq lines.json >> /tmp/connections
echo '}' >> /tmp/connections
circo -Tpng /tmp/connections > connections.png

26
jq/graphedges.jq Normal file
View File

@ -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(" -- ")

11
jq/graphnodes.jq Normal file
View File

@ -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)\"]"