123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using System.Runtime.CompilerServices;
- using System.Text.Json.Nodes;
- using KYFramework;
- using KYFramework.Network;
- using Model;
- using SimulationCommon;
- using SimulationSingleServer.Utils;
- namespace SimulationServer.Utils;
- public class Util
- {
- public static double GetDistance(double lon1, double lon2, double lat1, double lat2)
- {
- double R = 6371; // 地球的半径(公里)
- double dLat = (lat2 - lat1) * Math.PI / 180.0;
- double dLon = (lon2 - lon1) * Math.PI / 180.0;
- double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
- Math.Cos(lat1 * Math.PI / 180.0) * Math.Cos(lat2 * Math.PI / 180.0) *
- Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
- double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
- double distance = R * c;
- return distance;
- }
- /// <summary>
- /// 根据 shape 解析出 经纬度
- /// </summary>
- /// <param name="shape"></param>
- /// <returns></returns>
- public static double[] Checkout(string shape)
- {
- string s = shape.Replace("POINT(", "").Replace(")", "");
- string[] tmps = s.Split(" ");
- double[] result = new double[tmps.Length];
- for (int i = 0; i < tmps.Length; i++)
- {
- result[i] = double.Parse(tmps[i]);
- }
- return result;
- }
- public static AircraftDB GetAircraftDefine(string aircraftType, string aircraftSubType, string aircraftID)
- {
- string content = HttpManager.Get(HttpInterface.aircraft, new List<string>
- {
- "fType","fSubtype","fName","limit"
- }, new List<string>
- {
- aircraftType,aircraftSubType,aircraftID,"1"
- });
- //Log.Debug($"Type = {aircraftType}, SubType = {aircraftSubType}, ID = {aircraftID}");
- var define = JsonHelper.FromJson<AircraftDefine>(content);
- if (define.zs.Count == 0)
- {
- //Log.Debug($"没有找到对应 [{aircraftID}] 的飞机信息");
- return new AircraftDB();
- }
- return define.zs[0];
- }
- // 医疗
- public static string GetYL(string id)
- {
- string content = HttpManager.Get(HttpInterface.yl, new List<string>
- {
- "fSubtypeId","recordId" // "fScene","fName","fSubtypeId","limit"
- }, new List<string>
- {
- "136",id //"航空医疗","","136","10"
- });
- //Console.WriteLine("YL:" + content);
- var yl = JsonHelper.FromJson<YLDB>(content);
- string result = string.Empty;
- for (int i = 0; i < yl.data.Length; i++)
- {
- //Console.WriteLine(yl.data[i].fValue);
- result += yl.data[i].fValue;
- if (i != yl.data.Length - 1)
- result += "-";
- }
- return result;
- }
- public static Weather GetWeather(string province_name, string city_name, string data)
- {
- string content = HttpManager.Get(HttpInterface.weather, new List<string>
- {
- "province_name","city_name","weather_date"
- }, new List<string>
- {
- province_name,city_name,data
- });
- var weather = JsonHelper.FromJson<WeatherDB>(content);
- var result = JsonHelper.FromJson<WeatherData>(weather.data).result;
- return result;
- }
- public static double GetSlope(double lon, double lat, int gridCount)
- {
- string content = HttpManager.Get(HttpInterface.slope, new List<string>
- {
- "lon","lat","gridCount"
- }, new List<string>
- {
- lon.ToString(),lat.ToString(),gridCount.ToString()
- });
- var slope = JsonHelper.FromJson<SlopeDb>(content);
- return Math.Atan(Math.Abs(slope.average.s1)) * (180.0 / Math.PI);
- }
- /// <summary>
- /// 获取当前位置的温度
- /// </summary>
- /// <param name="varName"></param>
- /// <param name="lon"></param>
- /// <param name="lat"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public static double GetTemperature(double lon, double lat)
- {
- string content = HttpManager.Get(HttpInterface.temperature, new List<string>
- {
- "varName","centerLon","centerLat","weather_date"
- }, new List<string>
- {
- "t2m",lon.ToString(),lat.ToString(),"2024-01-01 12:00:00"
- });
- var temp = JsonHelper.FromJson<Temperature>(content);
- return temp.vale - 273;
- }
- //
- public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight)
- {
- string content = HttpManager.Get(HttpInterface.fuel, new List<string>
- {
- "fname","ftype","fstate","ftemperature","fheight","fweight"
- }, new List<string>
- {
- fName,fType,fState,fTemperature,fHeight,fWeight
- });
- var fuel = JsonHelper.FromJson<FuelDB>(content);
- return fuel.data[0];
- }
- public static EntitySheetReportValue GetSheetReportValue(string name, Dictionary<string, Dictionary<string, List<string>>> report)
- {
- EntitySheetReportValue aircraftValue = new EntitySheetReportValue();
- aircraftValue.Name = name;
- //每架飞机的所有sheet
- foreach (var kv1 in report)
- {
- SheetReportValue sheetValue = new SheetReportValue();
- sheetValue.Name = kv1.Key;
- aircraftValue.SheetReportValueArr.Add(sheetValue);
- //每个sheet的所有数据
- foreach (var kv2 in kv1.Value)
- {
- ReportValue reportValue = new ReportValue();
- reportValue.Name = kv2.Key;
- reportValue.Value = kv2.Value.First();
- sheetValue.ValueArr.Add(reportValue);
- }
- }
- return aircraftValue;
- }
- }
|