浏览代码

添加海上搜救输出报告

zansimple 8 月之前
父节点
当前提交
58dccd1c6b

+ 59 - 0
SimulationServer/Component/SJAllTotalTaskPerformance.cs

@@ -0,0 +1,59 @@
+namespace SimulationServer;
+
+public class SJAllTotalTaskPerformance
+{
+    public string 识别成功率;
+    public string 平均搜索时间;
+    public string 平均救助时间;
+    public string 总飞行时间;
+    public string 海情覆盖率;
+    public string 人员存活率;
+}
+
+public class SJAllTotalTaskPerformanceComponent
+{
+    public SJAllTotalTaskPerformance SJAllTotalTaskPerformance = new SJAllTotalTaskPerformance();
+    
+    public void FillData(List<SeaSJRescueMission> missions)
+    {
+        double 任务准备时间 = 0;
+        double 平均搜索时间 = 0;
+        double 总飞行时间 = 0;
+        double 人员存活率 = 0;
+        float 识别成功率 = missions.FindAll(a => a.Success).Count / missions.Count;
+        SJAllTotalTaskPerformance.识别成功率 = (识别成功率 * 100 ).ToString() ;
+        
+        double aircreftCount = 0;
+        foreach (SeaSJRescueMission mhRescueMission in missions)
+        {
+            foreach (var aircraft in mhRescueMission.aircrafts)
+            {
+                任务准备时间 += aircraft.TaskReadyTime;
+                平均搜索时间 += aircraft.SearchTime;
+                总飞行时间 += aircraft.TotalTime;
+                人员存活率 += aircraft.Success ? 1 : 0;
+                aircreftCount++;
+            }
+        }
+        SJAllTotalTaskPerformance.平均搜索时间 = (平均搜索时间 / aircreftCount).ToString();
+        SJAllTotalTaskPerformance.平均救助时间 = 5.ToString();
+        SJAllTotalTaskPerformance.总飞行时间 = 总飞行时间.ToString();
+        SJAllTotalTaskPerformance.海情覆盖率 = "60%".ToString();
+        SJAllTotalTaskPerformance.人员存活率 = (人员存活率 / aircreftCount).ToString();
+    }
+    
+    public Dictionary<string, Dictionary<string, string>> GetReport()
+    {
+        Dictionary<string, Dictionary<string, string>> report = new Dictionary<string, Dictionary<string, string>>();
+        report["总任务表现"] = new Dictionary<string, string>
+        {
+            { "识别成功率", SJAllTotalTaskPerformance.识别成功率.ToString() },
+            { "平均搜索时间", SJAllTotalTaskPerformance.平均搜索时间.ToString() },
+            { "平均救助时间", SJAllTotalTaskPerformance.平均救助时间.ToString() },
+            { "总飞行时间", SJAllTotalTaskPerformance.总飞行时间.ToString() },
+            { "海情覆盖率", SJAllTotalTaskPerformance.海情覆盖率.ToString() },
+            { "人员存活率", SJAllTotalTaskPerformance.人员存活率.ToString() }
+        };
+        return report;
+    }
+}

+ 1 - 25
SimulationServer/Component/SJTotalTaskPerformanceComponent.cs

@@ -6,13 +6,7 @@ public class SJTotalTaskPerformance
 {
     public string 任务准备时间;
     public string 任务成功率;
-    
-    // public string 识别成功率;
-    // public string 平均搜索时间;
-    // public string 平均救助时间;
-    // public string 总飞行时间;
-    // public string 海情覆盖率;
-    // public string 人员存活率;
+
 }
 
 public class SJTotalTaskPerformanceComponent : Component
@@ -24,29 +18,17 @@ public class SJTotalTaskPerformanceComponent : Component
         var mission = GetParent<SeaSJRescueMission>();
 
         float 识别成功率 = mission.aircrafts.FindAll(a => a.Success).Count / mission.aircrafts.Count;
-        //SJTotalTaskPerformance.识别成功率 = 识别成功率 * 100 + "%";
 
         double 任务准备时间 = 0;
