Skip to content

Commit

Permalink
update main.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
csenet committed Apr 28, 2024
1 parent 225b288 commit 9952024
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 105 deletions.
211 changes: 109 additions & 102 deletions backend/auto-operation/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { BlockStateEnum } from "./proto/state/v1/block_pb.js";
import { StopStateEnum } from "./proto/state/v1/stop_pb.js";
import { PointStateEnum } from "./proto/state/v1/point_pb.js";
import { Priority } from "./proto/state/v1/train_pb.js";
// @ts-ignore
import config from './map/mfk-2024.json' assert {type: 'json'};

type MapConfig = {
stopBlocks: { [key: string]: string },
Expand All @@ -25,7 +27,8 @@ const transport = createConnectTransport(
const client = createPromiseClient(StateManagerService, transport);

async function loadConfig() {
mapConfig = (await import("./map/mfk-2024.json")).default;
// @ts-ignore
mapConfig = config;
}

loadConfig();
Expand Down Expand Up @@ -121,110 +124,114 @@ async function main() {
}
}

// for (const point of points) {
// console.log(point);
// }

// ポイント確認
for (const point of points) {
if (point.id === "sakurajosui_up_p1") {
// 桜上水上りポイント
// デフォルトではSTRAIGHTにして、sakurajosui_up_s1がONならREVERSEにする
const sakurajosui_up_s1 = stops.find(s => s.id === "sakurajosui_up_s1");
if (sakurajosui_up_s1 && sakurajosui_up_s1.state === StopStateEnum.STOP_STATE_STOP) {
if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
await client.updatePointState({
"state": {
"id": point.id,
"state": PointStateEnum.POINT_STATE_REVERSE
}
})
}
} else {
if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
await client.updatePointState({
"state": {
"id": point.id,
"state": PointStateEnum.POINT_STATE_NORMAL
}
})
}
}
}
if (point.id === "sakurajosui_down_p1") {
// const sakurajosui_down_s1 = stops.find(s => s.id === "sakurajosui_down_s1");
const sakurajosui_down_b1 = blocks.find(b => b.blockId === "sakurajosui_down_b1");
if (sakurajosui_down_b1 && sakurajosui_down_b1.state === BlockStateEnum.BLOCK_STATE_CLOSE) {
if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
await client.updatePointState({
"state": {
"id": point.id,
"state": PointStateEnum.POINT_STATE_REVERSE
}
})
}
} else {
if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
await client.updatePointState({
"state": {
"id": point.id,
"state": PointStateEnum.POINT_STATE_NORMAL
}
})
}
}
}
if (point.id === "chofu_up_p1") {
// 閉塞が空いてる方に切り替える b1 or b2
const chofu_up_b1 = blocks.find(b => b.blockId === "chofu_up_b1");
const chofu_up_b2 = blocks.find(b => b.blockId === "chofu_up_b2");
if (chofu_up_b1 && chofu_up_b2) {
if (chofu_up_b1.state === BlockStateEnum.BLOCK_STATE_OPEN) {
if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
await client.updatePointState({
"state": {
"id": point.id,
"state": PointStateEnum.POINT_STATE_NORMAL
}
})
}
} else if (chofu_up_b2.state === BlockStateEnum.BLOCK_STATE_OPEN) {
if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
await client.updatePointState({
"state": {
"id": point.id,
"state": PointStateEnum.POINT_STATE_REVERSE
}
})
}
}
}
}
// for (const point of points) {
// if (point.id === "sakurajosui_up_p1") {
// // 桜上水上りポイント
// // デフォルトではSTRAIGHTにして、sakurajosui_up_s1がONならREVERSEにする
// const sakurajosui_up_s1 = stops.find(s => s.id === "sakurajosui_up_s1");
// if (sakurajosui_up_s1 && sakurajosui_up_s1.state === StopStateEnum.STOP_STATE_STOP) {
// if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_REVERSE
// }
// })
// }
// } else {
// if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_NORMAL
// }
// })
// }
// }
// }
// if (point.id === "sakurajosui_down_p1") {
// // const sakurajosui_down_s1 = stops.find(s => s.id === "sakurajosui_down_s1");
// const sakurajosui_down_b1 = blocks.find(b => b.blockId === "sakurajosui_down_b1");
// if (sakurajosui_down_b1 && sakurajosui_down_b1.state === BlockStateEnum.BLOCK_STATE_CLOSE) {
// if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_REVERSE
// }
// })
// }
// } else {
// if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_NORMAL
// }
// })
// }
// }
// }
// if (point.id === "chofu_up_p1") {
// // 閉塞が空いてる方に切り替える b1 or b2
// const chofu_up_b1 = blocks.find(b => b.blockId === "chofu_up_b1");
// const chofu_up_b2 = blocks.find(b => b.blockId === "chofu_up_b2");
// if (chofu_up_b1 && chofu_up_b2) {
// if (chofu_up_b1.state === BlockStateEnum.BLOCK_STATE_OPEN) {
// if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_NORMAL
// }
// })
// }
// } else if (chofu_up_b2.state === BlockStateEnum.BLOCK_STATE_OPEN) {
// if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_REVERSE
// }
// })
// }
// }
// }
// }

// // 調布ポイント
// // 閉塞 chofu_up_b1 にいる列車の目的地に応じてポイントを切り替える
// const train = trains.find(t => t.positionId === "chofu_up_b1");
// if (train) {
// const destination = train.destination;
// if (destination.includes("hashimoto")) {
// if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_REVERSE
// }
// })
// }
// } else {
// if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
// await client.updatePointState({
// "state": {
// "id": point.id,
// "state": PointStateEnum.POINT_STATE_NORMAL
// }
// })
// }
// // // 調布ポイント
// // // 閉塞 chofu_up_b1 にいる列車の目的地に応じてポイントを切り替える
// // const train = trains.find(t => t.positionId === "chofu_up_b1");
// // if (train) {
// // const destination = train.destination;
// // if (destination.includes("hashimoto")) {
// // if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
// // await client.updatePointState({
// // "state": {
// // "id": point.id,
// // "state": PointStateEnum.POINT_STATE_REVERSE
// // }
// // })
// // }
// // } else {
// // if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
// // await client.updatePointState({
// // "state": {
// // "id": point.id,
// // "state": PointStateEnum.POINT_STATE_NORMAL
// // }
// // })
// // }

// }
// }
// }
}
// // }
// // }
// // }
// }
}

// addTest();
Expand Down
6 changes: 3 additions & 3 deletions backend/auto-operation/map/mfk-2024.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"stopBlocks": {
"ninini_s1": "ninini_b1",
"ninini_s2": "ninini_b1",
"nanana_s1": "nanana_b1"
"ninini_s1": "nanana_b1",
"ninini_s2": "nanana_b1",
"nanana_s1": "ninini_b1"
},
"stations": {
"ninini": {
Expand Down

0 comments on commit 9952024

Please sign in to comment.