DataManager.cs 46 KB

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