12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- from flask import Flask, request, jsonify
- import json
- from csvread import read_dddd_data, read_satellite_data, get_position_by_time
- from stkcom import *
- # 开启http server
- app = Flask(__name__)
- # 存储dddd数据、satellite数据
- dddd_array = []
- satellite_array = []
- @app.route("/")
- def hello_world():
- return "这是电子gf弹道服务器"
- @app.route("/traj", methods=["GET","POST"])
- def get_traj():
- # 1. 启动STK
- root = activeSTK()
- if root is None:
- print("启动STK失败")
- else:
- print("启动STK成功")
- # axois用这个
- # xdparams = request.get_json(force=True)
- # postman用这个
- xdjson = request.form.to_dict()
- # xdjson = json.loads(xdparams)
- # 1.解析想定
- (
- begintime,
- endtime,
- timestep,
- id,
- xdname,
- redunit,
- blueunit,
- satellite,
- center,
- ) = get_data_from_json(xdjson)
- starttime, stoptime, duration = datetime_transform(begintime, endtime)
- # 2.创建场景
- ret = createScenario(
- root,
- xdname,
- starttime,
- stoptime,
- duration
- )
- # 3.导出轨迹文件
- exportMovementFile(root, redunit, satellite, starttime, stoptime, timestep)
- # 从轨迹文件中读取轨迹数据
- for i in range(len(redunit)):
- str = redunit[i].get("name") + '.csv'
- dddd_array.append(read_dddd_data("C:\\fire\\simulation",str))
- for i in range(len(satellite)):
- str = satellite[i].get("name") + '.csv'
- satellite_array.append((read_satellite_data("C:\\fire\\simulation",str)))
- # 获取最终要返回给请求端的json list
- final_data = get_position_by_time(starttime, stoptime, dddd_array, satellite_array, timestep, redunit, satellite)
- return jsonify({"status":"success"},{"data":final_data}), 200
-
- # @app.route("/pos", methods=["GET","POST"])
- # def get_pos():
-
|