-        // double 平均搜索时间 = 0;
-        // double 总飞行时间 = 0;
-        // double 人员存活率 = 0;
         int 任务成功次数 = 0;
         foreach (var aircraft in mission.aircrafts)
         {
             任务准备时间 += aircraft.TaskReadyTime;
-            // 平均搜索时间 += aircraft.SearchTime;
-            // 总飞行时间 += aircraft.TotalTime;
-            // 人员存活率 += aircraft.Success ? 1 : 0;
             任务成功次数 += aircraft.Success ? 1 : 0;
         }
 
         SJTotalTaskPerformance.任务准备时间 = 任务准备时间.ToString();
-        // SJTotalTaskPerformance.平均搜索时间 = (平均搜索时间 / mission.aircrafts.Count).ToString();
-        // SJTotalTaskPerformance.平均救助时间 = 5.ToString();
-        // SJTotalTaskPerformance.总飞行时间 = 总飞行时间.ToString();
-        // SJTotalTaskPerformance.海情覆盖率 = "60%".ToString();
         SJTotalTaskPerformance.任务成功率 = (任务成功次数 / mission.aircrafts.Count).ToString();
-        //SJTotalTaskPerformance.人员存活率 = (人员存活率 / mission.aircrafts.Count).ToString();
     }
 
     public Dictionary<string, Dictionary<string, string>> GetReport()
@@ -54,14 +36,8 @@ public class SJTotalTaskPerformanceComponent : Component
         Dictionary<string, Dictionary<string, string>> report = new Dictionary<string, Dictionary<string, string>>();
         report["总任务表现"] = new Dictionary<string, string>
         {
-            //{ "识别成功率", SJTotalTaskPerformance.识别成功率.ToString() },
             { "任务准备时间", SJTotalTaskPerformance.任务准备时间.ToString() },
-            //{ "平均搜索时间", SJTotalTaskPerformance.平均搜索时间.ToString() },
-            //{ "平均救助时间", SJTotalTaskPerformance.平均救助时间.ToString() },
-            //{ "总飞行时间", SJTotalTaskPerformance.总飞行时间.ToString() },
-            //{ "海情覆盖率", SJTotalTaskPerformance.海情覆盖率.ToString() },
             { "任务成功率", SJTotalTaskPerformance.任务成功率.ToString() },
-            //{ "人员存活率", SJTotalTaskPerformance.人员存活率.ToString() }
         };
         return report;
     }

+ 62 - 2
SimulationServer/Component/TaskComponent.cs

@@ -11,20 +11,62 @@ public class TaskComponent : Component
     public List<MHRescueMission> MHRescueMissions;
     public List<XHRescueMission> XHRescueMissions;
     public List<ZCRescueMission> ZCRescueMissions;
-    
     public List<SeaSJRescueMission> SeaSJRescueMissions;
 
+    public SJAllTotalTaskPerformanceComponent SJAllTotalTaskPerformance = new SJAllTotalTaskPerformanceComponent();
+    public Dictionary<string, Dictionary<string, List<string>>> alltotalReport = new ();
+
     public void Start()
     {
         MHRescueMissions?.ForEach(r => r.Reset());
         XHRescueMissions?.ForEach(r => r.Reset());
         
-        
         MHRescueMissions?.ForEach(r => r.Start());
         XHRescueMissions?.ForEach(r => r.Start());
         ZCRescueMissions?.ForEach(r => r.Start());
         SeaSJRescueMissions?.ForEach(r => r.Start());
     }
+
+    public void SaveSJ(Dictionary<string, Dictionary<string, string>> totalReport)
+    {
+        //把totalReport保存到alltotalReport
+        foreach (var kv in totalReport)
+        {
+            if(!alltotalReport.ContainsKey(kv.Key)) alltotalReport[kv.Key] = new Dictionary<string, List<string>>();
+            
+            
+            foreach (var kv2 in kv.Value)
+            {
+                if(!alltotalReport[kv.Key].ContainsKey(kv2.Key)) alltotalReport[kv.Key][kv2.Key] = new List<string>();
+                 
+                alltotalReport[kv.Key][kv2.Key].Add(kv2.Value);
+            }
+        }
+        
+        // 求一个平均值放到最后一位
+        foreach (var kv in alltotalReport)
+        {
+            foreach (var kv2 in kv.Value)
+            {
+                var sum = 0f;
+                foreach (var value in kv2.Value)
+                {
+                    sum += float.Parse(value);
+                }
+                kv2.Value.Add((sum / kv2.Value.Count).ToString());
+            }
+        }
+    }
+    
+    public void ReportAllSJ()
+    {
+        string data = DateTime.Now.ToString("yyyy-MM-dd");
+        string path = $"Reports/SJ/{data}";
+        if(!Directory.Exists(path)) Directory.CreateDirectory(path);
+
+        string totalPath = $"{path}/{"海上搜救任务总体指标报告"}.xls";
+        DataTableExtensions.SaveToExcel(totalPath, alltotalReport,true);
+    }
 }
 
 [ObjectSystem]
