Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use vite and implement blocks #264

Merged
merged 9 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 54 additions & 15 deletions backend/auto-operation/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ async function main() {
// 閉塞の確認する
const block = blocks.find(b => b.blockId === collespondBlock);
if (block && block.state === BlockStateEnum.BLOCK_STATE_CLOSE) {
// sakurajosui_down_s1はSTOPにしない chofufes
if (stop.id === "sakurajosui_down_s1") continue;
if (stop.state !== StopStateEnum.STOP_STATE_STOP) {
// 閉塞が閉じていたら列車を止めておく
await client.updateStopState({
Expand All @@ -73,6 +75,16 @@ async function main() {
}
})
}
} else {
if (stop.state !== StopStateEnum.STOP_STATE_GO) {
// 閉塞が開いていたら列車を開けておく
await client.updateStopState({
"state": {
"id": stop.id,
"state": StopStateEnum.STOP_STATE_GO
}
})
}
}
}

Expand Down Expand Up @@ -138,8 +150,9 @@ async function main() {
}
}
if (point.id === "sakurajosui_down_p1") {
const sakurajosui_down_s1 = stops.find(s => s.id === "sakurajosui_down_s1");
if (sakurajosui_down_s1 && sakurajosui_down_s1.state === StopStateEnum.STOP_STATE_STOP) {
// 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": {
Expand All @@ -160,37 +173,63 @@ async function main() {
}
}
if (point.id === "chofu_up_p1") {
// 調布ポイント
// 閉塞 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) {
// 閉塞が空いてる方に切り替える 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_REVERSE
"state": PointStateEnum.POINT_STATE_NORMAL
}
})
}
} else {
if (point.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_NORMAL
"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
// }
// })
// }

// }
// }
// }
}
}

addTest();
// addTest();

(async () => {
while (true) {
Expand Down
5 changes: 2 additions & 3 deletions backend/onetime/seed-data/data/chofufes-2023.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ stop_rails:
point_rails:
- sakurajosui_up_p1
- sakurajosui_down_p1
- chofu_up_p1
- chofu_down_p1
blocks:
- shinjyuku_down_b1
- sakurajosui_down_b1
- sakurajosui_down_b1
- sakurajosui_up_b1
- chofu_down_b2
- hashimoto_down_b1
- hashimoto_up_b1
- chofu_up_b1
- chofu_down_b1
- hachioji_down_b1
- hachioji_up_b1
- chofu_up_b1
- sakurajosui_up_b1
- sakurajosui_up_b1
- shinjyuku_up_b1
4 changes: 2 additions & 2 deletions backend/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
frontendURL, _ := url.Parse("http://localhost:3000")
frontendURL, _ := url.Parse("http://localhost:5173")
backendURL, _ := url.Parse("http://localhost:8080")

mux := http.NewServeMux()
Expand All @@ -24,5 +24,5 @@ func main() {
}
mux.Handle("/api/", &rev)

fmt.Println(http.ListenAndServe(":3030", mux))
fmt.Println(http.ListenAndServe(":3031", mux))
}
70 changes: 51 additions & 19 deletions backend/spec/state/v1/statev1connect/state.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/state-manager/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func main() {
"version": version,
"commit": commit,
},
LogLevel: slog.LevelDebug,
LogLevel: slog.LevelWarn,
},
),
),
Expand Down
13 changes: 13 additions & 0 deletions backend/state-manager/pkg/connect/connect_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (s *StateManagerServer) GetBlockStates(
ctx context.Context,
req *connect.Request[statev1.GetBlockStatesRequest],
) (*connect.Response[statev1.GetBlockStatesResponse], error) {
req.Header().Set("Access-Control-Allow-Headers", "*")
req.Header().Set("Access-Control-Allow-Origin", "*")
req.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")

blockStates, err := s.DBHandler.GetBlocks()
if err != nil {
err = connect.NewError(
Expand Down Expand Up @@ -144,6 +148,9 @@ func (s *StateManagerServer) GetStopStates(
ctx context.Context,
req *connect.Request[statev1.GetStopStatesRequest],
) (*connect.Response[statev1.GetStopStatesResponse], error) {
req.Header().Set("Access-Control-Allow-Headers", "*")
req.Header().Set("Access-Control-Allow-Origin", "*")
req.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
stopStates, err := s.DBHandler.GetStops()
if err != nil {
err = connect.NewError(
Expand Down Expand Up @@ -178,6 +185,9 @@ func (s *StateManagerServer) GetTrains(
ctx context.Context,
req *connect.Request[statev1.GetTrainsRequest],
) (*connect.Response[statev1.GetTrainsResponse], error) {
req.Header().Set("Access-Control-Allow-Headers", "*")
req.Header().Set("Access-Control-Allow-Origin", "*")
req.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
trains, err := s.DBHandler.GetTrains()
if err != nil {
err = connect.NewError(
Expand Down Expand Up @@ -209,6 +219,9 @@ func (s *StateManagerServer) AddTrain(
ctx context.Context,
req *connect.Request[statev1.AddTrainRequest],
) (*connect.Response[statev1.AddTrainResponse], error) {
req.Header().Set("Access-Control-Allow-Headers", "*")
req.Header().Set("Access-Control-Allow-Origin", "*")
req.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
err := s.DBHandler.AddTrain(req.Msg.Train)
if err != nil {
err = connect.NewError(
Expand Down
Loading