Simulation activate/deactivate
This commit is contained in:
parent
9395f71485
commit
ef938ab84a
@ -73,7 +73,7 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
env_file: ".env"
|
||||
ports:
|
||||
- "10000:10000"
|
||||
- "10001:10000"
|
||||
depends_on:
|
||||
- nats
|
||||
networks:
|
||||
@ -95,26 +95,22 @@ services:
|
||||
networks:
|
||||
- dns_net
|
||||
restart: always
|
||||
# For messaging
|
||||
nats:
|
||||
image: nats
|
||||
container_name: dns-nats
|
||||
|
||||
#
|
||||
math:
|
||||
container_name: dns-math
|
||||
build:
|
||||
context: ./src/microservices/py-simulation
|
||||
dockerfile: Dockerfile
|
||||
env_file: ".env"
|
||||
ports:
|
||||
- "8222:8222"
|
||||
- "6222:6222"
|
||||
command: "--cluster_name NATS --cluster nats://0.0.0.0:6222 --http_port 8222 "
|
||||
- "10000:10000"
|
||||
networks:
|
||||
- dns_net
|
||||
restart: always
|
||||
nats-1:
|
||||
image: nats
|
||||
container_name: dns-nats-cluster-1
|
||||
command: "--cluster_name NATS --cluster nats://0.0.0.0:6222 --routes=nats://ruser:T0pS3cr3t@nats:6222"
|
||||
networks:
|
||||
- dns_net
|
||||
depends_on: ["nats"]
|
||||
restart: always
|
||||
|
||||
|
||||
# For messaging
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
BIN
docs/imgs/sim_process.png
Normal file
BIN
docs/imgs/sim_process.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
@ -114,7 +114,7 @@ class DroneNetworkSimulator:
|
||||
return 5.0
|
||||
return 1.0
|
||||
|
||||
@app.post("/start_simulation")
|
||||
@app.post("/simulation/forceRunCalc")
|
||||
async def start_simulation(request: SimulationRequest):
|
||||
try:
|
||||
simulator = DroneNetworkSimulator(
|
||||
|
15
src/microservices/py-simulation/requirements.txt
Normal file
15
src/microservices/py-simulation/requirements.txt
Normal file
@ -0,0 +1,15 @@
|
||||
annotated-types==0.7.0
|
||||
anyio==4.6.2.post1
|
||||
click==8.1.7
|
||||
fastapi==0.115.5
|
||||
h11==0.14.0
|
||||
idna==3.10
|
||||
numpy==2.1.3
|
||||
pydantic==2.9.2
|
||||
pydantic_core==2.23.4
|
||||
PyWavefront==1.3.3
|
||||
sniffio==1.3.1
|
||||
starlette==0.41.2
|
||||
typing_extensions==4.12.2
|
||||
uvicorn==0.32.0
|
||||
websockets==14.1
|
@ -60,9 +60,13 @@ func SpawnServer() error {
|
||||
|
||||
// GET http://localhost:8080/get/server/state
|
||||
app.Get("/get/server/state", GetServerState)
|
||||
|
||||
// WebSocket маршрут
|
||||
app.Get("/ws/connect/", websocket.New(CreateOrConnectSocket))
|
||||
|
||||
// Return scheme for request to start simulation
|
||||
app.Get("/simulation/forceRunCalc", ForceRunCalcSim)
|
||||
|
||||
return app.Listen(os.Getenv("SERVER_BASE_ADDRESS"))
|
||||
}
|
||||
|
||||
|
@ -49,3 +49,12 @@ func GetActiveRooms(c *fiber.Ctx) error {
|
||||
c.Write(res)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ForceRunCalcSim "заставляет" запустить симуляцию игнорируя очередь
|
||||
func ForceRunCalcSim(c *fiber.Ctx) error {
|
||||
return c.Status(1002).JSON(fiber.Map{
|
||||
"message": "Wait minutes, prepare simulation...",
|
||||
"link": "localhost:10000/run/sumulation",
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,12 @@ import { PlayCircleIcon } from '@heroicons/react/24/outline';
|
||||
import FormComponent from '../ObjectProps/FormComponent';
|
||||
import Modal from '../Modal/Modal';
|
||||
|
||||
const ThreeJsInstance = () => {
|
||||
|
||||
interface IThreeJsInstance {
|
||||
Click: (value: boolean) => void; // клик по кнопке
|
||||
}
|
||||
|
||||
const ThreeJsInstance : React.FC<IThreeJsInstance> = ({Click}) => {
|
||||
const [drones, setDrones] = useState<Drone[]>([]);
|
||||
const [baseStations, setBaseStations] = useState<BaseStation[]>([]);
|
||||
const [selectedObject, setSelectedObject] = useState<{ type: 'drone' | 'baseStation'; id: number } | null>(null);
|
||||
@ -58,6 +63,16 @@ const ThreeJsInstance = () => {
|
||||
]);
|
||||
};
|
||||
|
||||
const runSimulation = () => {
|
||||
// GET:
|
||||
// baseStations
|
||||
// drones
|
||||
// SET TO PAYLOAD
|
||||
const STANDART_TS = 300; // seconds
|
||||
const STANDART_TIMESTEP = 1; // timestep
|
||||
Click(true)
|
||||
}
|
||||
|
||||
const handleObjectClick = (type: 'drone' | 'baseStation', id: number) => {
|
||||
setSelectedObject({ type, id });
|
||||
setIsModalOpen(true);
|
||||
@ -181,7 +196,7 @@ const ThreeJsInstance = () => {
|
||||
<button onClick={resetCamera} className="p-2 m-2 bg-red-500 text-white rounded transition duration-300 ease-in-out transform hover:scale-105 focus:scale-95">Сбросить камеру</button>
|
||||
|
||||
<button onClick={() => document.getElementById("fileInput")?.click()} className="p-2 m-2 bg-orange-400 text-white rounded transition duration-300 ease-in-out transform hover:scale-105 focus:scale-95">Загрузка из JSON</button>
|
||||
<button onClick={() => {}} className="p-1 m-2 w-9 h-9 bg-emerald-700 text-white rounded transition duration-300 ease-in-out transform hover:scale-105 focus:scale-95">
|
||||
<button onClick={() => runSimulation()} className="p-1 m-2 w-9 h-9 bg-emerald-700 text-white rounded transition duration-300 ease-in-out transform hover:scale-105 focus:scale-95">
|
||||
<PlayCircleIcon/>
|
||||
</button>
|
||||
{selectedObject && (
|
||||
@ -270,3 +285,6 @@ const BaseStationModel = ({ position, onClick, isSelected }: { position: [number
|
||||
};
|
||||
|
||||
export default ThreeJsInstance;
|
||||
|
||||
|
||||
// /simulation/forceRunCalc => start simulation => REQUEST(DTO) => START_PLAYER()
|
||||
|
@ -1,17 +1,43 @@
|
||||
"use client";
|
||||
import InitPlayer from '@/app/components/Player/Player';
|
||||
import ThreeJsInstance from '@/app/components/Threejs/ThreeJsInstance';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
|
||||
const Simulations: React.FC = () => {
|
||||
const [activeSimalationWindow, setActiveSimalationWindow] = useState(false);
|
||||
const [activeSimulationWindow, setActiveSimulationWindow] = useState(false);
|
||||
const [mathServer, setMathServer] = useState("");
|
||||
const [simulationDto, setSimulationDto] = useState({});
|
||||
const ActiveSimulation = (value: boolean) => setActiveSimulationWindow(value);
|
||||
|
||||
useEffect(() => {
|
||||
// let value = SendRequestGetLink()
|
||||
// value.then(e => {
|
||||
// if (e.status == 1002){
|
||||
// e.json().then( res =>{
|
||||
// if (res.link) {
|
||||
// setMathServer(res.link)
|
||||
// }})}
|
||||
// })
|
||||
setMathServer("localhost:10000/run/sumulation")
|
||||
|
||||
}, [])
|
||||
|
||||
// => localhost:10000/run/sumulation
|
||||
|
||||
return (
|
||||
|
||||
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
||||
{/* TEST : MATH SERVER ENDPOINT */}
|
||||
{/* <p>{mathServer}</p> */}
|
||||
<main id="modal-root">
|
||||
{activeSimalationWindow ? <div>
|
||||
</div> : <ThreeJsInstance/>}
|
||||
{activeSimulationWindow ?
|
||||
<div>
|
||||
<InitPlayer
|
||||
Click={() => {}}
|
||||
TimeEnd={100}
|
||||
TimeStep={1}
|
||||
></InitPlayer>
|
||||
</div> : <ThreeJsInstance Click={ActiveSimulation}/>}
|
||||
</main>
|
||||
|
||||
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
|
||||
@ -19,4 +45,20 @@ const Simulations: React.FC = () => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const SendRequestGetLink = async () => {
|
||||
const requestOptions: RequestInit = {
|
||||
method: "GET",
|
||||
redirect: "follow"
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(`http://api.localhost/simulation/forceRunCalc`, requestOptions);
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw new Error('Network error');
|
||||
}
|
||||
};
|
||||
|
||||
export default Simulations;
|
Loading…
Reference in New Issue
Block a user