DataManager.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using LitJson;
  6. using UnityEngine;
  7. using UnityEngine.Networking;
  8. using static Manager;
  9. using System.Security.Cryptography;
  10. using Random = System.Random;
  11. public class DataManager : MonoBehaviour
  12. {
  13. public static int admin=0;
  14. public static string acc="";
  15. public static string email="";
  16. public static string token="";
  17. public static DataManager Instance;
  18. private void Awake()
  19. {
  20. Instance = this;
  21. // StartCoroutine(wx_demo("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx9a280bbd81c64f56&secret=aeb6e5818800f8196fcac007e992dae0"));
  22. }
  23. public IEnumerator SetdonghuanSetting(int a,int b,int c,Action<string> callback)
  24. {
  25. JsonData d = new JsonData();
  26. d["current_data_source"] = a;
  27. d["backup_data_switch_type"] = b;
  28. d["data_recover_type"] = c;
  29. yield return StartCoroutine(Post_Demo("/admin/donghuanSetting", d.ToJson(), (string msg) => {
  30. callback.Invoke(msg);
  31. }));
  32. }
  33. public IEnumerator SetzongjiSetting(int a,int b,int c,Action<string> callback)
  34. {
  35. JsonData d = new JsonData();
  36. d["current_data_source"] = a;
  37. d["backup_data_switch_type"] = b;
  38. d["data_recover_type"] = c;
  39. yield return StartCoroutine(Post_Demo("/admin/zongjiSetting", d.ToJson(), (string msg) => {
  40. callback.Invoke(msg);
  41. }));
  42. }
  43. public IEnumerator SetyunnengSetting(int a,int b,int c,Action<string> callback)
  44. {
  45. JsonData d = new JsonData();
  46. d["current_data_source"] = a;
  47. d["backup_data_switch_type"] = b;
  48. d["data_recover_type"] = c;
  49. yield return StartCoroutine(Post_Demo("/admin/yunnengSetting", d.ToJson(), (string msg) => {
  50. callback.Invoke(msg);
  51. }));
  52. }
  53. public IEnumerator SetgeneralSetting(bool b,Action<string> callback)
  54. {
  55. JsonData d = new JsonData();
  56. d["update_time_display_switch"] = b;
  57. yield return StartCoroutine(Post_Demo("/admin/generalSetting", d.ToJson(), (string msg) => {
  58. callback.Invoke(msg);
  59. }));
  60. }
  61. public IEnumerator GetUserList(Action<string> callback)
  62. {
  63. yield return StartCoroutine(Get_Demo("/admin/userList", "", (string msg) => {
  64. callback.Invoke(msg);
  65. }));
  66. }
  67. public IEnumerator GetRePort(JsonData data,Action<string> callback)
  68. {
  69. yield return StartCoroutine(Post_Demo("/admin/queryOperateLog", data.ToJson(), (string msg) => {
  70. callback.Invoke(msg);
  71. }));
  72. }
  73. // ButtonSpawnFruit
  74. // Token: 0x0600000B RID: 11 RVA: 0x00002170 File Offset: 0x00000370
  75. public static string Sha1(string str)
  76. {
  77. byte[] bytes = Encoding.UTF8.GetBytes(str);
  78. byte[] array = SHA1.Create().ComputeHash(bytes);
  79. StringBuilder stringBuilder = new StringBuilder();
  80. foreach (byte b in array)
  81. {
  82. stringBuilder.Append(b.ToString("X2"));
  83. }
  84. return stringBuilder.ToString().ToLower();
  85. }
  86. // ButtonSpawnFruit
  87. // Token: 0x0600000A RID: 10 RVA: 0x00002110 File Offset: 0x00000310
  88. public static string Md5(string str)
  89. {
  90. byte[] bytes = Encoding.UTF8.GetBytes(str);
  91. byte[] array = MD5.Create().ComputeHash(bytes);
  92. StringBuilder stringBuilder = new StringBuilder();
  93. foreach (byte b in array)
  94. {
  95. stringBuilder.Append(b.ToString("X2"));
  96. }
  97. return stringBuilder.ToString().Substring(0, 20);
  98. }
  99. private static Random random = new Random();
  100. public static string CreateNoncestr(int length) {
  101. const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  102. char[] nonceChars = new char[length];
  103. for (int i = 0; i < length; i++) {
  104. nonceChars[i] = chars[random.Next(chars.Length)];
  105. }
  106. return new String(nonceChars);
  107. }
  108. public static long GetCurrentUnixTimestampMillis()
  109. {
  110. // Unix时间戳是从1970年1月1日开始计算
  111. DateTime unixStartTime = new DateTime(1970, 1, 1);
  112. // 当前时间
  113. DateTime now = DateTime.UtcNow;
  114. // 当前时间与Unix时间戳的时间间隔
  115. TimeSpan timeSpan = now - unixStartTime;
  116. // 将时间间隔转换为毫秒数
  117. long timestamp = (long)timeSpan.TotalSeconds;
  118. return timestamp;
  119. }
  120. public IEnumerator wx_demo(string urls)
  121. {
  122. UnityWebRequest webRequest = UnityWebRequest.Get(urls);
  123. //发送请求
  124. yield return webRequest.SendWebRequest();
  125. //等待请求完成
  126. while (!webRequest.isDone)
  127. {
  128. yield return null;
  129. }
  130. if (string.IsNullOrEmpty(webRequest.error))
  131. {//Get的请求成功//Get请求的返回参数
  132. var data = webRequest.downloadHandler.text;
  133. Debug.Log(data);
  134. Debug.Log("成功");
  135. JsonData dataj = JsonMapper.ToObject(data);
  136. string nonceStr = CreateNoncestr(16); // 生成一个长度为16的随机字符串
  137. string jsapi_ticket=dataj["access_token"].ToString();
  138. long timestamp=GetCurrentUnixTimestampMillis();
  139. string url="https://mp.ghz-tech.com/yx/";
  140. //jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg&noncestr=Wm3WZYTPz0wzccnW&timestamp=1414587457&url=http://mp.weixin.qq.com?params=value
  141. Debug.Log("nonceStr==>"+nonceStr);
  142. Debug.Log("jsapi_ticket==>"+jsapi_ticket);
  143. Debug.Log("timestamp==>"+timestamp);
  144. Debug.Log("url==>"+url);
  145. string sha1Hash = Sha1("jsapi_ticket="+jsapi_ticket+"&noncestr="+nonceStr+"&timestamp="+timestamp+"&url="+url);
  146. Debug.Log("sha1Hash==>"+sha1Hash);
  147. }
  148. else
  149. {//Get的请求失败
  150. Debug.Log("失败");
  151. }
  152. }
  153. public void setPass(string oldpass, string newpass,Action<string> callback)
  154. {
  155. JsonData jdata=new JsonData();
  156. jdata["old_password"] =oldpass;
  157. jdata["new_password"] =newpass;
  158. StartCoroutine(Post_Demo("/admin/resetPassword", jdata.ToJson(), (string msg) => {
  159. callback.Invoke(msg);
  160. }));
  161. }
  162. public void setuserinfo(UserInfo info,Action<string> callback)
  163. {
  164. StartCoroutine(Post_Demo("/admin/userInfo", JsonMapper.ToJson(info), (string msg) => {
  165. callback.Invoke(msg);
  166. }));
  167. }
  168. public void getuserinfo(Action<UserInfo> callback)
  169. {
  170. StartCoroutine(Get_Demo("/admin/userInfo", "", (string msg) => {
  171. try{
  172. if (msg == null)
  173. {
  174. msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"count\":\"ext_hujiajun\",\"name\":\"胡佳骏\",\"dept\":\"\",\"notes\":\"\",\"position\":\"\"}}";
  175. }
  176. JsonData jdata = JsonMapper.ToObject(msg);
  177. if (jdata["data"] != null)
  178. {
  179. UserInfo data = JsonMapper.ToObject<UserInfo>(jdata["data"].ToJson());
  180. callback.Invoke(data);
  181. }
  182. else
  183. {
  184. msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"count\":\"ext_hujiajun\",\"name\":\"胡佳骏\",\"dept\":\"\",\"notes\":\"\",\"position\":\"\"}}";
  185. jdata = JsonMapper.ToObject(msg);
  186. UserInfo data = JsonMapper.ToObject<UserInfo>(jdata["data"].ToJson());
  187. callback.Invoke(data);
  188. }
  189. }catch
  190. {
  191. }
  192. }));
  193. }
  194. public void login(JsonData data, Action<string> callback)
  195. {
  196. StartCoroutine(Post_Demo("/admin/login", data.ToJson(), (string msg) => {
  197. callback.Invoke(msg);
  198. }));
  199. }
  200. public void createzh(JsonData data, Action<string> callback)
  201. {
  202. StartCoroutine(Post_Demo("/admin/addUser", data.ToJson(), (string msg) => {
  203. callback.Invoke(msg);
  204. }));
  205. }
  206. public void getInfo( Action<AdminsystemInfo> callback)
  207. {
  208. //
  209. StartCoroutine(Post_Demo("/admin/systemInfo", "", (string msg) => {
  210. try{
  211. if (msg == null)
  212. {
  213. msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"general_option\":{\"update_time_display_switch\":false},\"yunneng_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"通算资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"k8S集群信息\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"告警数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"监控平台数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"zongji_ption\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"智算服务器\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU功率\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"交换机数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"donghuan_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"温湿度\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"电量数据\",\"update_rate_display\":\"24h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"功率数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"视频监控\",\"update_rate_display\":\"实时监控\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":0,\"update_rate_type\":0,\"update_Rate_value\":0}]}}}";
  214. }
  215. JsonData jdata = JsonMapper.ToObject(msg);
  216. if (jdata["data"]!=null)
  217. {
  218. AdminsystemInfo data = JsonMapper.ToObject<AdminsystemInfo>(jdata["data"].ToJson());
  219. callback.Invoke(data);
  220. }
  221. else
  222. {
  223. msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"general_option\":{\"update_time_display_switch\":false},\"yunneng_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"通算资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"k8S集群信息\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"告警数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"监控平台数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"zongji_ption\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"智算服务器\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU功率\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"交换机数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"donghuan_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"温湿度\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"电量数据\",\"update_rate_display\":\"24h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"功率数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"视频监控\",\"update_rate_display\":\"实时监控\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":0,\"update_rate_type\":0,\"update_Rate_value\":0}]}}}";
  224. jdata = JsonMapper.ToObject(msg);
  225. AdminsystemInfo data = JsonMapper.ToObject<AdminsystemInfo>(jdata["data"].ToJson());
  226. callback.Invoke(data);
  227. }
  228. }
  229. catch{
  230. }
  231. }));
  232. }
  233. public void GetJiFang(Action<ServerData> callback)
  234. {
  235. ServerData sd = new ServerData();
  236. sd.serverList = new List<ServerRoomData>();
  237. for (int i = 0; i < 8; i++)
  238. {
  239. ServerRoomData srd = new ServerRoomData();
  240. srd.id = i;
  241. srd.name = i + "_机房";
  242. sd.serverList.Add(srd);
  243. }
  244. callback.Invoke(sd);
  245. }
  246. IEnumerator getUsageInfo(ServerData data, Action<LineChartData> callback, int type)
  247. {
  248. string typestr = "last_month_usage";
  249. if (type == 0)
  250. {
  251. typestr = "last_week_usage";
  252. }
  253. LineChartData data2 = new LineChartData();
  254. data2.xdata = new List<string>();
  255. data2.sdata = new List<LineChartSeriesData>();
  256. yield return StartCoroutine(Post_Demo("/detail/electricUsageInfo", "", (string msg) =>
  257. {
  258. try{
  259. JsonData datamsg = JsonMapper.ToObject(msg);
  260. for (int j = 0; j < datamsg["data"][typestr].Count; j++)
  261. {
  262. if(!data2.xdata.Contains(datamsg["data"][typestr][j]["date"].ToString()))
  263. data2.xdata.Add(datamsg["data"][typestr][j]["date"].ToString());
  264. }
  265. for (int i = 0; i < data.serverList.Count; i++)
  266. {
  267. LineChartSeriesData lc = new LineChartSeriesData();
  268. lc.name = data.serverList[i].name;
  269. lc.values = new List<float>();
  270. for (int z = 0; z < datamsg["data"][typestr].Count; z++)
  271. {
  272. if(data.serverList[i].name == datamsg["data"][typestr][z]["server_room_name"].ToString())
  273. {
  274. lc.values.Add(float.Parse(datamsg["data"][typestr][z]["usage"].ToString()));
  275. }
  276. }
  277. data2.sdata.Add(lc);
  278. }
  279. }
  280. catch{
  281. }
  282. }));
  283. callback.Invoke(data2);
  284. }
  285. public void GetDLBiao(Action<LineChartData> callback,int type)
  286. {
  287. GetWSD((data) =>
  288. {
  289. StartCoroutine(getUsageInfo(data, callback, type));
  290. });
  291. return;
  292. LineChartData data = new LineChartData();
  293. data.xdata = new List<string>();
  294. data.sdata = new List<LineChartSeriesData>();
  295. for (int i = 0; i < 20; i++)
  296. {
  297. data.xdata.Add("xdata_" + i);
  298. }
  299. for (int i = 0; i < 8; i++)
  300. {
  301. LineChartSeriesData lc = new LineChartSeriesData();
  302. lc.name = "数据_"+ i;
  303. lc.values = new List<float>();
  304. for (int j = 0; j < 20; j++)
  305. {
  306. lc.values.Add(UnityEngine.Random.Range(1, 1000));
  307. }
  308. data.sdata.Add(lc);
  309. }
  310. callback.Invoke(data);
  311. }
  312. public void GetJL(int id,Action<List<ServerJiLongData>> callback)
  313. {
  314. List<ServerJiLongData> list = new List<ServerJiLongData>();
  315. JsonData data = new JsonData();
  316. data["server_room_id"] = id;
  317. StartCoroutine(Post_Demo("/detail/rackElectricInfo", data.ToJson(), (string msg) => {
  318. try{
  319. JsonData data = JsonMapper.ToObject(msg);
  320. for (int i = 0; i < data["data"]["groups"].Count; i++)
  321. {
  322. ServerJiLongData jilong = new ServerJiLongData();
  323. jilong.id = i;
  324. jilong.name = data["data"]["groups"][i]["name"].ToString();
  325. jilong.jiguilist = new List<ServerjiguiData>();
  326. for (int z = 0; z < data["data"]["groups"][i]["racks"].Count; z++)
  327. {
  328. ServerjiguiData jg = new ServerjiguiData();
  329. jg.name = data["data"]["groups"][i]["racks"][z]["name"].ToString();
  330. jg.srz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_day_usage"].ToString());
  331. jg.syz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_month_usage"].ToString());
  332. jg.szz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_week_usage"].ToString());
  333. jg.zgl = float.Parse(data["data"]["groups"][i]["racks"][z]["power"].ToString());
  334. jilong.jiguilist.Add(jg);
  335. }
  336. list.Add(jilong);
  337. }
  338. callback.Invoke(list);
  339. }
  340. catch{
  341. }
  342. }));
  343. }
  344. public void GetDL(Action<ServerData> callback)
  345. {
  346. GetWSD((data) =>
  347. {
  348. for (int j = 0; j < data.serverList.Count; j++)
  349. {
  350. if(data.serverList[j].jilonglist==null)
  351. {
  352. data.serverList[j].jilonglist = new List<ServerJiLongData>();
  353. }
  354. }
  355. callback.Invoke(data);
  356. });
  357. return;
  358. ServerData sd = new ServerData();
  359. sd.serverList = new List<ServerRoomData>();
  360. for (int i = 0; i < 8; i++)
  361. {
  362. ServerRoomData srd = new ServerRoomData();
  363. srd.id = i;
  364. srd.name = i + "_机房";
  365. srd.zonggonglv = UnityEngine.Random.Range(30.0f, 40.0f);
  366. srd.shangridl = UnityEngine.Random.Range(30.0f, 40.0f);
  367. srd.jilonglist = new List<ServerJiLongData>();
  368. for (int j = 0; j < i; j++)
  369. {
  370. ServerJiLongData jilong = new ServerJiLongData();
  371. jilong.id = j;
  372. jilong.name = i + "_" + j;
  373. jilong.jiguilist = new List<ServerjiguiData>();
  374. int rand = UnityEngine.Random.Range(2,4)>2?4:2;
  375. for (int z = 0; z < rand; z++)
  376. {
  377. ServerjiguiData jg = new ServerjiguiData();
  378. jg.name = i + "_" + j + "_" + z;
  379. jg.srz = 123;
  380. jg.syz = 123;
  381. jg.szz = 123;
  382. jg.zgl = 123;
  383. jilong.jiguilist.Add(jg);
  384. }
  385. srd.jilonglist.Add(jilong);
  386. }
  387. sd.serverList.Add(srd);
  388. }
  389. callback.Invoke(sd);
  390. }
  391. public static string ip = "";
  392. public IEnumerator Post_Demo(string url,string lstformData,Action<string> callback)
  393. {
  394. Debug.Log("开始请求" + url + "_" + lstformData);
  395. while (ip=="")
  396. {
  397. Debug.Log("ip未设置" + ip + "_" + lstformData);
  398. yield return null;
  399. }
  400. string m_url = ip + url;
  401. Debug.Log("请求地址" + m_url + "_" + lstformData);
  402. var request = new UnityWebRequest(m_url, "POST");
  403. byte[] bodyRaw = Encoding.UTF8.GetBytes(lstformData);
  404. request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
  405. request.SetRequestHeader("Content-Type", "application/json");
  406. DownloadHandler downloadHandler = new DownloadHandlerBuffer();
  407. request.downloadHandler = downloadHandler;
  408. if (DataManager.token!="")
  409. request.SetRequestHeader("AUTHORIZATION", "Bearer " + DataManager.token);
  410. yield return request.SendWebRequest();
  411. if (string.IsNullOrEmpty(request.error))
  412. {//Post的请求成功 //Post请求的返回参数
  413. var data = request.downloadHandler.text;
  414. Debug.Log(m_url+"_"+ lstformData + "——成功:" + data);
  415. callback.Invoke(data);
  416. }
  417. else
  418. {//Post的请求失败
  419. Debug.Log(m_url + "失败"+ lstformData+"_"+ request.error);
  420. callback.Invoke(null);
  421. }
  422. }
  423. public IEnumerator Get_Demo(string url, string lstformData, Action<string> callback)
  424. {
  425. Debug.Log("开始请求" + url + "_" + lstformData);
  426. while (ip == "")
  427. {
  428. Debug.Log("ip未设置" + ip + "_" + lstformData);
  429. yield return null;
  430. }
  431. string m_url = ip + url;
  432. Debug.Log("请求地址" + m_url + "_" + lstformData);
  433. var request = new UnityWebRequest(m_url, "Get");
  434. byte[] bodyRaw = Encoding.UTF8.GetBytes(lstformData);
  435. request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
  436. request.SetRequestHeader("Content-Type", "application/json");
  437. DownloadHandler downloadHandler = new DownloadHandlerBuffer();
  438. request.downloadHandler = downloadHandler;
  439. if (DataManager.token != "")
  440. request.SetRequestHeader("AUTHORIZATION", "Bearer " + DataManager.token);
  441. yield return request.SendWebRequest();
  442. if (string.IsNullOrEmpty(request.error))
  443. {//Post的请求成功 //Post请求的返回参数
  444. var data = request.downloadHandler.text;
  445. Debug.Log(m_url + "_" + lstformData + "——成功:" + data);
  446. callback.Invoke(data);
  447. }
  448. else
  449. {//Post的请求失败
  450. Debug.Log(m_url + "失败" + lstformData + "_" + request.error);
  451. callback.Invoke(null);
  452. }
  453. }
  454. public void GetTwoWsdTb(int id,int rid, Action<List<LineChartData>> callback)
  455. {
  456. JsonData data = new JsonData();
  457. data["server_room_id"] = id;
  458. data["rack_id"] = rid;
  459. StartCoroutine(Post_Demo("/detail/tempHumiInfo", data.ToJson(), (string msg) =>
  460. {
  461. List<LineChartData> sjds = new List<LineChartData>();
  462. JsonData datamsg = JsonMapper.ToObject(msg);
  463. LineChartData data = new LineChartData();
  464. data.xdata = new List<string>();
  465. data.sdata = new List<LineChartSeriesData>();
  466. //24小时last_24h_temp 温度
  467. LineChartSeriesData lc = new LineChartSeriesData();
  468. lc.name = "温度";
  469. lc.values = new List<float>();
  470. for (int i = 0; i < datamsg["data"]["last_24h_temp"].Count; i++)
  471. {
  472. data.xdata.Add(datamsg["data"]["last_24h_temp"][i]["date"].ToString().Split(' ')[1]);
  473. lc.values.Add(float.Parse(datamsg["data"]["last_24h_temp"][i]["value"].ToString()));
  474. }
  475. data.sdata.Add(lc);
  476. //24小时last_24h_humi 温度
  477. LineChartSeriesData lc2 = new LineChartSeriesData();
  478. lc2.name = "湿度";
  479. lc2.values = new List<float>();
  480. for (int i = 0; i < datamsg["data"]["last_24h_humi"].Count; i++)
  481. {
  482. lc2.values.Add(float.Parse(datamsg["data"]["last_24h_humi"][i]["value"].ToString()));
  483. }
  484. data.sdata.Add(lc2);
  485. sjds.Add(data);
  486. data = new LineChartData();
  487. data.xdata = new List<string>();
  488. data.sdata = new List<LineChartSeriesData>();
  489. //24小时last_day_temp 温度
  490. lc = new LineChartSeriesData();
  491. lc.name = "温度";
  492. lc.values = new List<float>();
  493. for (int i = 0; i < datamsg["data"]["last_day_temp"].Count; i++)
  494. {
  495. data.xdata.Add(datamsg["data"]["last_day_temp"][i]["date"].ToString().Split(' ')[1]);
  496. lc.values.Add(float.Parse(datamsg["data"]["last_day_temp"][i]["value"].ToString()));
  497. }
  498. data.sdata.Add(lc);
  499. //24小时last_day_humi 温度
  500. lc2 = new LineChartSeriesData();
  501. lc2.name = "湿度";
  502. lc2.values = new List<float>();
  503. for (int i = 0; i < datamsg["data"]["last_day_humi"].Count; i++)
  504. {
  505. lc2.values.Add(float.Parse(datamsg["data"]["last_day_humi"][i]["value"].ToString()));
  506. }
  507. data.sdata.Add(lc2);
  508. sjds.Add(data);
  509. data = new LineChartData();
  510. data.xdata = new List<string>();
  511. data.sdata = new List<LineChartSeriesData>();
  512. //24小时last_weed_temp 温度
  513. lc = new LineChartSeriesData();
  514. lc.name = "温度";
  515. lc.values = new List<float>();
  516. for (int i = 0; i < datamsg["data"]["last_week_temp"].Count; i++)
  517. {
  518. data.xdata.Add(datamsg["data"]["last_week_temp"][i]["date"].ToString().Split(' ')[0]);
  519. lc.values.Add(float.Parse(datamsg["data"]["last_week_temp"][i]["value"].ToString()));
  520. }
  521. data.sdata.Add(lc);
  522. //24小时last_week_humi 温度
  523. lc2 = new LineChartSeriesData();
  524. lc2.name = "湿度";
  525. lc2.values = new List<float>();
  526. for (int i = 0; i < datamsg["data"]["last_week_humi"].Count; i++)
  527. {
  528. lc2.values.Add(float.Parse(datamsg["data"]["last_week_humi"][i]["value"].ToString()));
  529. }
  530. data.sdata.Add(lc2);
  531. sjds.Add(data); data = new LineChartData();
  532. data.xdata = new List<string>();
  533. data.sdata = new List<LineChartSeriesData>();
  534. //24小时last_weed_temp 温度
  535. lc = new LineChartSeriesData();
  536. lc.name = "温度";
  537. lc.values = new List<float>();
  538. for (int i = 0; i < datamsg["data"]["last_month_temp"].Count; i++)
  539. {
  540. data.xdata.Add(datamsg["data"]["last_month_temp"][i]["date"].ToString().Split(' ')[0]);
  541. lc.values.Add(float.Parse(datamsg["data"]["last_month_temp"][i]["value"].ToString()));
  542. }
  543. data.sdata.Add(lc);
  544. //24小时last_week_humi 温度
  545. lc2 = new LineChartSeriesData();
  546. lc2.name = "湿度";
  547. lc2.values = new List<float>();
  548. for (int i = 0; i < datamsg["data"]["last_month_humi"].Count; i++)
  549. {
  550. lc2.values.Add(float.Parse(datamsg["data"]["last_month_humi"][i]["value"].ToString()));
  551. }
  552. data.sdata.Add(lc2);
  553. sjds.Add(data);
  554. callback.Invoke(sjds);
  555. }));
  556. }
  557. public void GetTwoWsd(int id, Action<List<ServerjiguiData>> callback)
  558. {
  559. JsonData data = new JsonData();
  560. data["server_room_id"] = id;
  561. StartCoroutine(Post_Demo("/detail/rackTempHumi", data.ToJson(), (string msg) =>
  562. {
  563. List<ServerjiguiData> sjds = new List<ServerjiguiData>();
  564. JsonData data = JsonMapper.ToObject(msg);
  565. for (int i = 0; i < data["data"]["racks"].Count; i++)
  566. {
  567. ServerjiguiData sjd = new ServerjiguiData();
  568. sjd.id =int.Parse( data["data"]["racks"][i]["id"].ToString());
  569. sjd.name = data["data"]["racks"][i]["name"].ToString();
  570. sjd.shidu = float.Parse(data["data"]["racks"][i]["temp"].ToString());
  571. sjd.wendu = float.Parse(data["data"]["racks"][i]["humi"].ToString());
  572. sjds.Add(sjd);
  573. }
  574. callback.Invoke(sjds);
  575. }));
  576. }
  577. public void GetWSD(Action<ServerData> callback)
  578. {
  579. Debug.Log("获取温湿度===》");
  580. StartCoroutine(Post_Demo("/overview/serverroom","",(string msg)=> {
  581. JsonData data = JsonMapper.ToObject(msg);
  582. ServerData sd = new ServerData();
  583. sd.serverList = new List<ServerRoomData>();
  584. for (int i = 0; i < data["data"]["item_info"].Count; i++)
  585. {
  586. ServerRoomData srd = new ServerRoomData();
  587. srd.id = int.Parse(data["data"]["item_info"][i]["server_room_id"].ToString());
  588. srd.name = data["data"]["item_info"][i]["item_name"].ToString();
  589. srd.wendu = float.Parse(data["data"]["item_info"][i]["item_temp"].ToString());
  590. srd.shidu = float.Parse(data["data"]["item_info"][i]["item_humi"].ToString());
  591. try
  592. {
  593. srd.shangridl = float.Parse(data["data"]["item_info"][i]["item_lastday_usage"].ToString());
  594. srd.zonggonglv = float.Parse(data["data"]["item_info"][i]["item_total_power"].ToString());
  595. }
  596. catch
  597. {
  598. }
  599. sd.serverList.Add(srd);
  600. }
  601. callback.Invoke(sd);
  602. }));
  603. return;
  604. ServerData sd = new ServerData();
  605. sd.serverList = new List<ServerRoomData>();
  606. for (int i = 0; i < 8; i++)
  607. {
  608. ServerRoomData srd = new ServerRoomData();
  609. srd.id = i;
  610. srd.name = i + "_机房";
  611. srd.wendu = UnityEngine.Random.Range(30.0f, 40.0f);
  612. srd.shidu = UnityEngine.Random.Range(30.0f, 40.0f);
  613. srd.jilonglist = new List<ServerJiLongData>();
  614. for (int j = 0; j < i; j++)
  615. {
  616. ServerJiLongData jilong = new ServerJiLongData();
  617. jilong.id = j;
  618. jilong.name = i + "_" + j;
  619. jilong.jiguilist = new List<ServerjiguiData>();
  620. int rand = UnityEngine.Random.Range(2, 4) > 2 ? 4 : 2;
  621. for (int z = 0; z < rand; z++)
  622. {
  623. ServerjiguiData jg = new ServerjiguiData();
  624. jg.name = i + "_" + j + "_" + z;
  625. jg.wendu = 123;
  626. jg.shidu = 123;
  627. jilong.jiguilist.Add(jg);
  628. }
  629. srd.jilonglist.Add(jilong);
  630. }
  631. sd.serverList.Add(srd);
  632. }
  633. callback.Invoke(sd);
  634. }
  635. ServerRoomData checkroom(int id , List<ServerRoomData> roomdata )
  636. {
  637. for (int i = 0; i < roomdata.Count; i++)
  638. {
  639. if(roomdata[i].id == id)
  640. {
  641. return roomdata[i];
  642. }
  643. }
  644. return null;
  645. }
  646. public void GetVideo(Action<ServerData> callback)
  647. {
  648. Debug.Log("获取video===》");
  649. StartCoroutine(Post_Demo("/overview/serverLiveOverview", "", (string msg) => {
  650. JsonData data = JsonMapper.ToObject(msg);
  651. ServerData sd = new ServerData();
  652. sd.serverList = new List<ServerRoomData>();
  653. for (int i = 0; i < data["data"]["items"].Count; i++)
  654. {
  655. ServerRoomData srd = new ServerRoomData();
  656. srd.id = int.Parse(data["data"]["items"][i]["server_room_id"].ToString());
  657. srd.name = data["data"]["items"][i]["server_name"].ToString();
  658. srd.videolist = new List<ServerVideoData>();
  659. ServerVideoData svd = new ServerVideoData();
  660. svd.id = 1;
  661. svd.type = 0;
  662. svd.name = "机房摄像头";
  663. svd.url = new List<string>();
  664. srd.videolist.Add(svd);
  665. for (int j = 0; j < data["data"]["items"][i]["video_list"]["room"].Count; j++)
  666. {
  667. svd.url.Add(data["data"]["items"][i]["video_list"]["room"][j].ToString());
  668. }
  669. ServerVideoData svd2 = new ServerVideoData();
  670. svd2.id = 1;
  671. svd.type = 1;
  672. svd2.name = "机笼摄像头";
  673. svd2.url = new List<string>();
  674. srd.videolist.Add(svd2);
  675. for (int j = 0; j < data["data"]["items"][i]["video_list"]["rack"].Count; j++)
  676. {
  677. svd2.url.Add(data["data"]["items"][i]["video_list"]["rack"][j].ToString());
  678. }
  679. sd.serverList.Add(srd);
  680. }
  681. callback.Invoke(sd);
  682. }));
  683. return;
  684. ServerData sd = new ServerData();
  685. sd.serverList = new List<ServerRoomData>();
  686. for (int i = 0; i < 8; i++)
  687. {
  688. ServerRoomData srd = new ServerRoomData();
  689. srd.id = i;
  690. srd.videolist = new List<ServerVideoData>();
  691. ServerVideoData svd = new ServerVideoData();
  692. svd.id = 1;
  693. svd.name = "机房摄像头";
  694. svd.url = new List<string>();
  695. for (int j = 0; j < 8; j++)
  696. {
  697. svd.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8");
  698. }
  699. srd.videolist.Add(svd);
  700. ServerVideoData svd2 = new ServerVideoData();
  701. svd2.id = 1;
  702. svd2.name = "机笼摄像头";
  703. svd2.url = new List<string>();
  704. for (int j = 0; j < 8; j++)
  705. {
  706. svd2.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8");
  707. }
  708. srd.videolist.Add(svd2);
  709. sd.serverList.Add(srd);
  710. }
  711. callback.Invoke(sd);
  712. }
  713. public void GetTongSuan(Action<TongSuanData> callback)
  714. {
  715. StartCoroutine(Post_Demo("/overview/generalResourceOverview", "", (string msg) =>
  716. {
  717. try{
  718. JsonData data = JsonMapper.ToObject(msg)["data"];
  719. TongSuanData jdata = new TongSuanData();
  720. jdata.devct = float.Parse(data["network_device_number"].ToString());
  721. jdata.serverct = float.Parse(data["server_number"].ToString());
  722. jdata.zhiji = float.Parse(data["host_number"].ToString());
  723. callback.Invoke(jdata);
  724. }
  725. catch{
  726. }
  727. }));
  728. return;
  729. TongSuanData jdata = new TongSuanData();
  730. jdata.devct = 123;
  731. jdata.serverct = 123;
  732. jdata.zhiji = 123;
  733. callback.Invoke(jdata);
  734. }
  735. public void GetJianKongPt(Action<JianKongPtData> callback)
  736. {
  737. StartCoroutine(Post_Demo("/overview/monitor", "", (string msg) =>
  738. {
  739. JsonData data = JsonMapper.ToObject(msg)["data"];
  740. JianKongPtData jdata = new JianKongPtData();
  741. jdata.shijianct =float.Parse( data["strategy_number"].ToString()) ;
  742. jdata.zhixingct = float.Parse(data["plugin_number"].ToString());
  743. jdata.gaojingct = float.Parse(data["warn_number"].ToString());
  744. callback.Invoke(jdata);
  745. }));
  746. return;
  747. JianKongPtData jdata = new JianKongPtData();
  748. jdata.shijianct = 123;
  749. jdata.zhixingct = 123;
  750. jdata.gaojingct = 123;
  751. callback.Invoke(jdata);
  752. }
  753. public void GetSixServer(Action<List<PieChartData>> callback)
  754. {
  755. Debug.Log("6个服务器===》");
  756. StartCoroutine(Post_Demo("/overview/intelligentResourceOverview", "", (string msg) =>
  757. {
  758. JsonData data = JsonMapper.ToObject(msg);
  759. List<PieChartData> lp = new List<PieChartData>();
  760. for (int i = 0; i < 5; i++)
  761. {
  762. if(i< data["data"]["items"].Count)
  763. {
  764. PieChartData p = new PieChartData();
  765. p.title = data["data"]["items"][i]["name"].ToString();
  766. p.value = float.Parse(data["data"]["items"][i]["count"].ToString());
  767. p.items = new List<PieChartItemData>();
  768. foreach (var k in data["data"]["items"][i].Keys)
  769. {
  770. if (k != "name" && k != "count")
  771. {
  772. PieChartItemData idata1 = new PieChartItemData();
  773. idata1.name = k;
  774. idata1.value = float.Parse(data["data"]["items"][i][k].ToString().Split('%')[0]);
  775. p.items.Add(idata1);
  776. }
  777. }
  778. lp.Add(p);
  779. }
  780. else
  781. {
  782. PieChartData p = new PieChartData();
  783. p.title ="空";
  784. p.value = 0;
  785. p.items = new List<PieChartItemData>();
  786. PieChartItemData idata1 = new PieChartItemData();
  787. idata1.name = "空";
  788. idata1.value =0;
  789. p.items.Add(idata1);
  790. lp.Add(p);
  791. }
  792. }
  793. PieChartData p2 = new PieChartData();
  794. p2.title = data["data"]["flops"]["name"].ToString();
  795. p2.value = float.Parse(data["data"]["flops"]["value"].ToString().Split(' ')[0]);
  796. lp.Add(p2);
  797. callback.Invoke(lp);
  798. }));
  799. return;
  800. List<PieChartData> lp = new List<PieChartData>();
  801. for (int i = 0; i < 6; i++)
  802. {
  803. PieChartData p = new PieChartData();
  804. p.title = i.ToString();
  805. p.value = 1000000;
  806. p.items = new List<PieChartItemData>();
  807. PieChartItemData idata1 = new PieChartItemData();
  808. idata1.name = "RUN";
  809. idata1.value = 27;
  810. p.items.Add(idata1);
  811. PieChartItemData idata2 = new PieChartItemData();
  812. idata2.name = "IDLE";
  813. idata2.value = 27;
  814. p.items.Add(idata2);
  815. lp.Add(p);
  816. }
  817. callback.Invoke(lp);
  818. }
  819. public void GetK8s(Action<List<RingValueData>> callback)
  820. {
  821. Debug.Log("获取k8s===》");
  822. List<RingValueData> rvs = new List<RingValueData>();
  823. StartCoroutine(Post_Demo("/overview/kubernetsCluster", "", (string msg) =>
  824. {
  825. JsonData datamsg = JsonMapper.ToObject(msg);
  826. RingValueData d1 = new RingValueData();
  827. d1.value = datamsg["data"]["cluster_name"].ToString();
  828. RingValueData d2 = new RingValueData();
  829. d2.value = datamsg["data"]["cluster_status"].ToString();
  830. datamsg["data"]["cluster_status"].ToString();
  831. RingValueData d3 = new RingValueData();
  832. d3.value = datamsg["data"]["cluster_node_count"][0].ToString();
  833. d3.max = datamsg["data"]["cluster_node_count"][1].ToString();
  834. rvs.Add(d1);
  835. rvs.Add(d2);
  836. rvs.Add(d3);
  837. callback.Invoke(rvs);
  838. }));
  839. return;
  840. }
  841. public void GetGPUData(Action<LineChartData> callback)
  842. {
  843. Debug.Log("获取gpu===》");
  844. StartCoroutine(Post_Demo("/overview/gpupower", "", (string msg) => {
  845. JsonData datamsg = JsonMapper.ToObject(msg);
  846. LineChartData data = new LineChartData();
  847. data.xdata = new List<string>();
  848. data.sdata = new List<LineChartSeriesData>();
  849. LineChartSeriesData lc = new LineChartSeriesData();
  850. lc.name = "今日";
  851. lc.values = new List<float>();
  852. for (int i = 0; i < datamsg["data"][ "today_info"].Count; i++)
  853. {
  854. data.xdata.Add(datamsg["data"]["today_info"][i]["time"].ToString().Split(' ')[1]);
  855. lc.values.Add(float.Parse(datamsg["data"]["today_info"][i]["value"].ToString()));
  856. }
  857. data.sdata.Add(lc);
  858. LineChartSeriesData lc2 = new LineChartSeriesData();
  859. lc2.name = "昨日";
  860. lc2.values = new List<float>();
  861. for (int i = 0; i < datamsg["data"]["yesterday_info"].Count; i++)
  862. {
  863. lc2.values.Add(float.Parse( datamsg["data"]["yesterday_info"][i]["value"].ToString()));
  864. }
  865. data.sdata.Add(lc2);
  866. callback.Invoke(data);
  867. }));
  868. return;
  869. LineChartData data = new LineChartData();
  870. data.xdata = new List<string>();
  871. data.sdata = new List<LineChartSeriesData>();
  872. for (int i = 0; i < 10; i++)
  873. {
  874. data.xdata.Add("xdata_" + i);
  875. }
  876. LineChartSeriesData lc = new LineChartSeriesData();
  877. lc.name = "数据1";
  878. lc.values = new List<float>();
  879. for (int i = 0; i < 10; i++)
  880. {
  881. lc.values.Add(UnityEngine.Random.Range(1, 800));
  882. }
  883. data.sdata.Add(lc);
  884. LineChartSeriesData lc2 = new LineChartSeriesData();
  885. lc2.name = "数据2";
  886. lc2.values = new List<float>();
  887. for (int i = 0; i < 10; i++)
  888. {
  889. lc2.values.Add(UnityEngine.Random.Range(1, 800));
  890. }
  891. data.sdata.Add(lc2);
  892. callback.Invoke(data);
  893. }
  894. public void GetGaoJingData(Action<LineChartData> callback)
  895. {
  896. StartCoroutine(Post_Demo("/overview/warnData", "", (string msg) =>
  897. {
  898. JsonData datamsg = JsonMapper.ToObject(msg);
  899. LineChartData data = new LineChartData();
  900. data.xdata = new List<string>();
  901. data.sdata = new List<LineChartSeriesData>();
  902. for (int i = 0; i < datamsg["data"]["prop_ame"].Count; i++)
  903. {
  904. LineChartSeriesData lc = new LineChartSeriesData();
  905. lc.name = datamsg["data"]["prop_ame"][i].ToString();
  906. lc.values = new List<float>();
  907. data.sdata.Add(lc);
  908. }
  909. try
  910. {
  911. for (int i = 0; i < datamsg["data"]["items"].Count; i++)
  912. {
  913. data.xdata.Add(datamsg["data"]["items"][i]["date"].ToString());
  914. for (int j = 0; j < data.sdata.Count; j++)
  915. {
  916. data.sdata[j].values.Add(float.Parse(datamsg["data"]["items"][i]["prop_value"][j].ToString()));
  917. }
  918. }
  919. }
  920. catch
  921. {
  922. }
  923. callback.Invoke(data);
  924. }));
  925. return;
  926. LineChartData data = new LineChartData();
  927. data.xdata = new List<string>();
  928. data.sdata = new List<LineChartSeriesData>();
  929. for (int i = 0; i < 20; i++)
  930. {
  931. data.xdata.Add("xdata_" + i);
  932. }
  933. LineChartSeriesData lc = new LineChartSeriesData();
  934. lc.name = "数据1";
  935. lc.values = new List<float>();
  936. for (int i = 0; i < 20; i++)
  937. {
  938. lc.values.Add(UnityEngine.Random.Range(1, 1000));
  939. }
  940. data.sdata.Add(lc);
  941. LineChartSeriesData lc2 = new LineChartSeriesData();
  942. lc2.name = "数据2";
  943. lc2.values = new List<float>();
  944. for (int i = 0; i < 20; i++)
  945. {
  946. lc2.values.Add(UnityEngine.Random.Range(1, 1000));
  947. }
  948. data.sdata.Add(lc2);
  949. LineChartSeriesData lc3 = new LineChartSeriesData();
  950. lc3.name = "数据3";
  951. lc3.values = new List<float>();
  952. for (int i = 0; i < 20; i++)
  953. {
  954. lc3.values.Add(UnityEngine.Random.Range(1, 1000));
  955. }
  956. data.sdata.Add(lc2);
  957. callback.Invoke(data);
  958. }
  959. public void GetGaoJingJiLuData(Action<GaoJingListData> callback)
  960. {
  961. StartCoroutine(Post_Demo("/overview/warnRecord", "", (string msg) =>
  962. {
  963. JsonData datamsg = JsonMapper.ToObject(msg);
  964. GaoJingListData gjl = new GaoJingListData();
  965. gjl.list = new List<GaoJingItemData>();
  966. try{
  967. for (int i = 0; i < datamsg["data"]["items"].Count; i++)
  968. {
  969. GaoJingItemData gjid = new GaoJingItemData();
  970. gjid.lv = datamsg["data"]["items"][i]["level"].ToString();
  971. gjid.time = datamsg["data"]["items"][i]["time"].ToString();
  972. gjid.dev = datamsg["data"]["items"][i]["device"].ToString();
  973. gjid.type = datamsg["data"]["items"][i]["status"].ToString();
  974. gjl.list.Add(gjid);
  975. }
  976. }catch{
  977. }
  978. callback.Invoke(gjl);
  979. }));
  980. return;
  981. GaoJingListData gjl = new GaoJingListData();
  982. gjl.list = new List<GaoJingItemData>();
  983. for (int i = 0; i < 2; i++)
  984. {
  985. GaoJingItemData gjid = new GaoJingItemData();
  986. gjid.lv = "一般";
  987. gjid.time = "2024-1-1 00:11";
  988. gjid.dev = "111机房";
  989. gjid.type = "已解决";
  990. gjl.list.Add(gjid);
  991. }
  992. for (int i = 0; i < 2; i++)
  993. {
  994. GaoJingItemData gjid = new GaoJingItemData();
  995. gjid.lv = "紧急";
  996. gjid.time = "2024-1-1 00:11";
  997. gjid.dev = "111机房";
  998. gjid.type = "待解决";
  999. gjl.list.Add(gjid);
  1000. }
  1001. for (int i = 0; i < 2; i++)
  1002. {
  1003. GaoJingItemData gjid = new GaoJingItemData();
  1004. gjid.lv = "严重";
  1005. gjid.time = "2024-1-1 00:11";
  1006. gjid.dev = "111机房";
  1007. gjid.type = "已解决";
  1008. gjl.list.Add(gjid);
  1009. }
  1010. callback.Invoke(gjl);
  1011. }
  1012. }