|
@@ -0,0 +1,177 @@
|
|
|
+using KYFramework;
|
|
|
+using NPOI.SS.Formula.PTG;
|
|
|
+using SimulationServer.Utils;
|
|
|
+
|
|
|
+namespace SimulationServer;
|
|
|
+
|
|
|
+public class ZSJYMission : Entity
|
|
|
+{
|
|
|
+ public string MissionId; // 任务ID
|
|
|
+ public bool Success; // 任务是否成功
|
|
|
+ public List<AircraftZS> aircrafts = new List<AircraftZS>();
|
|
|
+
|
|
|
+ public bool IsRunning;
|
|
|
+ public double SimulationTime;
|
|
|
+
|
|
|
+ public Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> singleReport = new();
|
|
|
+
|
|
|
+ public Dictionary<string, Dictionary<string, List<string>>> aircraftSJDatas = new();
|
|
|
+
|
|
|
+ public bool IsOver = false;
|
|
|
+
|
|
|
+ private int currentExecuteCount = 1;
|
|
|
+ public int ExecutionContext = 0;
|
|
|
+ public void Start()
|
|
|
+ {
|
|
|
+ IsRunning = true;
|
|
|
+ aircrafts.ForEach(a => a.Start());
|
|
|
+ Log.Info($"{MissionId} 任务开始!");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Reset()
|
|
|
+ {
|
|
|
+ SimulationTime = 0;
|
|
|
+ aircrafts?.ForEach(a => a.Reset());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void EndMission()
|
|
|
+ {
|
|
|
+ IsRunning = false;
|
|
|
+ Log.Info($"{MissionId} 任务结束!");
|
|
|
+
|
|
|
+ if (currentExecuteCount > ExecutionContext)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentExecuteCount < ExecutionContext)
|
|
|
+ {
|
|
|
+ SaveSJ();
|
|
|
+ SaveAircraftSJDatas();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentExecuteCount == ExecutionContext)
|
|
|
+ {
|
|
|
+ SaveSJ();
|
|
|
+ SaveAircraftSJDatas();
|
|
|
+ ReportSJ();
|
|
|
+ IsOver = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.Reset();
|
|
|
+ this.Start();
|
|
|
+ currentExecuteCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SaveAircraftSJDatas()
|
|
|
+ {
|
|
|
+ foreach (AircraftZS aircraftEntity in aircrafts)
|
|
|
+ {
|
|
|
+ string key = aircraftEntity.AircraftId;
|
|
|
+ if (!aircraftSJDatas.ContainsKey(key))
|
|
|
+ {
|
|
|
+ aircraftSJDatas[key] = new Dictionary<string, List<string>>();
|
|
|
+ }
|
|
|
+ if (!aircraftSJDatas[key].ContainsKey("识别成功率"))
|
|
|
+ aircraftSJDatas[key]["识别成功率"] = new List<string>();
|
|
|
+ aircraftSJDatas[key]["识别成功率"].Add("0");
|
|
|
+ if (!aircraftSJDatas[key].ContainsKey("任务准备时间"))
|
|
|
+ aircraftSJDatas[key]["任务准备时间"] = new List<string>();
|
|
|
+ aircraftSJDatas[key]["任务准备时间"].Add(aircraftEntity.TaskReadyTime.ToString());
|
|
|
+ if (!aircraftSJDatas[key].ContainsKey("平均搜索时间"))
|
|
|
+ aircraftSJDatas[key]["平均搜索时间"] = new List<string>();
|
|
|
+ aircraftSJDatas[key]["平均搜索时间"].Add("0");
|
|
|
+ if (!aircraftSJDatas[key].ContainsKey("总飞行时间"))
|
|
|
+ aircraftSJDatas[key]["总飞行时间"] = new List<string>();
|
|
|
+ aircraftSJDatas[key]["总飞行时间"].Add(aircraftEntity.TotalTime.ToString());
|
|
|
+ if (!aircraftSJDatas[key].ContainsKey("人员存活率"))
|
|
|
+ aircraftSJDatas[key]["人员存活率"] = new List<string>();
|
|
|
+ aircraftSJDatas[key]["人员存活率"].Add(aircraftEntity.Success ? "1" : "0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SaveSJ()
|
|
|
+ {
|
|
|
+ foreach (AircraftZS aircraftEntity in aircrafts)
|
|
|
+ {
|
|
|
+ var staticCapacity = aircraftEntity.GetComponent<SJStaticCapacityComponent>();
|
|
|
+
|
|
|
+ if (staticCapacity == null) continue;
|
|
|
+
|
|
|
+ staticCapacity.FillData4(aircraftEntity.Db);
|
|
|
+
|
|
|
+ string key = aircraftEntity.AircraftId;
|
|
|
+
|
|
|
+ if (!singleReport.ContainsKey(key))
|
|
|
+ {
|
|
|
+ singleReport[key] = new Dictionary<string, Dictionary<string, List<string>>>();
|
|
|
+ }
|
|
|
+
|
|
|
+ Dictionary<string, Dictionary<string, string>> staticReport = staticCapacity.GetReport4();
|
|
|
+ foreach (var kv in staticReport)
|
|
|
+ {
|
|
|
+ if (!singleReport[key].ContainsKey(kv.Key)) singleReport[key][kv.Key] = new Dictionary<string, List<string>>();
|
|
|
+ foreach (var kv2 in kv.Value)
|
|
|
+ {
|
|
|
+ if (!singleReport[key][kv.Key].ContainsKey(kv2.Key)) singleReport[key][kv.Key][kv2.Key] = new List<string>();
|
|
|
+ singleReport[key][kv.Key][kv2.Key].Add(kv2.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (currentExecuteCount == ExecutionContext)
|
|
|
+ {
|
|
|
+ foreach (var kv in singleReport)
|
|
|
+ {
|
|
|
+ foreach (var kv2 in kv.Value)
|
|
|
+ {
|
|
|
+ foreach (var kv3 in kv2.Value)
|
|
|
+ {
|
|
|
+ var sum = 0f;
|
|
|
+ foreach (var kv4 in kv3.Value)
|
|
|
+ {
|
|
|
+ bool isfloat = float.TryParse(kv4, out float f);
|
|
|
+ if (isfloat)
|
|
|
+ sum += float.Parse(kv4);
|
|
|
+ else
|
|
|
+ sum = -1f;
|
|
|
+ }
|
|
|
+ if (sum != -1f)
|
|
|
+ kv3.Value.Add((sum / kv3.Value.Count).ToString());
|
|
|
+ else
|
|
|
+ kv3.Value.Add("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ReportSJ()
|
|
|
+ {
|
|
|
+ string data = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
+ string path = $"Reports/着水救援任务/{data}/{MissionId}"; //作为海上/陆上搜救子任务需生成实验报告,路径不确定,需判断跟随谁
|
|
|
+ if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
|
|
+ foreach (var kv in singleReport)
|
|
|
+ {
|
|
|
+ string filePath = $"{path}/{kv.Key}搜救任务单机指标报告.xls";
|
|
|
+ DataTableExtensions.SaveToExcel(filePath, kv.Value, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+[ObjectSystem]
|
|
|
+public class ZSJYMissionUpdateSystem : UpdateSystem<ZSJYMission>
|
|
|
+{
|
|
|
+ public override void Update(ZSJYMission self)
|
|
|
+ {
|
|
|
+ if (!self.IsRunning) return;
|
|
|
+
|
|
|
+ self.aircrafts?.ForEach(a => a.Update(self.SimulationTime));
|
|
|
+
|
|
|
+ if (self.aircrafts.All(a => a.IsOver))
|
|
|
+ {
|
|
|
+ self.EndMission();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|