From b6ba770a8aba6f40d4ba51992f92f2d4355eda59 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sat, 19 Oct 2024 15:00:08 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BB=8A=E3=82=A2=E3=82=A4=E3=82=B3?= =?UTF-8?q?=E3=83=B3=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EachTrainInfo/EachStopList.js | 2 +- .../EachTrainInfoCore.js | 12 +- .../findReversalPoints.js | 116 ++++-------------- 3 files changed, 32 insertions(+), 98 deletions(-) diff --git a/components/ActionSheetComponents/EachTrainInfo/EachStopList.js b/components/ActionSheetComponents/EachTrainInfo/EachStopList.js index 5ffecb7..f5d3fb6 100644 --- a/components/ActionSheetComponents/EachTrainInfo/EachStopList.js +++ b/components/ActionSheetComponents/EachTrainInfo/EachStopList.js @@ -107,7 +107,7 @@ export const EachStopList = ({ {station} - {points && points.findIndex((d) => d == index) >= 0 ? ( + {points ? ( ๐ŸšŠ ) : null} {!isNaN(currentTrainData?.delay) && currentTrainData?.delay != 0 && ( diff --git a/components/ActionSheetComponents/EachTrainInfoCore.js b/components/ActionSheetComponents/EachTrainInfoCore.js index 0ef42bb..5c283d9 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore.js +++ b/components/ActionSheetComponents/EachTrainInfoCore.js @@ -95,7 +95,7 @@ export const EachTrainInfoCore = ({ ); // ไฝฟ็”จไพ‹ - const stopStationIDList = trainData.map((i) => { + const stopStationIDList = trainDataWidhThrough.map((i) => { const [station, se, time] = i.split(","); const Stations = stationList.map((a) => a.filter((d) => d.StationName == station) @@ -104,9 +104,7 @@ export const EachTrainInfoCore = ({ Stations && Stations.reduce((newArray, e) => { return newArray.concat(e); - }, []) - .filter((d) => d.StationNumber) - .map((d) => d.StationNumber); + }, []).map((d) => d.StationNumber); return StationNumbers; }); useEffect(() => { @@ -142,7 +140,6 @@ export const EachTrainInfoCore = ({ d.StationNumber > baseStationNumberFirst && d.StationNumber < baseStationNumberSecond ) { - console.log(d.Station_JP); allThroughStation.push(`${d.Station_JP},้€š้Ž,`); setHaveThrough(true); reverse = false; @@ -151,7 +148,6 @@ export const EachTrainInfoCore = ({ d.StationNumber < baseStationNumberFirst && d.StationNumber > baseStationNumberSecond ) { - console.log(d.Station_JP); allThroughStation.push(`${d.Station_JP},้€š้Ž,`); setHaveThrough(true); reverse = true; @@ -176,7 +172,7 @@ export const EachTrainInfoCore = ({ const points = trainPositionSwitch == "true" ? findReversalPoints(currentPosition, stopStationIDList) - : []; + : stopStationIDList.map(() => false); const trainName = useMemo(() => { if (!data.limited) return ""; const limitedArray = data.limited.split(":"); @@ -439,7 +435,7 @@ export const EachTrainInfoCore = ({ i, index, stationList, - points, + points: points ? points[index] : false, currentTrainData, openStationACFromEachTrainInfo, showThrew, diff --git a/lib/eachTrainInfoCoreLib/findReversalPoints.js b/lib/eachTrainInfoCoreLib/findReversalPoints.js index a7cd70e..353a75c 100644 --- a/lib/eachTrainInfoCoreLib/findReversalPoints.js +++ b/lib/eachTrainInfoCoreLib/findReversalPoints.js @@ -7,105 +7,43 @@ export const findReversalPoints = (array, stopStationIDList) => { if (!array instanceof Array) return []; if (!array) return []; if (array[0] instanceof Array) return []; - const arrayNumber = array.map((d) => ({ - line: d - .split("") - .filter((s) => "A" < s && s < "Z") - .join(""), - ID: d - .split("") - .filter((s) => "0" <= s && s <= "9") - .join(""), - })); - const stopStationIDListNumber = stopStationIDList.map((d) => { - if (!d) return { line: [], ID: [] }; - return { - line: d[0] - .split("") - .filter((s) => "A" < s && s < "Z") - .join(""), - ID: d[0] - .split("") - .filter((s) => "0" <= s && s <= "9") - .join(""), - }; - }); + // ๅฎŒๅ…จไธ€่‡ด if (array.length == 1) { - const index = stopStationIDList.indexOf(array[0]); - if (index != -1) return [index]; - // ้€š้Ž้ง…ใฎๅ ดๅˆ - for (let i = 0; i < stopStationIDListNumber.length - 1; i++) { - if (stopStationIDListNumber[i].ID < arrayNumber[0].ID) { - if (stopStationIDListNumber[i + 1].ID > arrayNumber[0].ID) { - return [i + 1]; - } - } - if (stopStationIDListNumber[i].ID > arrayNumber[0].ID) { - if (stopStationIDListNumber[i + 1].ID < arrayNumber[0].ID) { - return [i + 1]; - } - } + const index = stopStationIDList.map((d) => { + let a = false; + d.forEach((x) => { + if (x == array[0]) a = true; + }); + return a; + }); + if (index != -1) { + return index; } } // ้ง…้–“ใฎๅ ดๅˆ if (array.length == 2) { - const index1 = stopStationIDList.indexOf(array[0]); - const index2 = stopStationIDList.indexOf(array[1]); - if (index1 != -1 && index2 != -1) { - // ้ง…้–“ใง้€š้Ž้ง…ใ‚‚็„กใ„ๅ ดๅˆ - if (index1 < index2) { - if (index1 + 1 == index2) { - return [index2]; - } else { - const returnArray = []; - for (let i = index1 + 1; i <= index2; i++) { - returnArray.push(i); - } - return returnArray; + + const allThroughStation = stopStationIDList.map((d) => { + if(array[0] == "M12" && array[1] == "Y09" || array[0] == "Y09" && array[1] == "M12"){ + if(d[0] == "M12"){ + return true; } + else return false; } - if (index1 > index2) { - if (index2 + 1 == index1) return [index1]; - else { - const returnArray = []; - for (let i = index2 + 1; i <= index1; i++) { - returnArray.push(i); - } - return returnArray; - } - } - } else { - const getNearStationID = (stationID) => { - for (let i = 0; i <= stopStationIDListNumber.length; i++) { - if (stopStationIDListNumber[i].ID < stationID) { - if (stopStationIDListNumber[i + 1].ID > stationID) { - return i + 1; - } - } - if (stopStationIDListNumber[i].ID > stationID) { - if (stopStationIDListNumber[i + 1].ID < stationID) { - return i + 1; - } - } - } - }; - let newIndex1 = index1; - let newIndex2 = index2; - if (index1 == -1) { - newIndex1 = getNearStationID(arrayNumber[0].ID); - } - if (index2 == -1) { - newIndex2 = getNearStationID(arrayNumber[1].ID); - } - if (newIndex1 && newIndex2) { - return [newIndex1, newIndex2]; + if (d[0] < array[0] && d[0] > array[1]) { + return true; + } else if (d[0] < array[1] && d[0] > array[0]) { + return true; + }else if (d[0] < array[0] && d[0] == array[1]) { + return true; + } else if (d[0] == array[1] && d[0] > array[0]) { + return true; } - // ้€š้Ž้ง…ใฎๅ ดๅˆ - } - - return []; + return false; + }); + return allThroughStation; } } catch (e) { console.log(e);