AircraftXCJJ.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. using BHJD.DEMdll.Entity;
  2. using KYFramework;
  3. using MathNet.Numerics.Distributions;
  4. using Model;
  5. using MongoDB.Bson;
  6. using SimulationCommon;
  7. using SimulationServer.Utils;
  8. namespace SimulationServer;
  9. public class AircraftXCJJ : AircraftEntity
  10. {
  11. public XCJJTask taskContent;
  12. public MissionEndPoint MissionEndPoint;
  13. public bool IsOver;
  14. public bool Success;
  15. public TaskParameter taskParameter;
  16. public MissionEndPoint hospitalPoint;
  17. public List<double> jiuzhuTimes = new List<double>();
  18. public Dictionary<string, string> reportInfo = new Dictionary<string, string>();
  19. public TaskLoad load;
  20. public string device;
  21. public string medicine;
  22. public string hospitalAirport;
  23. public override void End()
  24. {
  25. TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
  26. }
  27. public override void Reset()
  28. {
  29. base.Reset();
  30. IsOver = false;
  31. Success = false;
  32. TotalTime = 0;
  33. reportInfo = new Dictionary<string, string>();
  34. device = string.Empty;
  35. medicine = string.Empty;
  36. }
  37. public override void Start()
  38. {
  39. FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  40. FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  41. FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalTargetPoint[0].TargetPointHeight;
  42. //Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
  43. int patientCount = FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; // 伤患人数
  44. List<string> diseaseTypes = new List<string>();
  45. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes.Length; i++)
  46. {
  47. diseaseTypes.Add(FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes[i]);
  48. }
  49. int medicCount = taskParameter.doctorPersonnel + taskParameter.nursePersonnel + taskParameter.nurseSeverePersonnel;//taskParameter.MedicalStaffCount; // 医护人员数量
  50. //Console.WriteLine("medicCount:" + medicCount);
  51. // 交接时间为5分钟
  52. double handoverTime = 5;
  53. // 计算总急救时间 需要飞机停留时间
  54. double totalEmergencyTime = CalculateTotalEmergencyTime(diseaseTypes);
  55. // 计算平均急救时间(每个医护人员分担的时间)
  56. double averageEmergencyTimePerMedic = totalEmergencyTime / medicCount;
  57. // 计算总时间(平均急救时间 + 交接时间)
  58. double totalTime = averageEmergencyTimePerMedic + handoverTime;
  59. Console.WriteLine($"总急救时间(平均每个医护人员): {averageEmergencyTimePerMedic} 分钟");
  60. Console.WriteLine($"总时间(包括交接时间): {totalTime} 分钟");
  61. Random rand = new Random();
  62. List<Patient> patients = new List<Patient>();
  63. for (int i = 0; i < patientCount; i++)
  64. {
  65. patients.Add(new Patient()
  66. {
  67. Id = i + 1,
  68. DiseaseType = diseaseTypes[i],
  69. GoldenHour = 0
  70. });
  71. }
  72. patients = MedicalRescue.ProcessPatients(patients, rand);
  73. // 对患者进行排序
  74. var sortedPatients = patients.OrderBy(p => DiseasePriorityService.GetPriority(p.DiseaseType))
  75. .ThenBy(p => p.GoldenHour)
  76. .ToList();
  77. // 输出排序后的患者列表 // 从是事故点到医院的飞行时间 + 5分钟的交接时间 < 黄金时间 ? 成功:失败
  78. foreach (var patient in sortedPatients)
  79. {
  80. Console.WriteLine($"sortedPatients ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {patient.GoldenHour:F2}");
  81. }
  82. // 注意:实际项目中,每次转运一名伤员的操作可能涉及更多的逻辑,比如更新数据库中的转运状态等。
  83. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  84. FXJHGenerate.JIJIU(totalTime, FlightPlanEditor, ref TurningPoints);
  85. FXJHGenerate.JIJIU1(5 * 60, hospitalPoint, ref TurningPoints);
  86. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.Count - 1; i++)
  87. {
  88. FXJHGenerate.JIJIU(5 * 60, FlightPlanEditor, ref TurningPoints);
  89. FXJHGenerate.JIJIU1(5 * 60, hospitalPoint, ref TurningPoints);
  90. }
  91. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, hospitalPoint, ref TurningPoints);
  92. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  93. double time = 0;
  94. for (int i = 2; i < 5; i++)
  95. {
  96. time += TurningPoints[i].SegmentFlightTime;
  97. }
  98. jiuzhuTimes.Add(time);
  99. int p = 5;
  100. int c = 0;
  101. for (int i = p; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.Count * 4 + 1; i++)
  102. {
  103. time += TurningPoints[i].SegmentFlightTime;
  104. c++;
  105. if (c == 4)
  106. {
  107. jiuzhuTimes.Add(time);
  108. c = 0;
  109. }
  110. }
  111. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  112. {
  113. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  114. }
  115. Console.WriteLine("TotalTime:" + TotalTime);
  116. reportInfo.Add("准备时间", TaskReadyTime.ToString());
  117. double reachTime = 0;
  118. for (int i = 0; i < 2; i++)
  119. {
  120. reachTime += TurningPoints[i].SegmentFlightTime;
  121. }
  122. reportInfo.Add("到达时间", reachTime.ToString()); // 基地 -> 目标点
  123. reportInfo.Add("任务周期时间", TotalTime.ToString());
  124. reportInfo.Add("执行任务飞机型号", Name);
  125. reportInfo.Add("执行任务飞机数量", "1");
  126. reportInfo.Add("单机飞行员人数", taskParameter.pilotPersonnel.ToString());
  127. reportInfo.Add("单机医师人数", taskParameter.doctorPersonnel.ToString());
  128. reportInfo.Add("单机护士人数", taskParameter.nursePersonnel.ToString());
  129. reportInfo.Add("单机重症监护护理人员人数", taskParameter.nurseSeverePersonnel.ToString());
  130. reportInfo.Add("单机地面保障人数", taskParameter.groundSupportPersonnel.ToString());
  131. reportInfo.Add("单机总任务时长", TotalTime.ToString());
  132. reportInfo.Add("单机总油耗", FXJHGenerate.CalculateTotalFuelConsumption(FlightPlanEditor, TurningPoints).ToString());
  133. reportInfo.Add("单机机场使用情况", Airport + "\r\n" + hospitalAirport);
  134. double zhc = 0;
  135. for (int i = 0; i < TurningPoints.Count - 1; i++)
  136. {
  137. zhc += Utils.Util.GetDistance(TurningPoints[i].TurningPointLongitude,
  138. TurningPoints[i + 1].TurningPointLongitude, TurningPoints[i].TurningPointLatitude, TurningPoints[i + 1].TurningPointLatitude);
  139. }
  140. reportInfo.Add("单机导航使用情况", zhc.ToString()); //飞行总距离
  141. if(load.FirstAid != null)
  142. {
  143. for (int i = 0; i < load.FirstAid.Length; i++)
  144. {
  145. device += load.FirstAid[i];
  146. device += "\r\n";
  147. }
  148. }
  149. if (load.HandlingAndFixing != null)
  150. {
  151. for (int i = 0; i < load.HandlingAndFixing.Length; i++)
  152. {
  153. device += load.HandlingAndFixing[i];
  154. device += "\r\n";
  155. }
  156. }
  157. if (load.DiagnosisAndMonitoring != null)
  158. {
  159. for (int i = 0; i < load.DiagnosisAndMonitoring.Length; i++)
  160. {
  161. device += load.DiagnosisAndMonitoring[i];
  162. device += "\r\n";
  163. }
  164. }
  165. if (load.Trauma != null)
  166. {
  167. for (int i = 0; i < load.Trauma.Length; i++)
  168. {
  169. device += load.Trauma[i];
  170. device += "\r\n";
  171. }
  172. }
  173. if (load.Infusion != null)
  174. {
  175. for (int i = 0; i < load.Infusion.Length; i++)
  176. {
  177. device += load.Infusion[i];
  178. device += "\r\n";
  179. }
  180. }
  181. if (load.Drug != null)
  182. {
  183. for (int i = 0; i < load.Drug.Length; i++)
  184. {
  185. medicine += load.Drug[i];
  186. if (i != load.Drug.Length - 1)
  187. medicine += "\r\n";
  188. }
  189. }
  190. char[] cs = { '\r', '\n' };
  191. device = device.TrimEnd(cs);
  192. //Console.WriteLine("医疗任务设备:" + device);
  193. //Console.WriteLine("医疗药品:" + medicine);
  194. if (device != null)
  195. reportInfo.Add("医疗任务设备", device);
  196. else
  197. reportInfo.Add("医疗任务设备", "");
  198. if (medicine != null)
  199. reportInfo.Add("医疗药品", medicine);
  200. else
  201. reportInfo.Add("医疗药品", "");
  202. reportInfo.Add("任务缓急情况", "紧急");
  203. IsOver = true;
  204. End();
  205. }
  206. static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
  207. {
  208. double totalTime = 0;
  209. // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
  210. foreach (var diseaseType in diseaseTypes)
  211. {
  212. double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
  213. totalTime += emergencyTime;
  214. }
  215. return totalTime;
  216. }
  217. // 模拟从数据库获取急救时间的方法
  218. static double GetEmergencyTimeFromDatabase(string diseaseType)
  219. {
  220. // 这里应该是实际的数据库查询逻辑
  221. // 但为了示例,我们直接返回一个模拟值
  222. switch (diseaseType)
  223. {
  224. case "aa": //HeartAttack
  225. return 2; // 心脏病急救时间为2分钟
  226. case "bb": //Stroke
  227. return 5; // 中风急救时间为5分钟
  228. case "cc": //Trauma
  229. return 10; // 创伤急救时间为10分钟
  230. case "dd":
  231. return 15;
  232. case "ee":
  233. return 20;
  234. default:
  235. return 0;
  236. }
  237. }
  238. // 假设从前端接收到的数据结构
  239. public class Patient
  240. {
  241. public int Id { get; set; }
  242. public string DiseaseType { get; set; }
  243. public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
  244. }
  245. public class DiseaseInfo
  246. {
  247. public string DiseaseType { get; set; }
  248. public double MinGoldenHour { get; set; }
  249. public double MaxGoldenHour { get; set; }
  250. }
  251. public class MedicalRescue
  252. {
  253. private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
  254. {
  255. { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
  256. { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
  257. { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
  258. { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
  259. { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },
  260. // 添加更多疾病类型
  261. };
  262. public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
  263. {
  264. foreach (var patient in patients)
  265. {
  266. var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
  267. double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
  268. Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
  269. patient.GoldenHour = goldenHour;
  270. }
  271. return patients;
  272. }
  273. public static DiseaseInfo GetDiseaseInfo(string diseaseType)
  274. {
  275. if (diseaseDatabase.ContainsKey(diseaseType))
  276. {
  277. return diseaseDatabase[diseaseType];
  278. }
  279. throw new ArgumentException("Unknown disease type.");
  280. }
  281. public static double GenerateRandomGoldenHour(Random rand, double min, double max)
  282. {
  283. double mu = (max + min) / 2;
  284. double sigma = (max - min) / 6;
  285. var normal = new Normal(mu, sigma);
  286. return normal.Sample();
  287. }
  288. }
  289. // 假设数据库中的疾病优先级信息
  290. public class DiseasePriority
  291. {
  292. public string DiseaseType { get; set; }
  293. public int Priority { get; set; } // 优先级,数字越小优先级越高
  294. }
  295. // 静态类,包含与疾病优先级相关的静态方法
  296. public static class DiseasePriorityService
  297. {
  298. // 数据库查询(实际项目中应该是从数据库读取)
  299. public static List<DiseasePriority> GetDiseasePriorities()
  300. {
  301. return new List<DiseasePriority>
  302. {
  303. new DiseasePriority { DiseaseType = "aa", Priority = 5 },
  304. new DiseasePriority { DiseaseType = "bb", Priority = 4 },
  305. new DiseasePriority { DiseaseType = "cc", Priority = 3 },
  306. new DiseasePriority { DiseaseType = "dd", Priority = 2 },
  307. new DiseasePriority { DiseaseType = "ee", Priority = 5 },
  308. };
  309. }
  310. // 根据疾病类型获取优先级
  311. public static int GetPriority(string diseaseType)
  312. {
  313. var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
  314. if (priorities.TryGetValue(diseaseType, out int priority))
  315. {
  316. return priority;
  317. }
  318. return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级
  319. }
  320. }
  321. public string TargetQiXiangInfoSave(string s, int hour)
  322. {
  323. string result = hour.ToString() + "-" + s;
  324. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  325. {
  326. }
  327. switch (s)
  328. {
  329. case "温度":
  330. break;
  331. case "湿度":
  332. break;
  333. case "能见度":
  334. break;
  335. case "风速":
  336. break;
  337. case "风向":
  338. break;
  339. case "天气":
  340. break;
  341. }
  342. return result;
  343. }
  344. }
  345. [ObjectSystem]
  346. public class AircraftXCJJAwakeSystem : AwakeSystem<AircraftXCJJ, FlightPlanEditor>
  347. {
  348. public override void Awake(AircraftXCJJ self, FlightPlanEditor flightPlanEditor)
  349. {
  350. self.FlightPlanEditor = flightPlanEditor;
  351. self.Awake();
  352. }
  353. }