From 783f29ce687912331979d074329cf733836b98dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Thu, 16 Jan 2020 19:10:30 +0100 Subject: [PATCH] Prevent lines duplicate in network data --- back/data/network.js | 8 ++-- back/data/network.json | 86 ---------------------------------------- script/update-network.js | 15 ++++++- 3 files changed, 18 insertions(+), 91 deletions(-) diff --git a/back/data/network.js b/back/data/network.js index 783d1f4..df09be7 100644 --- a/back/data/network.js +++ b/back/data/network.js @@ -261,12 +261,12 @@ ${joinSentence(Array.from(candidate.directions), ', ', ' or ')} lat: stop.lat, lon: stop.lon, name: stop.tags.name, - lines: [lineRef], + lines: new Set([lineRef]), }; } else { - stops[stop.tags.ref].lines.push(lineRef); + stops[stop.tags.ref].lines.add(lineRef); } } } @@ -376,7 +376,7 @@ ${joinSentence(Array.from(candidate.directions), ', ', ' or ')} const {lat, lon} = elements[id]; return {latitude: lat, longitude: lon}; })), - lines: [lineRef], + lines: new Set([lineRef]), }; found = true; @@ -409,7 +409,7 @@ ${joinSentence(Array.from(candidate.directions), ', ', ' or ')} } else { - segments[segmentId].lines.push(lineRef); + segments[segmentId].lines.add(lineRef); } ++currentStopIndex; diff --git a/back/data/network.json b/back/data/network.json index 8ef0a02..0d4fca2 100644 --- a/back/data/network.json +++ b/back/data/network.json @@ -195,7 +195,6 @@ "lon": 3.8955449, "name": "Moularès (Hôtel de Ville)", "lines": [ - "3", "3", "1" ] @@ -205,7 +204,6 @@ "lon": 3.8999684, "name": "Port Marianne", "lines": [ - "3", "3", "1" ] @@ -279,7 +277,6 @@ "lon": 3.899234, "name": "Port Marianne", "lines": [ - "3", "3", "1" ] @@ -289,7 +286,6 @@ "lon": 3.8955356, "name": "Moularès (Hôtel de Ville)", "lines": [ - "3", "3", "1" ] @@ -521,7 +517,6 @@ "lon": 3.8444363, "name": "La Condamine", "lines": [ - "2", "2" ] }, @@ -604,7 +599,6 @@ "lon": 3.8842954, "name": "Place Carnot", "lines": [ - "3", "3" ] }, @@ -613,7 +607,6 @@ "lon": 3.8892253, "name": "Voltaire", "lines": [ - "3", "3" ] }, @@ -622,7 +615,6 @@ "lon": 3.8940022, "name": "Rives du Lez", "lines": [ - "3", "3" ] }, @@ -887,7 +879,6 @@ "lon": 3.8938614, "name": "Rives du Lez", "lines": [ - "3", "3" ] }, @@ -896,7 +887,6 @@ "lon": 3.8889694, "name": "Voltaire", "lines": [ - "3", "3" ] }, @@ -905,7 +895,6 @@ "lon": 3.8842324, "name": "Place Carnot", "lines": [ - "3", "3" ] }, @@ -1004,7 +993,6 @@ "lon": 3.8099711, "name": "Juvignac", "lines": [ - "3", "3" ] }, @@ -1013,7 +1001,6 @@ "lon": 3.8196447, "name": "Mosson", "lines": [ - "3", "3" ] }, @@ -1022,7 +1009,6 @@ "lon": 3.8259015, "name": "Celleneuve", "lines": [ - "3", "3" ] }, @@ -1031,7 +1017,6 @@ "lon": 3.8321502, "name": "Pilory", "lines": [ - "3", "3" ] }, @@ -1040,7 +1025,6 @@ "lon": 3.8351279, "name": "Hôtel du Département", "lines": [ - "3", "3" ] }, @@ -1049,7 +1033,6 @@ "lon": 3.8397593, "name": "Pergola", "lines": [ - "3", "3" ] }, @@ -1058,7 +1041,6 @@ "lon": 3.8397933, "name": "Tonnelles", "lines": [ - "3", "3" ] }, @@ -1067,7 +1049,6 @@ "lon": 3.8467949, "name": "Jules Guesde", "lines": [ - "3", "3" ] }, @@ -1076,7 +1057,6 @@ "lon": 3.855048, "name": "Astruc", "lines": [ - "3", "3" ] }, @@ -1085,7 +1065,6 @@ "lon": 3.8624768, "name": "Arceaux", "lines": [ - "3", "3" ] }, @@ -1094,7 +1073,6 @@ "lon": 3.8681087, "name": "Plan Cabanes", "lines": [ - "3", "3" ] }, @@ -1103,7 +1081,6 @@ "lon": 3.8739545, "name": "Saint-Denis", "lines": [ - "3", "3" ] }, @@ -1113,7 +1090,6 @@ "name": "Observatoire", "lines": [ "4", - "3", "3" ] }, @@ -1123,7 +1099,6 @@ "name": "Gare Saint-Roch", "lines": [ "4", - "3", "3" ] }, @@ -1164,7 +1139,6 @@ "lon": 3.9034583, "name": "Pablo Picasso", "lines": [ - "3", "3" ] }, @@ -1173,7 +1147,6 @@ "lon": 3.9257823, "name": "Boirargues", "lines": [ - "3", "3" ] }, @@ -1254,7 +1227,6 @@ "lon": 3.9256144, "name": "Boirargues", "lines": [ - "3", "3" ] }, @@ -1263,7 +1235,6 @@ "lon": 3.9036298, "name": "Pablo Picasso", "lines": [ - "3", "3" ] }, @@ -1305,7 +1276,6 @@ "name": "Gare Saint-Roch", "lines": [ "4", - "3", "3" ] }, @@ -1315,7 +1285,6 @@ "name": "Observatoire", "lines": [ "4", - "3", "3" ] }, @@ -1324,7 +1293,6 @@ "lon": 3.8727299, "name": "Saint-Denis", "lines": [ - "3", "3" ] }, @@ -1333,7 +1301,6 @@ "lon": 3.8681304, "name": "Plan Cabanes", "lines": [ - "3", "3" ] }, @@ -1342,7 +1309,6 @@ "lon": 3.8615025, "name": "Arceaux", "lines": [ - "3", "3" ] }, @@ -1351,7 +1317,6 @@ "lon": 3.8548, "name": "Astruc", "lines": [ - "3", "3" ] }, @@ -1360,7 +1325,6 @@ "lon": 3.8466375, "name": "Jules Guesde", "lines": [ - "3", "3" ] }, @@ -1369,7 +1333,6 @@ "lon": 3.8395235, "name": "Tonnelles", "lines": [ - "3", "3" ] }, @@ -1378,7 +1341,6 @@ "lon": 3.8391413, "name": "Pergola", "lines": [ - "3", "3" ] }, @@ -1387,7 +1349,6 @@ "lon": 3.8349511, "name": "Hôtel du Département", "lines": [ - "3", "3" ] }, @@ -1396,7 +1357,6 @@ "lon": 3.8319619, "name": "Pilory", "lines": [ - "3", "3" ] }, @@ -1405,7 +1365,6 @@ "lon": 3.8258568, "name": "Celleneuve", "lines": [ - "3", "3" ] }, @@ -1414,7 +1373,6 @@ "lon": 3.8196588, "name": "Mosson", "lines": [ - "3", "3" ] }, @@ -1423,7 +1381,6 @@ "lon": 3.810219, "name": "Juvignac", "lines": [ - "3", "3" ] }, @@ -1440,7 +1397,6 @@ "lon": 3.9139627, "name": "Cougourlude", "lines": [ - "3", "3" ] }, @@ -1473,7 +1429,6 @@ "lon": 3.8909614, "name": "Garcia Lorca", "lines": [ - "4", "4" ] }, @@ -1482,7 +1437,6 @@ "lon": 3.8911652, "name": "Garcia Lorca", "lines": [ - "4", "4" ] }, @@ -2207,7 +2161,6 @@ "length": 277, "lines": [ "4", - "3", "3" ] }, @@ -8589,7 +8542,6 @@ "length": 272, "lines": [ "4", - "3", "3" ] }, @@ -16705,7 +16657,6 @@ ], "length": 2514, "lines": [ - "3", "3" ] }, @@ -16798,7 +16749,6 @@ ], "length": 668, "lines": [ - "3", "3" ] }, @@ -16887,7 +16837,6 @@ ], "length": 352, "lines": [ - "3", "3", "1" ] @@ -17049,7 +16998,6 @@ ], "length": 478, "lines": [ - "3", "3" ] }, @@ -17146,7 +17094,6 @@ ], "length": 399, "lines": [ - "3", "3" ] }, @@ -17227,7 +17174,6 @@ ], "length": 405, "lines": [ - "3", "3" ] }, @@ -17404,7 +17350,6 @@ ], "length": 508, "lines": [ - "3", "3" ] }, @@ -17521,7 +17466,6 @@ ], "length": 460, "lines": [ - "3", "3" ] }, @@ -17582,7 +17526,6 @@ ], "length": 451, "lines": [ - "3", "3" ] }, @@ -17655,7 +17598,6 @@ ], "length": 563, "lines": [ - "3", "3" ] }, @@ -17748,7 +17690,6 @@ ], "length": 548, "lines": [ - "3", "3" ] }, @@ -17869,7 +17810,6 @@ ], "length": 683, "lines": [ - "3", "3" ] }, @@ -17978,7 +17918,6 @@ ], "length": 636, "lines": [ - "3", "3" ] }, @@ -18163,7 +18102,6 @@ ], "length": 637, "lines": [ - "3", "3" ] }, @@ -18280,7 +18218,6 @@ ], "length": 610, "lines": [ - "3", "3" ] }, @@ -18345,7 +18282,6 @@ ], "length": 358, "lines": [ - "3", "3" ] }, @@ -18454,7 +18390,6 @@ ], "length": 732, "lines": [ - "3", "3" ] }, @@ -18603,7 +18538,6 @@ ], "length": 608, "lines": [ - "3", "3" ] }, @@ -18920,7 +18854,6 @@ ], "length": 1200, "lines": [ - "3", "3" ] }, @@ -19565,7 +19498,6 @@ ], "length": 1230, "lines": [ - "3", "3" ] }, @@ -19710,7 +19642,6 @@ ], "length": 618, "lines": [ - "3", "3" ] }, @@ -19807,7 +19738,6 @@ ], "length": 728, "lines": [ - "3", "3" ] }, @@ -19868,7 +19798,6 @@ ], "length": 362, "lines": [ - "3", "3" ] }, @@ -19997,7 +19926,6 @@ ], "length": 692, "lines": [ - "3", "3" ] }, @@ -20158,7 +20086,6 @@ ], "length": 559, "lines": [ - "3", "3" ] }, @@ -20267,7 +20194,6 @@ ], "length": 629, "lines": [ - "3", "3" ] }, @@ -20384,7 +20310,6 @@ ], "length": 695, "lines": [ - "3", "3" ] }, @@ -20481,7 +20406,6 @@ ], "length": 608, "lines": [ - "3", "3" ] }, @@ -20550,7 +20474,6 @@ ], "length": 482, "lines": [ - "3", "3" ] }, @@ -20639,7 +20562,6 @@ ], "length": 573, "lines": [ - "3", "3" ] }, @@ -20772,7 +20694,6 @@ ], "length": 325, "lines": [ - "3", "3" ] }, @@ -20949,7 +20870,6 @@ ], "length": 516, "lines": [ - "3", "3" ] }, @@ -21046,7 +20966,6 @@ ], "length": 416, "lines": [ - "3", "3" ] }, @@ -21163,7 +21082,6 @@ ], "length": 390, "lines": [ - "3", "3" ] }, @@ -21356,7 +21274,6 @@ ], "length": 476, "lines": [ - "3", "3" ] }, @@ -21453,7 +21370,6 @@ ], "length": 420, "lines": [ - "3", "3", "1" ] @@ -21535,7 +21451,6 @@ ], "length": 578, "lines": [ - "3", "3" ] }, @@ -21692,7 +21607,6 @@ ], "length": 2533, "lines": [ - "3", "3" ] }, diff --git a/script/update-network.js b/script/update-network.js index 730ac84..9dd7837 100755 --- a/script/update-network.js +++ b/script/update-network.js @@ -11,6 +11,19 @@ const fs = require('fs'); fs.writeFileSync( path.join(__dirname, '../back/data/network.json'), - JSON.stringify(data) + JSON.stringify( + data, + (_, value) => + { + if (value instanceof Set) + { + // Convert sets to arrays for JSON representation + return Array.from(value.values()); + } + + return value; + }, + ' ' + ) ); })();