diff --git a/assets/originData/tokushima.ts b/assets/originData/tokushima.ts index c90b303..b94015d 100644 --- a/assets/originData/tokushima.ts +++ b/assets/originData/tokushima.ts @@ -1,5 +1,5 @@ export default [ -{"Station_JP" : "徳島", "Station_EN" : "Tokushima", "MyStation" : "0", "StationNumber" : "T00", "DispNum" : "3", "StationTimeTable" : "http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/tokushima.pdf", "StationMap":"https://www.google.co.jp/maps/place/34.074642,134.550764", "JrHpUrl" : "http://www.jr-shikoku.co.jp/01_trainbus/kakueki/tokushima/"}, +{"Station_JP" : "徳島", "Station_EN" : "Tokushima", "MyStation" : "0", "StationNumber" : "B00", "DispNum" : "3", "StationTimeTable" : "http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/tokushima.pdf", "StationMap":"https://www.google.co.jp/maps/place/34.074642,134.550764", "JrHpUrl" : "http://www.jr-shikoku.co.jp/01_trainbus/kakueki/tokushima/"}, {"Station_JP" : "佐古", "Station_EN" : "Sako", "MyStation" : "0", "StationNumber" : "B01", "DispNum" : "2", "StationTimeTable" : "http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/sako.pdf", "StationMap":"https://www.google.co.jp/maps/place/34.080616,134.538576", "JrHpUrl" : ""}, {"Station_JP" : "蔵本", "Station_EN" : "Kuramoto", "MyStation" : "1", "StationNumber" : "B02", "DispNum" : "2", "StationTimeTable" : "http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/kuramoto.pdf", "StationMap":"https://www.google.co.jp/maps/place/34.079332,134.518705", "JrHpUrl" : ""}, {"Station_JP" : "府中", "Station_EN" : "Kō", "MyStation" : "2", "StationNumber" : "B04", "DispNum" : "2", "StationTimeTable" : "http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/ko.pdf", "StationMap":"https://www.google.co.jp/maps/place/34.074134,134.482939", "JrHpUrl" : ""}, diff --git a/components/ActionSheetComponents/EachTrainInfo/EachStopList.js b/components/ActionSheetComponents/EachTrainInfo/EachStopList.js index a2813b3..f5d3fb6 100644 --- a/components/ActionSheetComponents/EachTrainInfo/EachStopList.js +++ b/components/ActionSheetComponents/EachTrainInfo/EachStopList.js @@ -10,7 +10,9 @@ export const EachStopList = ({ points, currentTrainData, openStationACFromEachTrainInfo, + showThrew, }) => { + if (!showThrew && i.split(",")[1] == "通過") return null; const [station, se, time] = i.split(","); // 阿波池田,発,6:21 const Stations = stationList .map((a) => a.filter((d) => d.StationName == station)) @@ -43,7 +45,7 @@ export const EachStopList = ({ .set("hour", parseInt(time.split(":")[0])) .set("minute", parseInt(time.split(":")[1])) .add(isNaN(currentTrainData?.delay) ? 0 : currentTrainData.delay, "minute"); - const timeString = dates.format("HH:mm").split(":"); + const timeString = se == "通過" ? "" : dates.format("HH:mm").split(":"); return ( ( - {station} + + {station} + - {points && points.findIndex((d) => d == index) >= 0 ? ( + {points ? ( 🚊 ) : null} {!isNaN(currentTrainData?.delay) && currentTrainData?.delay != 0 && ( @@ -128,7 +136,7 @@ export const EachStopList = ({ width: 60, }} > - {timeString[0]}:{timeString[1]} + {se == "通過" ? "レ" : `${timeString[0]}:${timeString[1]}`} {se?.replace("発", "出発").replace("着", "到着")} diff --git a/components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.js b/components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.js index 3881b36..545428d 100644 --- a/components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.js +++ b/components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.js @@ -1,7 +1,8 @@ import React from "react"; -import { View, Text } from "react-native"; +import { View, Text, LayoutAnimation, TouchableOpacity } from "react-native"; -export const ScrollStickyContent = ({ currentTrainData }) => { +export const ScrollStickyContent = (props) => { + const { currentTrainData, showThrew, setShowThrew, haveThrough } = props; return ( { > 見込 - + { + if (!haveThrough) return; + LayoutAnimation.configureNext({ + duration: 200, + update: { type: "easeInEaseOut", springDamping: 0.6 }, + }); + setShowThrew(!showThrew); + }} + > + + + (通過{showThrew ? "▼" : "▶"}) + + + diff --git a/components/ActionSheetComponents/EachTrainInfoCore.js b/components/ActionSheetComponents/EachTrainInfoCore.js index c145c36..e73893e 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore.js +++ b/components/ActionSheetComponents/EachTrainInfoCore.js @@ -11,7 +11,7 @@ import { import { SheetManager } from "react-native-actions-sheet"; import { AS } from "../../storageControl"; import trainList from "../../assets/originData/trainList"; -import { lineList } from "../../lib/getStationList"; +import { lineList, lineListPair } from "../../lib/getStationList"; import { useCurrentTrain } from "../../stateBox/useCurrentTrain"; import { checkDuplicateTrainData } from "../../lib/checkDuplicateTrainData"; import { getTrainType } from "../../lib/getTrainType"; @@ -34,6 +34,7 @@ import { ShowSpecialTrain } from "./EachTrainInfo/ShowSpecialTrain"; import { useTrainMenu } from "../../stateBox/useTrainMenu"; import { HeaderText } from "./EachTrainInfoCore/HeaderText"; import { useStationList } from "../../stateBox/useStationList"; +import { stationIDPair } from "../../lib/getStationList2"; export const EachTrainInfoCore = ({ actionSheetRef, @@ -80,6 +81,9 @@ export const EachTrainInfoCore = ({ const [trainPositionSwitch, setTrainPositionSwitch] = useState("false"); const [currentPosition, setCurrentPosition] = useState([]); const [trainData, setTrainData] = useState([]); + const [trainDataWidhThrough, setTrainDataWithThrough] = useState([]); + const [showThrew, setShowThrew] = useState(false); + const [haveThrough, setHaveThrough] = useState(false); const stationList = originalStationList && @@ -91,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) @@ -100,15 +104,75 @@ export const EachTrainInfoCore = ({ Stations && Stations.reduce((newArray, e) => { return newArray.concat(e); - }, []) - .filter((d) => d.StationNumber) - .map((d) => d.StationNumber); - return StationNumbers[0]; + }, []).map((d) => d.StationNumber); + return StationNumbers; }); + useEffect(() => { + const stopStationList = trainData.map((i) => { + const [station, se, time] = i.split(","); + return stationList.map((a) => a.filter((d) => d.StationName == station)); + }); + const allThroughStationList = stopStationList.map((i, index, array) => { + let allThroughStation = []; + if (index == array.length - 1) return; + + const firstItem = array[index]; + const secondItem = array[index + 1]; + let betweenStationLine = ""; + let baseStationNumberFirst = ""; + let baseStationNumberSecond = ""; + Object.keys(stationIDPair).forEach((d, index2, array) => { + if (!d) return; + const haveFirst = firstItem[index2]; + const haveSecond = secondItem[index2]; + if (haveFirst.length && haveSecond.length) { + betweenStationLine = d; + baseStationNumberFirst = haveFirst[0].StationNumber; + baseStationNumberSecond = haveSecond[0].StationNumber; + } + }); + if (!betweenStationLine) return; + let reverse = false; + originalStationList[ + lineListPair[stationIDPair[betweenStationLine]] + ].forEach((d) => { + if ( + d.StationNumber > baseStationNumberFirst && + d.StationNumber < baseStationNumberSecond + ) { + allThroughStation.push(`${d.Station_JP},通過,`); + setHaveThrough(true); + reverse = false; + } else { + if ( + d.StationNumber < baseStationNumberFirst && + d.StationNumber > baseStationNumberSecond + ) { + allThroughStation.push(`${d.Station_JP},通過,`); + setHaveThrough(true); + reverse = true; + } + } + }); + if (reverse) allThroughStation.reverse(); + return allThroughStation; + }); + let mainArray = [...trainData]; + let indexs = 0; + trainData.forEach((d, index, array) => { + indexs = indexs + 1; + if (!allThroughStationList[index]) return; + if (allThroughStationList[index].length == 0) return; + mainArray.splice(indexs, 0, ...allThroughStationList[index]); + indexs = indexs + allThroughStationList[index].length; + }); + setTrainDataWithThrough(mainArray); + }, [trainData]); + const points = trainPositionSwitch == "true" ? findReversalPoints(currentPosition, stopStationIDList) - : []; + : stopStationIDList.map(() => false); const trainName = useMemo(() => { if (!data.limited) return ""; const limitedArray = data.limited.split(":"); @@ -193,9 +257,41 @@ export const EachTrainInfoCore = ({ if (currentTrainData?.Pos.match("~")) { const pos = currentTrainData?.Pos.replace("(下り)", "") .replace("(上り)", "") + .replace("(徳島線)", "") + .replace("(高徳線)", "") .split("~"); const direction = parseInt(currentTrainData?.Direction) || 0; - if (direction == 0) { + if (pos[0] == "児島" && pos[1] == "宇多津") { + setCurrentPosition(["M12", "Y09"]); + return; + } else if (pos[1] == "児島" && pos[0] == "宇多津") { + setCurrentPosition(["Y09", "M12"]); + return; + } + const currentPosID = Object.keys(originalStationList).map((key) => { + let firstStation = false; + let firstStationID = ""; + let secondStation = false; + let secondStationID = ""; + originalStationList[key].forEach((station) => { + if (station.Station_JP === pos[0]) { + firstStation = true; + firstStationID = station.StationNumber; + } + if (station.Station_JP === pos[1]) { + secondStation = true; + secondStationID = station.StationNumber; + } + }); + if (firstStation && secondStation) { + return [firstStationID, secondStationID]; + } else return false; + }); + const currentPos = currentPosID.filter((d) => d != false)[0]; + if (currentPos) { + if (direction == 0) setCurrentPosition(currentPos.reverse()); + else setCurrentPosition(currentPos); + } else if (direction == 0) { setCurrentPosition([ getStationID(pos[1], stationList), getStationID(pos[0], stationList), @@ -301,7 +397,9 @@ export const EachTrainInfoCore = ({ shortHeader={} longHeader={} topStickyContent={ - + } > {headStation.length != 0 && @@ -360,17 +458,20 @@ export const EachTrainInfoCore = ({ )} - {trainData.map((i, index) => + {trainDataWidhThrough.map((i, index) => i.split(",")[1] == "提" ? ( ) : ( ) )} diff --git a/components/発車時刻表/EachData.tsx b/components/発車時刻表/EachData.tsx index 6feb5e5..22dd788 100644 --- a/components/発車時刻表/EachData.tsx +++ b/components/発車時刻表/EachData.tsx @@ -141,7 +141,7 @@ export const EachData: FC = (props) => { { diff --git a/lib/eachTrainInfoCoreLib/findReversalPoints.js b/lib/eachTrainInfoCoreLib/findReversalPoints.js index 05f6f55..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 - .split("") - .filter((s) => "A" < s && s < "Z") - .join(""), - ID: d - .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);