Util.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System.Runtime.CompilerServices;
  2. using System.Text.Json.Nodes;
  3. using KYFramework;
  4. using KYFramework.Network;
  5. using Model;
  6. using SimulationCommon;
  7. using SimulationSingleServer.Utils;
  8. namespace SimulationServer.Utils;
  9. public class Util
  10. {
  11. public static double GetDistance(double lon1, double lon2, double lat1, double lat2)
  12. {
  13. double R = 6371; // 地球的半径(公里)
  14. double dLat = (lat2 - lat1) * Math.PI / 180.0;
  15. double dLon = (lon2 - lon1) * Math.PI / 180.0;
  16. double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
  17. Math.Cos(lat1 * Math.PI / 180.0) * Math.Cos(lat2 * Math.PI / 180.0) *
  18. Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
  19. double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
  20. double distance = R * c;
  21. return distance;
  22. }
  23. /// <summary>
  24. /// 根据 shape 解析出 经纬度
  25. /// </summary>
  26. /// <param name="shape"></param>
  27. /// <returns></returns>
  28. public static double[] Checkout(string shape)
  29. {
  30. string s = shape.Replace("POINT(", "").Replace(")", "");
  31. string[] tmps = s.Split(" ");
  32. double[] result = new double[tmps.Length];
  33. for (int i = 0; i < tmps.Length; i++)
  34. {
  35. result[i] = double.Parse(tmps[i]);
  36. }
  37. return result;
  38. }
  39. public static AircraftDB GetAircraftDefine(string aircraftType, string aircraftSubType, string aircraftID)
  40. {
  41. string content = HttpManager.Get(HttpInterface.aircraft ,new List<string>
  42. {
  43. "fType","fSubtype","fName","limit"
  44. }, new List<string>
  45. {
  46. aircraftType,aircraftSubType,aircraftID,"1"
  47. });
  48. //Log.Debug($"Type = {aircraftType}, SubType = {aircraftSubType}, ID = {aircraftID}");
  49. var define = JsonHelper.FromJson<AircraftDefine>(content);
  50. if (define.zs.Count == 0)
  51. {
  52. //Log.Debug($"没有找到对应 [{aircraftID}] 的飞机信息");
  53. return new AircraftDB();
  54. }
  55. return define.zs[0];
  56. }
  57. // 医疗
  58. public static YLDBData GetYL(string aircraftType, string aircraftSubType, string aircraftID)
  59. {
  60. string content = HttpManager.Get(HttpInterface.yl, new List<string>
  61. {
  62. "fType","fSubtype","fName","limit"
  63. }, new List<string>
  64. {
  65. aircraftType,aircraftSubType,aircraftID,"1"
  66. });
  67. var yl = JsonHelper.FromJson<YLDB>(content);
  68. var result = JsonHelper.FromJson<YLDBData>(yl.data);
  69. return result;
  70. }
  71. public static Weather GetWeather(string province_name, string city_name, string data)
  72. {
  73. string content = HttpManager.Get(HttpInterface.weather ,new List<string>
  74. {
  75. "province_name","city_name","weather_date"
  76. }, new List<string>
  77. {
  78. province_name,city_name,data
  79. });
  80. var weather = JsonHelper.FromJson<WeatherDB>(content);
  81. var result = JsonHelper.FromJson<WeatherData>(weather.data).result;
  82. return result;
  83. }
  84. public static double GetSlope(double lon, double lat, int gridCount)
  85. {
  86. string content = HttpManager.Get(HttpInterface.slope ,new List<string>
  87. {
  88. "lon","lat","gridCount"
  89. }, new List<string>
  90. {
  91. lon.ToString(),lat.ToString(),gridCount.ToString()
  92. });
  93. var slope = JsonHelper.FromJson<SlopeDb>(content);
  94. return Math.Atan(Math.Abs(slope.average.s1)) * (180.0 / Math.PI);
  95. }
  96. /// <summary>
  97. /// 获取当前位置的温度
  98. /// </summary>
  99. /// <param name="varName"></param>
  100. /// <param name="lon"></param>
  101. /// <param name="lat"></param>
  102. /// <param name="data"></param>
  103. /// <returns></returns>
  104. public static double GetTemperature(double lon, double lat)
  105. {
  106. string content = HttpManager.Get(HttpInterface.temperature ,new List<string>
  107. {
  108. "varName","centerLon","centerLat","weather_date"
  109. }, new List<string>
  110. {
  111. "t2m",lon.ToString(),lat.ToString(),"2024-01-01 12:00:00"
  112. });
  113. var temp = JsonHelper.FromJson<Temperature>(content);
  114. return temp.vale - 273;
  115. }
  116. //
  117. public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight)
  118. {
  119. string content = HttpManager.Get(HttpInterface.fuel ,new List<string>
  120. {
  121. "fname","ftype","fstate","ftemperature","fheight","fweight"
  122. }, new List<string>
  123. {
  124. fName,fType,fState,fTemperature,fHeight,fWeight
  125. });
  126. var fuel = JsonHelper.FromJson<FuelDB>(content);
  127. return fuel.data[0];
  128. }
  129. public static EntitySheetReportValue GetSheetReportValue(string name,Dictionary<string, Dictionary<string, List<string>>> report)
  130. {
  131. EntitySheetReportValue aircraftValue = new EntitySheetReportValue();
  132. aircraftValue.Name = name;
  133. //每架飞机的所有sheet
  134. foreach (var kv1 in report)
  135. {
  136. SheetReportValue sheetValue = new SheetReportValue();
  137. sheetValue.Name = kv1.Key;
  138. aircraftValue.SheetReportValueArr.Add(sheetValue);
  139. //每个sheet的所有数据
  140. foreach (var kv2 in kv1.Value)
  141. {
  142. ReportValue reportValue = new ReportValue();
  143. reportValue.Name = kv2.Key;
  144. reportValue.Value = kv2.Value.First();
  145. sheetValue.ValueArr.Add(reportValue);
  146. }
  147. }
  148. return aircraftValue;
  149. }
  150. }