AircraftXCJJ.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 AircraftXCJJ : AircraftEntity
  9. {
  10. public XCJJTask taskContent;
  11. public MissionEndPoint MissionEndPoint;
  12. public bool IsOver;
  13. public bool Success;
  14. public TaskParameter taskParameter;
  15. public GetNCData getNCData;
  16. public double resulttime;
  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. }
  30. public override void Start()
  31. {
  32. if (!isReadNC)
  33. {
  34. getNCData = new GetNCData();
  35. getNCData.initlatitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  36. getNCData.initlongitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  37. bool isSuccess3 = false;
  38. while (!isSuccess3)
  39. {
  40. isSuccess3 = getNCData.GetData();
  41. }
  42. text_ReadNC = new Text_readNC();
  43. text_ReadNC.initlatitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  44. text_ReadNC.initlongitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  45. bool isSuccess = false;
  46. while (!isSuccess)
  47. {
  48. isSuccess = text_ReadNC.GetNCData();
  49. }
  50. isReadNC = true;
  51. }
  52. int hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
  53. int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
  54. ////Console.WriteLine("hour:" + hour);
  55. //double windSpeed = Convert.ToDouble(TargetQiXiangInfoSave("风速", hour));
  56. ////Console.WriteLine("windSpeed:" + windSpeed);
  57. //double vis = Convert.ToDouble(TargetQiXiangInfoSave("能见度", hour));
  58. ////Console.WriteLine("vis:" + vis);
  59. FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  60. FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  61. FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalTargetPoint[0].TargetPointHeight;
  62. Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
  63. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  64. //// 吊运上升速度 吊运下降速度 Task文件读取 // Editor里读天气根据时间
  65. //resulttime = get_result_time_rope(taskParameter.Height, taskParameter.liftPersonnel, windSpeed, vis, taskParameter.liftUpSpeed, taskParameter.liftDownSpeed).time;//索滑降模型输出的索滑降时间
  66. //Console.WriteLine("resulttime:" + resulttime);
  67. //FXJHGenerate.SuoHuaJiang(resulttime, FlightPlanEditor, ref TurningPoints);
  68. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, FXJHGenerate.SuoHuaJiangMissionEndPoint(FlightPlanEditor), ref TurningPoints);
  69. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  70. // 飞到目标点时间与人员存活时间做对比 有一个人活着,整个任务成功
  71. double time = 0;
  72. for (int i = 0; i < TurningPoints.Count - 1; i++)
  73. {
  74. time += TurningPoints[i].SegmentFlightTime; // 判断幸存-1
  75. }
  76. //Console.WriteLine("time:" + time);
  77. int patientCount = FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; // 伤患人数
  78. List<string> diseaseTypes = new List<string>();
  79. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes.Length; i++)
  80. {
  81. diseaseTypes.Add(FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes[i]);
  82. }
  83. int medicCount = taskParameter.MedicalStaffCount; // 医护人员数量
  84. // 交接时间为5分钟
  85. double handoverTime = 5;
  86. // 计算总急救时间
  87. double totalEmergencyTime = CalculateTotalEmergencyTime(diseaseTypes);
  88. // 计算平均急救时间(每个医护人员分担的时间)
  89. double averageEmergencyTimePerMedic = totalEmergencyTime / medicCount;
  90. // 计算总时间(平均急救时间 + 交接时间)
  91. double totalTime = averageEmergencyTimePerMedic + handoverTime;
  92. Console.WriteLine($"总急救时间(平均每个医护人员): {averageEmergencyTimePerMedic} 分钟");
  93. Console.WriteLine($"总时间(包括交接时间): {totalTime} 分钟");
  94. Random rand = new Random();
  95. List<Patient> patients = new List<Patient>();
  96. for (int i = 0; i < patientCount; i++)
  97. {
  98. patients.Add(new Patient()
  99. {
  100. Id = i + 1,
  101. DiseaseType = diseaseTypes[i],
  102. GoldenHour = 0
  103. });
  104. }
  105. patients = MedicalRescue.ProcessPatients(patients, rand);
  106. // 对患者进行排序
  107. var sortedPatients = patients.OrderBy(p => DiseasePriorityService.GetPriority(p.DiseaseType))
  108. .ThenBy(p => p.GoldenHour)
  109. .ToList();
  110. // 输出排序后的患者列表 // 从是事故点到医院的飞行时间 + 5分钟的交接时间 < 黄金时间 ? 成功:失败
  111. foreach (var patient in sortedPatients)
  112. {
  113. Console.WriteLine($"sortedPatients ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {patient.GoldenHour:F2}");
  114. }
  115. // 注意:实际项目中,每次转运一名伤员的操作可能涉及更多的逻辑,比如更新数据库中的转运状态等。
  116. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  117. {
  118. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  119. }
  120. Console.WriteLine("TotalTime:" + TotalTime);
  121. IsOver = true;
  122. End();
  123. }
  124. static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
  125. {
  126. double totalTime = 0;
  127. // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
  128. foreach (var diseaseType in diseaseTypes)
  129. {
  130. double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
  131. totalTime += emergencyTime;
  132. }
  133. return totalTime;
  134. }
  135. // 模拟从数据库获取急救时间的方法
  136. static double GetEmergencyTimeFromDatabase(string diseaseType)
  137. {
  138. // 这里应该是实际的数据库查询逻辑
  139. // 但为了示例,我们直接返回一个模拟值
  140. switch (diseaseType)
  141. {
  142. case "aa": //HeartAttack
  143. return 2; // 心脏病急救时间为2分钟
  144. case "bb": //Stroke
  145. return 5; // 中风急救时间为5分钟
  146. case "cc": //Trauma
  147. return 10; // 创伤急救时间为10分钟
  148. case "dd":
  149. return 15;
  150. case "ee":
  151. return 20;
  152. default:
  153. return 0;
  154. }
  155. }
  156. // 假设从前端接收到的数据结构
  157. public class Patient
  158. {
  159. public int Id { get; set; }
  160. public string DiseaseType { get; set; }
  161. public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
  162. }
  163. public class DiseaseInfo
  164. {
  165. public string DiseaseType { get; set; }
  166. public double MinGoldenHour { get; set; }
  167. public double MaxGoldenHour { get; set; }
  168. }
  169. public class MedicalRescue
  170. {
  171. private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
  172. {
  173. { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
  174. { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
  175. { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
  176. { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
  177. { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },
  178. // 添加更多疾病类型
  179. };
  180. public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
  181. {
  182. foreach (var patient in patients)
  183. {
  184. var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
  185. double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
  186. Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
  187. patient.GoldenHour = goldenHour;
  188. }
  189. return patients;
  190. }
  191. public static DiseaseInfo GetDiseaseInfo(string diseaseType)
  192. {
  193. if (diseaseDatabase.ContainsKey(diseaseType))
  194. {
  195. return diseaseDatabase[diseaseType];
  196. }
  197. throw new ArgumentException("Unknown disease type.");
  198. }
  199. public static double GenerateRandomGoldenHour(Random rand, double min, double max)
  200. {
  201. double mu = (max + min) / 2;
  202. double sigma = (max - min) / 6;
  203. var normal = new Normal(mu, sigma);
  204. return normal.Sample();
  205. }
  206. }
  207. // 假设数据库中的疾病优先级信息
  208. public class DiseasePriority
  209. {
  210. public string DiseaseType { get; set; }
  211. public int Priority { get; set; } // 优先级,数字越小优先级越高
  212. }
  213. // 静态类,包含与疾病优先级相关的静态方法
  214. public static class DiseasePriorityService
  215. {
  216. // 数据库查询(实际项目中应该是从数据库读取)
  217. public static List<DiseasePriority> GetDiseasePriorities()
  218. {
  219. return new List<DiseasePriority>
  220. {
  221. new DiseasePriority { DiseaseType = "aa", Priority = 5 },
  222. new DiseasePriority { DiseaseType = "bb", Priority = 4 },
  223. new DiseasePriority { DiseaseType = "cc", Priority = 3 },
  224. new DiseasePriority { DiseaseType = "dd", Priority = 2 },
  225. new DiseasePriority { DiseaseType = "ee", Priority = 5 },
  226. };
  227. }
  228. // 根据疾病类型获取优先级
  229. public static int GetPriority(string diseaseType)
  230. {
  231. var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
  232. if (priorities.TryGetValue(diseaseType, out int priority))
  233. {
  234. return priority;
  235. }
  236. return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级
  237. }
  238. }
  239. // 吊运函数
  240. public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed)
  241. {
  242. handling_result result = new handling_result();
  243. if (windspeed < 8 && vis > 3)
  244. {
  245. result.time = (person_number * H) / downspeed + (person_number * H) / upspeed;
  246. result.success = true;
  247. }
  248. else
  249. {
  250. result.success = false;
  251. }
  252. return result;
  253. }
  254. public string TargetQiXiangInfoSave(string s, int hour)
  255. {
  256. string result = hour.ToString() + "-" + s;
  257. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  258. {
  259. }
  260. switch (s)
  261. {
  262. case "温度":
  263. break;
  264. case "湿度":
  265. break;
  266. case "能见度":
  267. break;
  268. case "风速":
  269. break;
  270. case "风向":
  271. break;
  272. case "天气":
  273. break;
  274. }
  275. return result;
  276. }
  277. public static int GetDaysInYear(int year, int month, int day)
  278. {
  279. int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  280. if (IsLeapYear(year))
  281. {
  282. daysInMonths[1] = 29;
  283. }
  284. int days = day;
  285. for (int i = 0; i < month - 1; i++)
  286. {
  287. days += daysInMonths[i];
  288. }
  289. return days;
  290. }
  291. public static bool IsLeapYear(int year)
  292. {
  293. return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  294. }
  295. }
  296. [ObjectSystem]
  297. public class AircraftXCJJAwakeSystem : AwakeSystem<AircraftXCJJ, FlightPlanEditor>
  298. {
  299. public override void Awake(AircraftXCJJ self, FlightPlanEditor flightPlanEditor)
  300. {
  301. self.FlightPlanEditor = flightPlanEditor;
  302. self.Awake();
  303. }
  304. }