Browse Source

Realize position service, given query time

Haobin Luo 1 year ago
parent
commit
0a5a08979a
1 changed files with 22 additions and 3 deletions
  1. 22 3
      app.py

+ 22 - 3
app.py

@@ -9,6 +9,8 @@ app = Flask(__name__)
 # 存储dddd数据、satellite数据
 dddd_array = []
 satellite_array = []
+global final_data
+final_data = []
 
 @app.route("/")
 def hello_world():
@@ -61,10 +63,27 @@ def get_traj():
             satellite_array.append((read_satellite_data("C:\\fire\\simulation",str)))
 
         # 获取最终要返回给请求端的json list
+        global final_data
         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():
-    
+@app.route("/pos", methods=["GET","POST"])
+def get_pos():
+    if len(final_data) == 0:
+        return jsonify({}), 200
+    posjson = request.form.to_dict()
+    currentTime = posjson['simulation_time']
+    print(currentTime)
+    currentTime = datetime.datetime.strptime(currentTime, "%Y-%m-%d %H:%M:%S.%f")
+
+    # 越界检查
+    starttime = datetime.datetime.strptime(final_data[0]["dateTime"], "%d %b %Y %H:%M:%S.%f")
+    stoptime = datetime.datetime.strptime(final_data[-2]["dateTime"], "%d %b %Y %H:%M:%S.%f")
+    steptime = (datetime.datetime.strptime(final_data[1]["dateTime"], "%d %b %Y %H:%M:%S.%f") - datetime.datetime.strptime(final_data[0]["dateTime"], "%d %b %Y %H:%M:%S.%f")).total_seconds()
+    if currentTime < starttime or currentTime > stoptime:
+        return jsonify({"status":"success"},{"data":None}), 200
+    else:
+        # 计算下标
+        idx = int((currentTime - starttime).total_seconds()/steptime)
+        return jsonify({"status":"success"},{"data":final_data[idx]}), 200