@@ -38,3 +80,21 @@ public class TaskComponentAwakeSystem : AwakeSystem<TaskComponent>
         self.SeaSJRescueMissions = new List<SeaSJRescueMission>();
     }
 }
+
+[ObjectSystem]
+public class TaskComponentUpdateSystem : UpdateSystem<TaskComponent>
+{
+    public override void Update(TaskComponent self)
+    {
+       if(self.SeaSJRescueMissions.Count < 0) return;
+       
+       if(self.SeaSJRescueMissions.All(m => m.IsOver))
+       {
+           self.SJAllTotalTaskPerformance.FillData(self.SeaSJRescueMissions);
+           var report = self.SJAllTotalTaskPerformance.GetReport();
+           self.SaveSJ(report);
+           self.ReportAllSJ();
+           self.SeaSJRescueMissions.Clear();
+       }
+    }
+}

+ 0 - 1
SimulationServer/Entity/AircraftMH.cs

@@ -26,7 +26,6 @@ public class AircraftMH : AircraftEntity
     // 任务开始
     public override void Start()
     {
-        
         FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
         // 计算出第一次洒水的时间
         FXJHGenerate.MieHuo1(FlightPlanEditor,ref TurningPoints);

+ 0 - 2
SimulationServer/Entity/AircraftSJ.cs

@@ -98,8 +98,6 @@ public class AircraftSJ : AircraftEntity
                 lat = startPoint1.lat/2 + startPoint2.lat/2,
                 lon = startPoint1.lon/2 + startPoint2.lon/2
             };
-            
-            
             waypoints = SectorSearch.sectorSearch(centerPoint, 30, taskContent.SearchWidth);
         }
 

+ 2 - 0
SimulationServer/Entity/MHRescueMission.cs

@@ -64,7 +64,9 @@ public class MHRescueMission : Entity
         End?.Invoke();
         
         SaveMH();
+        
         SaveTotalMH();
+        
         ReportMH();
 
         var readyTime = aircrafts.First().TaskReadyTime;

+ 3 - 1
SimulationServer/Entity/SeaSJRescueMission.cs

@@ -16,7 +16,8 @@ public class SeaSJRescueMission : Entity
     // 灭火的 整体能力
     // <sheet,<指标名,值列表>>
     public Dictionary<string, Dictionary<string, List<string>>> totalReport = new ();
-    
+
+    public bool IsOver = false;
     public void Start()
     {
         IsRunning = true;
@@ -31,6 +32,7 @@ public class SeaSJRescueMission : Entity
         SaveSJ();
         SaveTotalMH();
         ReportSJ();
+        IsOver = true;
         Log.Info($"{MissionId} 任务结束!");
 
         // var readyTime = AircraftXHs.First().TaskReadyTime;

+ 1 - 2
SimulationServer/EventHandler/CreateTaskEventHandler.cs

@@ -48,6 +48,7 @@ public class CreateMHTaskEventHandler : AEvent<CreateMHTask>
                 var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather,originBase,mhTask.MissionPoints[0], new []{point});
                 
                 AircraftMH aircraft = ComponentFactory.Create<AircraftMH, FlightPlanEditor>( flightPlanEditor);
+                
                 aircraft.Name = mhTask.missionInformation.AircraftInfos[i];
                 aircraft.AircraftId = mhTask.missionInformation.AircraftId[i];
                 
@@ -120,8 +121,6 @@ public class CreateMHTaskEventHandler : AEvent<CreateMHTask>
                 Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
             }
         }
-        
-        
         return UniTask.CompletedTask;
     }
 }