DataManager.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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. public class DataManager : MonoBehaviour
  10. {
  11. public static DataManager Instance;
  12. private void Awake()
  13. {
  14. Instance = this;
  15. }
  16. public void GetJiFang(Action<ServerData> callback)
  17. {
  18. ServerData sd = new ServerData();
  19. sd.serverList = new List<ServerRoomData>();
  20. for (int i = 0; i < 8; i++)
  21. {
  22. ServerRoomData srd = new ServerRoomData();
  23. srd.id = i;
  24. srd.name = i + "_机房";
  25. sd.serverList.Add(srd);
  26. }
  27. callback.Invoke(sd);
  28. }
  29. IEnumerator getUsageInfo(ServerData data, Action<LineChartData> callback, int type)
  30. {
  31. string typestr = "last_month_usage";
  32. if (type == 0)
  33. {
  34. typestr = "last_week_usage";
  35. }
  36. LineChartData data2 = new LineChartData();
  37. data2.xdata = new List<string>();
  38. data2.sdata = new List<LineChartSeriesData>();
  39. yield return StartCoroutine(Post_Demo("/detail/electricUsageInfo", "", (string msg) =>
  40. {
  41. JsonData datamsg = JsonMapper.ToObject(msg);
  42. for (int j = 0; j < datamsg["data"][typestr].Count; j++)
  43. {
  44. if(!data2.xdata.Contains(datamsg["data"][typestr][j]["date"].ToString()))
  45. data2.xdata.Add(datamsg["data"][typestr][j]["date"].ToString());
  46. }
  47. for (int i = 0; i < data.serverList.Count; i++)
  48. {
  49. LineChartSeriesData lc = new LineChartSeriesData();
  50. lc.name = data.serverList[i].name;
  51. lc.values = new List<float>();
  52. for (int z = 0; z < datamsg["data"][typestr].Count; z++)
  53. {
  54. if(data.serverList[i].name == datamsg["data"][typestr][z]["server_room_name"].ToString())
  55. {
  56. lc.values.Add(float.Parse(datamsg["data"][typestr][z]["usage"].ToString()));
  57. }
  58. }
  59. data2.sdata.Add(lc);
  60. }
  61. }));
  62. callback.Invoke(data2);
  63. }
  64. public void GetDLBiao(Action<LineChartData> callback,int type)
  65. {
  66. GetWSD((data) =>
  67. {
  68. StartCoroutine(getUsageInfo(data, callback, type));
  69. });
  70. return;
  71. LineChartData data = new LineChartData();
  72. data.xdata = new List<string>();
  73. data.sdata = new List<LineChartSeriesData>();
  74. for (int i = 0; i < 20; i++)
  75. {
  76. data.xdata.Add("xdata_" + i);
  77. }
  78. for (int i = 0; i < 8; i++)
  79. {
  80. LineChartSeriesData lc = new LineChartSeriesData();
  81. lc.name = "数据_"+ i;
  82. lc.values = new List<float>();
  83. for (int j = 0; j < 20; j++)
  84. {
  85. lc.values.Add(UnityEngine.Random.Range(1, 1000));
  86. }
  87. data.sdata.Add(lc);
  88. }
  89. callback.Invoke(data);
  90. }
  91. public void GetJL(int id,Action<List<ServerJiLongData>> callback)
  92. {
  93. List<ServerJiLongData> list = new List<ServerJiLongData>();
  94. JsonData data = new JsonData();
  95. data["server_room_id"] = id;
  96. StartCoroutine(Post_Demo("/detail/rackElectricInfo", data.ToJson(), (string msg) => {
  97. JsonData data = JsonMapper.ToObject(msg);
  98. for (int i = 0; i < data["data"]["groups"].Count; i++)
  99. {
  100. ServerJiLongData jilong = new ServerJiLongData();
  101. jilong.id = i;
  102. jilong.name = data["data"]["groups"][i]["name"].ToString();
  103. jilong.jiguilist = new List<ServerjiguiData>();
  104. for (int z = 0; z < data["data"]["groups"][i]["racks"].Count; z++)
  105. {
  106. ServerjiguiData jg = new ServerjiguiData();
  107. jg.name = data["data"]["groups"][i]["racks"][z]["name"].ToString();
  108. jg.srz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_day_usage"].ToString());
  109. jg.syz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_month_usage"].ToString());
  110. jg.szz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_week_usage"].ToString());
  111. jg.zgl = float.Parse(data["data"]["groups"][i]["racks"][z]["power"].ToString());
  112. jilong.jiguilist.Add(jg);
  113. }
  114. list.Add(jilong);
  115. }
  116. callback.Invoke(list);
  117. }));
  118. }
  119. public void GetDL(Action<ServerData> callback)
  120. {
  121. GetWSD((data) =>
  122. {
  123. for (int j = 0; j < data.serverList.Count; j++)
  124. {
  125. if(data.serverList[j].jilonglist==null)
  126. {
  127. data.serverList[j].jilonglist = new List<ServerJiLongData>();
  128. }
  129. }
  130. callback.Invoke(data);
  131. });
  132. return;
  133. ServerData sd = new ServerData();
  134. sd.serverList = new List<ServerRoomData>();
  135. for (int i = 0; i < 8; i++)
  136. {
  137. ServerRoomData srd = new ServerRoomData();
  138. srd.id = i;
  139. srd.name = i + "_机房";
  140. srd.zonggonglv = UnityEngine.Random.Range(30.0f, 40.0f);
  141. srd.shangridl = UnityEngine.Random.Range(30.0f, 40.0f);
  142. srd.jilonglist = new List<ServerJiLongData>();
  143. for (int j = 0; j < i; j++)
  144. {
  145. ServerJiLongData jilong = new ServerJiLongData();
  146. jilong.id = j;
  147. jilong.name = i + "_" + j;
  148. jilong.jiguilist = new List<ServerjiguiData>();
  149. int rand = UnityEngine.Random.Range(2,4)>2?4:2;
  150. for (int z = 0; z < rand; z++)
  151. {
  152. ServerjiguiData jg = new ServerjiguiData();
  153. jg.name = i + "_" + j + "_" + z;
  154. jg.srz = 123;
  155. jg.syz = 123;
  156. jg.szz = 123;
  157. jg.zgl = 123;
  158. jilong.jiguilist.Add(jg);
  159. }
  160. srd.jilonglist.Add(jilong);
  161. }
  162. sd.serverList.Add(srd);
  163. }
  164. callback.Invoke(sd);
  165. }
  166. public static string ip = "";
  167. public IEnumerator Post_Demo(string url,string lstformData,Action<string> callback)
  168. {
  169. while(ip=="")
  170. {
  171. yield return null;
  172. }
  173. string m_url = ip + url;
  174. var request = new UnityWebRequest(m_url, "POST");
  175. byte[] bodyRaw = Encoding.UTF8.GetBytes(lstformData);
  176. request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
  177. request.SetRequestHeader("Content-Type", "application/json");
  178. DownloadHandler downloadHandler = new DownloadHandlerBuffer();
  179. request.downloadHandler = downloadHandler;
  180. yield return request.SendWebRequest();
  181. if (string.IsNullOrEmpty(request.error))
  182. {//Post的请求成功 //Post请求的返回参数
  183. var data = request.downloadHandler.text;
  184. Debug.Log(m_url+"_"+ lstformData + "——成功:" + data);
  185. callback.Invoke(data);
  186. }
  187. else
  188. {//Post的请求失败
  189. Debug.Log(m_url + "失败"+ lstformData+"_"+ request.error);
  190. }
  191. }
  192. public void GetTwoWsdTb(int id,int rid, Action<List<LineChartData>> callback)
  193. {
  194. JsonData data = new JsonData();
  195. data["server_room_id"] = id;
  196. data["rack_id"] = rid;
  197. StartCoroutine(Post_Demo("/detail/tempHumiInfo", data.ToJson(), (string msg) =>
  198. {
  199. List<LineChartData> sjds = new List<LineChartData>();
  200. JsonData datamsg = JsonMapper.ToObject(msg);
  201. LineChartData data = new LineChartData();
  202. data.xdata = new List<string>();
  203. data.sdata = new List<LineChartSeriesData>();
  204. //24小时last_24h_temp 温度
  205. LineChartSeriesData lc = new LineChartSeriesData();
  206. lc.name = "温度";
  207. lc.values = new List<float>();
  208. for (int i = 0; i < datamsg["data"]["last_24h_temp"].Count; i++)
  209. {
  210. data.xdata.Add(datamsg["data"]["last_24h_temp"][i]["date"].ToString().Split(' ')[1]);
  211. lc.values.Add(float.Parse(datamsg["data"]["last_24h_temp"][i]["value"].ToString()));
  212. }
  213. data.sdata.Add(lc);
  214. //24小时last_24h_humi 温度
  215. LineChartSeriesData lc2 = new LineChartSeriesData();
  216. lc2.name = "湿度";
  217. lc2.values = new List<float>();
  218. for (int i = 0; i < datamsg["data"]["last_24h_humi"].Count; i++)
  219. {
  220. lc2.values.Add(float.Parse(datamsg["data"]["last_24h_humi"][i]["value"].ToString()));
  221. }
  222. data.sdata.Add(lc2);
  223. sjds.Add(data);
  224. data = new LineChartData();
  225. data.xdata = new List<string>();
  226. data.sdata = new List<LineChartSeriesData>();
  227. //24小时last_day_temp 温度
  228. lc = new LineChartSeriesData();
  229. lc.name = "温度";
  230. lc.values = new List<float>();
  231. for (int i = 0; i < datamsg["data"]["last_day_temp"].Count; i++)
  232. {
  233. data.xdata.Add(datamsg["data"]["last_day_temp"][i]["date"].ToString().Split(' ')[1]);
  234. lc.values.Add(float.Parse(datamsg["data"]["last_day_temp"][i]["value"].ToString()));
  235. }
  236. data.sdata.Add(lc);
  237. //24小时last_day_humi 温度
  238. lc2 = new LineChartSeriesData();
  239. lc2.name = "湿度";
  240. lc2.values = new List<float>();
  241. for (int i = 0; i < datamsg["data"]["last_day_humi"].Count; i++)
  242. {
  243. lc2.values.Add(float.Parse(datamsg["data"]["last_day_humi"][i]["value"].ToString()));
  244. }
  245. data.sdata.Add(lc2);
  246. sjds.Add(data);
  247. data = new LineChartData();
  248. data.xdata = new List<string>();
  249. data.sdata = new List<LineChartSeriesData>();
  250. //24小时last_weed_temp 温度
  251. lc = new LineChartSeriesData();
  252. lc.name = "温度";
  253. lc.values = new List<float>();
  254. for (int i = 0; i < datamsg["data"]["last_week_temp"].Count; i++)
  255. {
  256. data.xdata.Add(datamsg["data"]["last_week_temp"][i]["date"].ToString().Split(' ')[0]);
  257. lc.values.Add(float.Parse(datamsg["data"]["last_week_temp"][i]["value"].ToString()));
  258. }
  259. data.sdata.Add(lc);
  260. //24小时last_week_humi 温度
  261. lc2 = new LineChartSeriesData();
  262. lc2.name = "湿度";
  263. lc2.values = new List<float>();
  264. for (int i = 0; i < datamsg["data"]["last_week_humi"].Count; i++)
  265. {
  266. lc2.values.Add(float.Parse(datamsg["data"]["last_week_humi"][i]["value"].ToString()));
  267. }
  268. data.sdata.Add(lc2);
  269. sjds.Add(data); data = new LineChartData();
  270. data.xdata = new List<string>();
  271. data.sdata = new List<LineChartSeriesData>();
  272. //24小时last_weed_temp 温度
  273. lc = new LineChartSeriesData();
  274. lc.name = "温度";
  275. lc.values = new List<float>();
  276. for (int i = 0; i < datamsg["data"]["last_month_temp"].Count; i++)
  277. {
  278. data.xdata.Add(datamsg["data"]["last_month_temp"][i]["date"].ToString().Split(' ')[0]);
  279. lc.values.Add(float.Parse(datamsg["data"]["last_month_temp"][i]["value"].ToString()));
  280. }
  281. data.sdata.Add(lc);
  282. //24小时last_week_humi 温度
  283. lc2 = new LineChartSeriesData();
  284. lc2.name = "湿度";
  285. lc2.values = new List<float>();
  286. for (int i = 0; i < datamsg["data"]["last_month_humi"].Count; i++)
  287. {
  288. lc2.values.Add(float.Parse(datamsg["data"]["last_month_humi"][i]["value"].ToString()));
  289. }
  290. data.sdata.Add(lc2);
  291. sjds.Add(data);
  292. callback.Invoke(sjds);
  293. }));
  294. }
  295. public void GetTwoWsd(int id, Action<List<ServerjiguiData>> callback)
  296. {
  297. JsonData data = new JsonData();
  298. data["server_room_id"] = id;
  299. StartCoroutine(Post_Demo("/detail/rackTempHumi", data.ToJson(), (string msg) =>
  300. {
  301. List<ServerjiguiData> sjds = new List<ServerjiguiData>();
  302. JsonData data = JsonMapper.ToObject(msg);
  303. for (int i = 0; i < data["data"]["racks"].Count; i++)
  304. {
  305. ServerjiguiData sjd = new ServerjiguiData();
  306. sjd.id =int.Parse( data["data"]["racks"][i]["id"].ToString());
  307. sjd.name = data["data"]["racks"][i]["name"].ToString();
  308. sjd.shidu = float.Parse(data["data"]["racks"][i]["temp"].ToString());
  309. sjd.wendu = float.Parse(data["data"]["racks"][i]["humi"].ToString());
  310. sjds.Add(sjd);
  311. }
  312. callback.Invoke(sjds);
  313. }));
  314. }
  315. public void GetWSD(Action<ServerData> callback)
  316. {
  317. Debug.Log("获取温湿度===》");
  318. StartCoroutine(Post_Demo("/overview/serverroom","",(string msg)=> {
  319. JsonData data = JsonMapper.ToObject(msg);
  320. ServerData sd = new ServerData();
  321. sd.serverList = new List<ServerRoomData>();
  322. for (int i = 0; i < data["data"]["item_info"].Count; i++)
  323. {
  324. ServerRoomData srd = new ServerRoomData();
  325. srd.id = int.Parse(data["data"]["item_info"][i]["server_room_id"].ToString());
  326. srd.name = data["data"]["item_info"][i]["item_name"].ToString();
  327. srd.wendu = float.Parse(data["data"]["item_info"][i]["item_temp"].ToString());
  328. srd.shidu = float.Parse(data["data"]["item_info"][i]["item_humi"].ToString());
  329. try
  330. {
  331. srd.shangridl = float.Parse(data["data"]["item_info"][i]["item_lastday_usage"].ToString());
  332. srd.zonggonglv = float.Parse(data["data"]["item_info"][i]["item_total_power"].ToString());
  333. }
  334. catch
  335. {
  336. }
  337. sd.serverList.Add(srd);
  338. }
  339. callback.Invoke(sd);
  340. }));
  341. return;
  342. ServerData sd = new ServerData();
  343. sd.serverList = new List<ServerRoomData>();
  344. for (int i = 0; i < 8; i++)
  345. {
  346. ServerRoomData srd = new ServerRoomData();
  347. srd.id = i;
  348. srd.name = i + "_机房";
  349. srd.wendu = UnityEngine.Random.Range(30.0f, 40.0f);
  350. srd.shidu = UnityEngine.Random.Range(30.0f, 40.0f);
  351. srd.jilonglist = new List<ServerJiLongData>();
  352. for (int j = 0; j < i; j++)
  353. {
  354. ServerJiLongData jilong = new ServerJiLongData();
  355. jilong.id = j;
  356. jilong.name = i + "_" + j;
  357. jilong.jiguilist = new List<ServerjiguiData>();
  358. int rand = UnityEngine.Random.Range(2, 4) > 2 ? 4 : 2;
  359. for (int z = 0; z < rand; z++)
  360. {
  361. ServerjiguiData jg = new ServerjiguiData();
  362. jg.name = i + "_" + j + "_" + z;
  363. jg.wendu = 123;
  364. jg.shidu = 123;
  365. jilong.jiguilist.Add(jg);
  366. }
  367. srd.jilonglist.Add(jilong);
  368. }
  369. sd.serverList.Add(srd);
  370. }
  371. callback.Invoke(sd);
  372. }
  373. ServerRoomData checkroom(int id , List<ServerRoomData> roomdata )
  374. {
  375. for (int i = 0; i < roomdata.Count; i++)
  376. {
  377. if(roomdata[i].id == id)
  378. {
  379. return roomdata[i];
  380. }
  381. }
  382. return null;
  383. }
  384. public void GetVideo(Action<ServerData> callback)
  385. {
  386. Debug.Log("获取video===》");
  387. StartCoroutine(Post_Demo("/overview/serverLiveOverview", "", (string msg) => {
  388. JsonData data = JsonMapper.ToObject(msg);
  389. ServerData sd = new ServerData();
  390. sd.serverList = new List<ServerRoomData>();
  391. for (int i = 0; i < data["data"]["items"].Count; i++)
  392. {
  393. ServerRoomData srd = new ServerRoomData();
  394. srd.id = int.Parse(data["data"]["items"][i]["server_room_id"].ToString());
  395. srd.name = data["data"]["items"][i]["server_name"].ToString();
  396. srd.videolist = new List<ServerVideoData>();
  397. ServerVideoData svd = new ServerVideoData();
  398. svd.id = 1;
  399. svd.type = 0;
  400. svd.name = "机房摄像头";
  401. svd.url = new List<string>();
  402. srd.videolist.Add(svd);
  403. for (int j = 0; j < data["data"]["items"][i]["video_list"]["room"].Count; j++)
  404. {
  405. svd.url.Add(data["data"]["items"][i]["video_list"]["room"][j].ToString());
  406. }
  407. ServerVideoData svd2 = new ServerVideoData();
  408. svd2.id = 1;
  409. svd.type = 1;
  410. svd2.name = "机笼摄像头";
  411. svd2.url = new List<string>();
  412. srd.videolist.Add(svd2);
  413. for (int j = 0; j < data["data"]["items"][i]["video_list"]["rack"].Count; j++)
  414. {
  415. svd2.url.Add(data["data"]["items"][i]["video_list"]["rack"][j].ToString());
  416. }
  417. sd.serverList.Add(srd);
  418. }
  419. callback.Invoke(sd);
  420. }));
  421. return;
  422. ServerData sd = new ServerData();
  423. sd.serverList = new List<ServerRoomData>();
  424. for (int i = 0; i < 8; i++)
  425. {
  426. ServerRoomData srd = new ServerRoomData();
  427. srd.id = i;
  428. srd.videolist = new List<ServerVideoData>();
  429. ServerVideoData svd = new ServerVideoData();
  430. svd.id = 1;
  431. svd.name = "机房摄像头";
  432. svd.url = new List<string>();
  433. for (int j = 0; j < 8; j++)
  434. {
  435. svd.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8");
  436. }
  437. srd.videolist.Add(svd);
  438. ServerVideoData svd2 = new ServerVideoData();
  439. svd2.id = 1;
  440. svd2.name = "机笼摄像头";
  441. svd2.url = new List<string>();
  442. for (int j = 0; j < 8; j++)
  443. {
  444. svd2.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8");
  445. }
  446. srd.videolist.Add(svd2);
  447. sd.serverList.Add(srd);
  448. }
  449. callback.Invoke(sd);
  450. }
  451. public void GetTongSuan(Action<TongSuanData> callback)
  452. {
  453. StartCoroutine(Post_Demo("/overview/generalResourceOverview", "", (string msg) =>
  454. {
  455. JsonData data = JsonMapper.ToObject(msg)["data"];
  456. TongSuanData jdata = new TongSuanData();
  457. jdata.devct = float.Parse(data["host_number"].ToString());
  458. jdata.serverct = float.Parse(data["server_number"].ToString());
  459. jdata.zhiji = float.Parse(data["network_device_number"].ToString());
  460. callback.Invoke(jdata);
  461. }));
  462. return;
  463. TongSuanData jdata = new TongSuanData();
  464. jdata.devct = 123;
  465. jdata.serverct = 123;
  466. jdata.zhiji = 123;
  467. callback.Invoke(jdata);
  468. }
  469. public void GetJianKongPt(Action<JianKongPtData> callback)
  470. {
  471. StartCoroutine(Post_Demo("/overview/monitor", "", (string msg) =>
  472. {
  473. JsonData data = JsonMapper.ToObject(msg)["data"];
  474. JianKongPtData jdata = new JianKongPtData();
  475. jdata.shijianct =float.Parse( data["strategy_number"].ToString()) ;
  476. jdata.zhixingct = float.Parse(data["plugin_number"].ToString());
  477. jdata.gaojingct = float.Parse(data["warn_number"].ToString());
  478. callback.Invoke(jdata);
  479. }));
  480. return;
  481. JianKongPtData jdata = new JianKongPtData();
  482. jdata.shijianct = 123;
  483. jdata.zhixingct = 123;
  484. jdata.gaojingct = 123;
  485. callback.Invoke(jdata);
  486. }
  487. public void GetSixServer(Action<List<PieChartData>> callback)
  488. {
  489. Debug.Log("6个服务器===》");
  490. StartCoroutine(Post_Demo("/overview/intelligentResourceOverview", "", (string msg) =>
  491. {
  492. JsonData data = JsonMapper.ToObject(msg);
  493. List<PieChartData> lp = new List<PieChartData>();
  494. for (int i = 0; i < data["data"]["items"].Count; i++)
  495. {
  496. PieChartData p = new PieChartData();
  497. p.title = data["data"]["items"][i]["name"].ToString();
  498. p.value =float.Parse( data["data"]["items"][i]["count"].ToString());
  499. p.items = new List<PieChartItemData>();
  500. foreach(var k in data["data"]["items"][i].Keys)
  501. {
  502. if(k!="name"&&k!="count")
  503. {
  504. PieChartItemData idata1 = new PieChartItemData();
  505. idata1.name = k;
  506. idata1.value = float.Parse(data["data"]["items"][i][k].ToString().Split('%')[0]);
  507. p.items.Add(idata1);
  508. }
  509. }
  510. lp.Add(p);
  511. }
  512. PieChartData p2 = new PieChartData();
  513. p2.title = data["data"]["flops"]["name"].ToString();
  514. p2.value = float.Parse(data["data"]["flops"]["value"].ToString().Split(' ')[0]);
  515. lp.Add(p2);
  516. callback.Invoke(lp);
  517. }));
  518. return;
  519. List<PieChartData> lp = new List<PieChartData>();
  520. for (int i = 0; i < 6; i++)
  521. {
  522. PieChartData p = new PieChartData();
  523. p.title = i.ToString();
  524. p.value = 1000000;
  525. p.items = new List<PieChartItemData>();
  526. PieChartItemData idata1 = new PieChartItemData();
  527. idata1.name = "RUN";
  528. idata1.value = 27;
  529. p.items.Add(idata1);
  530. PieChartItemData idata2 = new PieChartItemData();
  531. idata2.name = "IDLE";
  532. idata2.value = 27;
  533. p.items.Add(idata2);
  534. lp.Add(p);
  535. }
  536. callback.Invoke(lp);
  537. }
  538. public void GetK8s(Action<List<RingValueData>> callback)
  539. {
  540. Debug.Log("获取k8s===》");
  541. List<RingValueData> rvs = new List<RingValueData>();
  542. StartCoroutine(Post_Demo("/overview/kubernetsCluster", "", (string msg) =>
  543. {
  544. JsonData datamsg = JsonMapper.ToObject(msg);
  545. RingValueData d1 = new RingValueData();
  546. d1.value = datamsg["data"]["cluster_name"].ToString();
  547. RingValueData d2 = new RingValueData();
  548. d2.value = datamsg["data"]["cluster_status"].ToString();
  549. datamsg["data"]["cluster_status"].ToString();
  550. RingValueData d3 = new RingValueData();
  551. d3.value = datamsg["data"]["cluster_node_count"][0].ToString();
  552. d3.max = datamsg["data"]["cluster_node_count"][1].ToString();
  553. rvs.Add(d1);
  554. rvs.Add(d2);
  555. rvs.Add(d3);
  556. callback.Invoke(rvs);
  557. }));
  558. return;
  559. }
  560. public void GetGPUData(Action<LineChartData> callback)
  561. {
  562. Debug.Log("获取gpu===》");
  563. StartCoroutine(Post_Demo("/overview/gpupower", "", (string msg) => {
  564. JsonData datamsg = JsonMapper.ToObject(msg);
  565. LineChartData data = new LineChartData();
  566. data.xdata = new List<string>();
  567. data.sdata = new List<LineChartSeriesData>();
  568. LineChartSeriesData lc = new LineChartSeriesData();
  569. lc.name = "今日";
  570. lc.values = new List<float>();
  571. for (int i = 0; i < datamsg["data"][ "today_info"].Count; i++)
  572. {
  573. data.xdata.Add(datamsg["data"]["today_info"][i]["time"].ToString().Split(' ')[1]);
  574. lc.values.Add(float.Parse(datamsg["data"]["today_info"][i]["value"].ToString()));
  575. }
  576. data.sdata.Add(lc);
  577. LineChartSeriesData lc2 = new LineChartSeriesData();
  578. lc2.name = "昨日";
  579. lc2.values = new List<float>();
  580. for (int i = 0; i < datamsg["data"]["yesterday_info"].Count; i++)
  581. {
  582. lc2.values.Add(float.Parse( datamsg["data"]["yesterday_info"][i]["value"].ToString()));
  583. }
  584. data.sdata.Add(lc2);
  585. callback.Invoke(data);
  586. }));
  587. return;
  588. LineChartData data = new LineChartData();
  589. data.xdata = new List<string>();
  590. data.sdata = new List<LineChartSeriesData>();
  591. for (int i = 0; i < 10; i++)
  592. {
  593. data.xdata.Add("xdata_" + i);
  594. }
  595. LineChartSeriesData lc = new LineChartSeriesData();
  596. lc.name = "数据1";
  597. lc.values = new List<float>();
  598. for (int i = 0; i < 10; i++)
  599. {
  600. lc.values.Add(UnityEngine.Random.Range(1, 800));
  601. }
  602. data.sdata.Add(lc);
  603. LineChartSeriesData lc2 = new LineChartSeriesData();
  604. lc2.name = "数据2";
  605. lc2.values = new List<float>();
  606. for (int i = 0; i < 10; i++)
  607. {
  608. lc2.values.Add(UnityEngine.Random.Range(1, 800));
  609. }
  610. data.sdata.Add(lc2);
  611. callback.Invoke(data);
  612. }
  613. public void GetGaoJingData(Action<LineChartData> callback)
  614. {
  615. StartCoroutine(Post_Demo("/overview/warnData", "", (string msg) =>
  616. {
  617. JsonData datamsg = JsonMapper.ToObject(msg);
  618. LineChartData data = new LineChartData();
  619. data.xdata = new List<string>();
  620. data.sdata = new List<LineChartSeriesData>();
  621. for (int i = 0; i < datamsg["data"]["prop_ame"].Count; i++)
  622. {
  623. LineChartSeriesData lc = new LineChartSeriesData();
  624. lc.name = datamsg["data"]["prop_ame"][i].ToString();
  625. lc.values = new List<float>();
  626. data.sdata.Add(lc);
  627. }
  628. for (int i = 0; i < datamsg["data"]["items"].Count; i++)
  629. {
  630. data.xdata.Add(datamsg["data"]["items"][i]["date"].ToString());
  631. for (int j = 0; j < data.sdata.Count; j++)
  632. {
  633. data.sdata[j].values.Add(float.Parse(datamsg["data"]["items"][i]["prop_value"][j].ToString()));
  634. }
  635. }
  636. callback.Invoke(data);
  637. }));
  638. return;
  639. LineChartData data = new LineChartData();
  640. data.xdata = new List<string>();
  641. data.sdata = new List<LineChartSeriesData>();
  642. for (int i = 0; i < 20; i++)
  643. {
  644. data.xdata.Add("xdata_" + i);
  645. }
  646. LineChartSeriesData lc = new LineChartSeriesData();
  647. lc.name = "数据1";
  648. lc.values = new List<float>();
  649. for (int i = 0; i < 20; i++)
  650. {
  651. lc.values.Add(UnityEngine.Random.Range(1, 1000));
  652. }
  653. data.sdata.Add(lc);
  654. LineChartSeriesData lc2 = new LineChartSeriesData();
  655. lc2.name = "数据2";
  656. lc2.values = new List<float>();
  657. for (int i = 0; i < 20; i++)
  658. {
  659. lc2.values.Add(UnityEngine.Random.Range(1, 1000));
  660. }
  661. data.sdata.Add(lc2);
  662. LineChartSeriesData lc3 = new LineChartSeriesData();
  663. lc3.name = "数据3";
  664. lc3.values = new List<float>();
  665. for (int i = 0; i < 20; i++)
  666. {
  667. lc3.values.Add(UnityEngine.Random.Range(1, 1000));
  668. }
  669. data.sdata.Add(lc2);
  670. callback.Invoke(data);
  671. }
  672. public void GetGaoJingJiLuData(Action<GaoJingListData> callback)
  673. {
  674. StartCoroutine(Post_Demo("/overview/warnRecord", "", (string msg) =>
  675. {
  676. JsonData datamsg = JsonMapper.ToObject(msg);
  677. GaoJingListData gjl = new GaoJingListData();
  678. gjl.list = new List<GaoJingItemData>();
  679. for (int i = 0; i < datamsg["data"]["items"].Count; i++)
  680. {
  681. GaoJingItemData gjid = new GaoJingItemData();
  682. gjid.lv = datamsg["data"]["items"][i]["level"].ToString();
  683. gjid.time = datamsg["data"]["items"][i]["time"].ToString();
  684. gjid.dev = datamsg["data"]["items"][i]["device"].ToString();
  685. gjid.type = datamsg["data"]["items"][i]["status"].ToString();
  686. gjl.list.Add(gjid);
  687. }
  688. callback.Invoke(gjl);
  689. }));
  690. return;
  691. GaoJingListData gjl = new GaoJingListData();
  692. gjl.list = new List<GaoJingItemData>();
  693. for (int i = 0; i < 2; i++)
  694. {
  695. GaoJingItemData gjid = new GaoJingItemData();
  696. gjid.lv = "一般";
  697. gjid.time = "2024-1-1 00:11";
  698. gjid.dev = "111机房";
  699. gjid.type = "已解决";
  700. gjl.list.Add(gjid);
  701. }
  702. for (int i = 0; i < 2; i++)
  703. {
  704. GaoJingItemData gjid = new GaoJingItemData();
  705. gjid.lv = "紧急";
  706. gjid.time = "2024-1-1 00:11";
  707. gjid.dev = "111机房";
  708. gjid.type = "待解决";
  709. gjl.list.Add(gjid);
  710. }
  711. for (int i = 0; i < 2; i++)
  712. {
  713. GaoJingItemData gjid = new GaoJingItemData();
  714. gjid.lv = "严重";
  715. gjid.time = "2024-1-1 00:11";
  716. gjid.dev = "111机房";
  717. gjid.type = "已解决";
  718. gjl.list.Add(gjid);
  719. }
  720. callback.Invoke(gjl);
  721. }
  722. }