app.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from flask import Flask, request, jsonify
  2. import json
  3. from csvread import read_dddd_data, read_satellite_data, get_position_by_time
  4. from stkcom import *
  5. # 开启http server
  6. app = Flask(__name__)
  7. # 存储dddd数据、satellite数据
  8. dddd_array = []
  9. satellite_array = []
  10. @app.route("/")
  11. def hello_world():
  12. return "这是电子gf弹道服务器"
  13. @app.route("/traj", methods=["GET","POST"])
  14. def get_traj():
  15. # 1. 启动STK
  16. root = activeSTK()
  17. if root is None:
  18. print("启动STK失败")
  19. else:
  20. print("启动STK成功")
  21. # axois用这个
  22. # xdparams = request.get_json(force=True)
  23. # postman用这个
  24. xdjson = request.form.to_dict()
  25. # xdjson = json.loads(xdparams)
  26. # 1.解析想定
  27. (
  28. begintime,
  29. endtime,
  30. timestep,
  31. id,
  32. xdname,
  33. redunit,
  34. blueunit,
  35. satellite,
  36. center,
  37. ) = get_data_from_json(xdjson)
  38. starttime, stoptime, duration = datetime_transform(begintime, endtime)
  39. # 2.创建场景
  40. ret = createScenario(
  41. root,
  42. xdname,
  43. starttime,
  44. stoptime,
  45. duration
  46. )
  47. # 3.导出轨迹文件
  48. exportMovementFile(root, redunit, satellite, starttime, stoptime, timestep)
  49. # 从轨迹文件中读取轨迹数据
  50. for i in range(len(redunit)):
  51. str = redunit[i].get("name") + '.csv'
  52. dddd_array.append(read_dddd_data("C:\\fire\\simulation",str))
  53. for i in range(len(satellite)):
  54. str = satellite[i].get("name") + '.csv'
  55. satellite_array.append((read_satellite_data("C:\\fire\\simulation",str)))
  56. # 获取最终要返回给请求端的json list
  57. final_data = get_position_by_time(starttime, stoptime, dddd_array, satellite_array, timestep, redunit, satellite)
  58. return jsonify({"status":"success"},{"data":final_data}), 200
  59. # @app.route("/pos", methods=["GET","POST"])
  60. # def get_pos():