AircraftDY.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using KYFramework;
  2. using Model;
  3. using MongoDB.Bson;
  4. using SimulationCommon;
  5. namespace SimulationServer;
  6. public class AircraftDY : AircraftEntity
  7. {
  8. public TaskParameter SHJParameter;
  9. public KZDYTask taskContent;
  10. public MissionEndPoint MissionEndPoint;
  11. public bool IsOver;
  12. public bool Success;
  13. public TaskParameter taskParameter;
  14. public GetNCData getNCData;
  15. public double resulttime;
  16. public int targetCount;
  17. public bool isReadNC;
  18. Text_readNC text_ReadNC;
  19. public override void End()
  20. {
  21. TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
  22. }
  23. public override void Reset()
  24. {
  25. base.Reset();
  26. IsOver = false;
  27. Success = false;
  28. TotalTime = 0;
  29. targetCount = 0;
  30. }
  31. public override void Start()
  32. {
  33. targetCount = FlightPlanEditor.targetpoint[0].TargetType.Count;
  34. if (!isReadNC)
  35. {
  36. getNCData = new GetNCData();
  37. getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
  38. getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
  39. bool isSuccess3 = false;
  40. while (!isSuccess3)
  41. {
  42. isSuccess3 = getNCData.GetData();
  43. }
  44. text_ReadNC = new Text_readNC();
  45. text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
  46. text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
  47. //text_ReadNC = new Text_readNC();
  48. bool isSuccess = false;
  49. while (!isSuccess)
  50. {
  51. isSuccess = text_ReadNC.GetNCData();
  52. }
  53. isReadNC = true;
  54. }
  55. int hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
  56. //Console.WriteLine("hour:" + hour);
  57. double windSpeed = Convert.ToDouble(TargetQiXiangInfoSave("风速", hour));
  58. //Console.WriteLine("windSpeed:" + windSpeed);
  59. double vis = Convert.ToDouble(TargetQiXiangInfoSave("能见度", hour));
  60. //Console.WriteLine("vis:" + vis);
  61. FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
  62. FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
  63. FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.targetpoint[0].TargetPointHeight;
  64. //Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
  65. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  66. // 吊运上升速度 吊运下降速度 Task文件读取 // Editor里读天气根据时间
  67. resulttime = get_result_time_rope(taskParameter.Height, taskParameter.liftPersonnel, windSpeed, vis, taskParameter.liftUpSpeed, taskParameter.liftDownSpeed).time;//索滑降模型输出的索滑降时间
  68. Console.WriteLine("resulttime:" + resulttime);
  69. FXJHGenerate.SuoHuaJiang(resulttime, FlightPlanEditor, ref TurningPoints);
  70. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, FXJHGenerate.SuoHuaJiangMissionEndPoint(FlightPlanEditor), ref TurningPoints);
  71. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  72. // 飞到目标点时间与人员存活时间做对比 有一个人活着,整个任务成功
  73. double time = 0;
  74. for (int i = 0; i < TurningPoints.Count - 1; i++)
  75. {
  76. time += TurningPoints[i].SegmentFlightTime; // 判断幸存-1
  77. }
  78. //Console.WriteLine("time:" + time);
  79. // 类型只有人,其它不影响任务成功率 ,所有目标都影响识别成功率 任务准备时间 分钟 平均搜索时间 小时 平均救助时间 秒 总飞行时间 小时 第一列加单位
  80. if (FlightPlanEditor.targetpoint[0].TargetType.Type == "落水人员")
  81. {
  82. double latitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude; //落水人员纬度;数据测试用
  83. double longitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude; //落水人员经度,数据测试用
  84. int Days;
  85. int Hour;
  86. int Year = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[0]);
  87. int Month = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[0]);
  88. int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
  89. Hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
  90. Days = GetDaysInYear(Year, Month, Day);
  91. double survivalTime = SurvivalTimeModel.SurvivalTime(getNCData.tempreadNC, latitude, longitude, time, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour); //幸存时间
  92. //Console.WriteLine("survivalTime:" + survivalTime * 3600);
  93. if (survivalTime * 3600 > time)
  94. {
  95. Success = true;
  96. //Console.WriteLine("Success:" + true);
  97. }
  98. }
  99. if (FlightPlanEditor.targetpoint[0].TargetType.Type == "遇险人员")
  100. {
  101. if (FlightPlanEditor.targetpoint[0].TargetType.LiveTime > time) //陆上搜寻预期存活时间读配置文件
  102. {
  103. Success = true;
  104. //Console.WriteLine("Success:" + true);
  105. }
  106. }
  107. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  108. {
  109. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  110. }
  111. Console.WriteLine("TotalTime:" + TotalTime);
  112. IsOver = true;
  113. End();
  114. }
  115. // --接口
  116. // --输入
  117. // --
  118. // 1)吊运高度(m)
  119. //--H(double)
  120. // 2)吊运人数
  121. //--person_number(int)
  122. // 3)风速(m/s)
  123. //--windspeed(double)
  124. // 4)能见度(m/)
  125. // --vis(double)
  126. // 5)吊运上升速度(m/s)
  127. //--upspeed(double)
  128. // 6)吊运下降速度(m/s)
  129. //--downspeed(double)
  130. // --
  131. // --输出
  132. // --
  133. // 1)能否吊运、吊运时间
  134. //--result(handling_result)
  135. // --
  136. //--定义handling_result类
  137. // 吊运函数
  138. public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed)
  139. {
  140. handling_result result = new handling_result();
  141. if (windspeed < 8 && vis > 3)
  142. {
  143. result.time = (person_number * H) / downspeed + (person_number * H) / upspeed;
  144. result.success = true;
  145. }
  146. else
  147. {
  148. result.success = false;
  149. }
  150. return result;
  151. }
  152. public string TargetQiXiangInfoSave(string s, int hour)
  153. {
  154. string result = hour.ToString() + "-" + s;
  155. switch (s)
  156. {
  157. case "温度":
  158. if (hour >= 0 && hour < 8)
  159. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Temperature_00_08.ToString();
  160. else if (hour >= 8 && hour < 19)
  161. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Temperature_08_19.ToString();
  162. else if (hour >= 19 && hour <= 24)
  163. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Temperature_19_24.ToString();
  164. break;
  165. case "湿度":
  166. if (hour >= 0 && hour < 8)
  167. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Humidity_00_08.ToString();
  168. else if (hour >= 8 && hour < 19)
  169. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Humidity_08_19.ToString();
  170. else if (hour >= 19 && hour <= 24)
  171. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Humidity_19_24.ToString();
  172. break;
  173. case "能见度":
  174. if (hour >= 0 && hour < 8)
  175. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Visibility_00_08.ToString();
  176. else if (hour >= 8 && hour < 19)
  177. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Visibility_08_19.ToString();
  178. else if (hour >= 19 && hour <= 24)
  179. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Visibility_19_24.ToString();
  180. break;
  181. case "风速":
  182. if (hour >= 0 && hour < 8)
  183. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindSpeed_00_08.ToString();
  184. else if (hour >= 8 && hour < 19)
  185. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindSpeed_08_19.ToString();
  186. else if (hour >= 19 && hour <= 24)
  187. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindSpeed_19_24.ToString();
  188. break;
  189. case "风向":
  190. if (hour >= 0 && hour < 8)
  191. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindDirection_00_08.ToString();
  192. else if (hour >= 8 && hour < 19)
  193. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindDirection_08_19.ToString();
  194. else if (hour >= 19 && hour <= 24)
  195. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindDirection_19_24.ToString();
  196. break;
  197. case "天气":
  198. if (hour >= 0 && hour < 8)
  199. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Weather_00_08;
  200. else if (hour >= 8 && hour < 19)
  201. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Weather_08_19;
  202. else if (hour >= 19 && hour <= 24)
  203. result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Weather_19_24;
  204. break;
  205. }
  206. return result;
  207. }
  208. public static int GetDaysInYear(int year, int month, int day)
  209. {
  210. int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  211. if (IsLeapYear(year))
  212. {
  213. daysInMonths[1] = 29;
  214. }
  215. int days = day;
  216. for (int i = 0; i < month - 1; i++)
  217. {
  218. days += daysInMonths[i];
  219. }
  220. return days;
  221. }
  222. public static bool IsLeapYear(int year)
  223. {
  224. return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  225. }
  226. }
  227. public class handling_result
  228. {
  229. public bool success { get; set; }
  230. public double time { get; set; }
  231. }
  232. [ObjectSystem]
  233. public class AircraftDYAwakeSystem : AwakeSystem<AircraftDY, FlightPlanEditor>
  234. {
  235. public override void Awake(AircraftDY self, FlightPlanEditor flightPlanEditor)
  236. {
  237. self.FlightPlanEditor = flightPlanEditor;
  238. self.Awake();
  239. }
  240. }