AircraftYLZY.cs 14 KB

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