DataManager.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. try{
  462. List<LineChartData> sjds = new List<LineChartData>();
  463. JsonData datamsg = JsonMapper.ToObject(msg);
  464. LineChartData data = new LineChartData();
  465. data.xdata = new List<string>();
  466. data.sdata = new List<LineChartSeriesData>();
  467. //24小时last_24h_temp 温度
  468. LineChartSeriesData lc = new LineChartSeriesData();
  469. lc.name = "温度";
  470. lc.values = new List<float>();
  471. for (int i = 0; i < datamsg["data"]["last_24h_temp"].Count; i++)
  472. {
  473. data.xdata.Add(datamsg["data"]["last_24h_temp"][i]["date"].ToString().Split(' ')[1]);
  474. lc.values.Add(float.Parse(datamsg["data"]["last_24h_temp"][i]["value"].ToString()));
  475. }
  476. data.sdata.Add(lc);
  477. //24小时last_24h_humi 温度
  478. LineChartSeriesData lc2 = new LineChartSeriesData();
  479. lc2.name = "湿度";
  480. lc2.values = new List<float>();
  481. for (int i = 0; i < datamsg["data"]["last_24h_humi"].Count; i++)
  482. {
  483. lc2.values.Add(float.Parse(datamsg["data"]["last_24h_humi"][i]["value"].ToString()));
  484. }
  485. data.sdata.Add(lc2);
  486. sjds.Add(data);
  487. data = new LineChartData();
  488. data.xdata = new List<string>();
  489. data.sdata = new List<LineChartSeriesData>();
  490. //24小时last_day_temp 温度
  491. lc = new LineChartSeriesData();
  492. lc.name = "温度";
  493. lc.values = new List<float>();
  494. for (int i = 0; i < datamsg["data"]["last_day_temp"].Count; i++)
  495. {
  496. data.xdata.Add(datamsg["data"]["last_day_temp"][i]["date"].ToString().Split(' ')[1]);
  497. lc.values.Add(float.Parse(datamsg["data"]["last_day_temp"][i]["value"].ToString()));
  498. }
  499. data.sdata.Add(lc);
  500. //24小时last_day_humi 温度
  501. lc2 = new LineChartSeriesData();
  502. lc2.name = "湿度";
  503. lc2.values = new List<float>();
  504. for (int i = 0; i < datamsg["data"]["last_day_humi"].Count; i++)
  505. {
  506. lc2.values.Add(float.Parse(datamsg["data"]["last_day_humi"][i]["value"].ToString()));
  507. }
  508. data.sdata.Add(lc2);
  509. sjds.Add(data);
  510. data = new LineChartData();
  511. data.xdata = new List<string>();
  512. data.sdata = new List<LineChartSeriesData>();
  513. //24小时last_weed_temp 温度
  514. lc = new LineChartSeriesData();
  515. lc.name = "温度";
  516. lc.values = new List<float>();
  517. for (int i = 0; i < datamsg["data"]["last_week_temp"].Count; i++)
  518. {
  519. data.xdata.Add(datamsg["data"]["last_week_temp"][i]["date"].ToString().Split(' ')[0]);
  520. lc.values.Add(float.Parse(datamsg["data"]["last_week_temp"][i]["value"].ToString()));
  521. }
  522. data.sdata.Add(lc);
  523. //24小时last_week_humi 温度
  524. lc2 = new LineChartSeriesData();
  525. lc2.name = "湿度";
  526. lc2.values = new List<float>();
  527. for (int i = 0; i < datamsg["data"]["last_week_humi"].Count; i++)
  528. {
  529. lc2.values.Add(float.Parse(datamsg["data"]["last_week_humi"][i]["value"].ToString()));
  530. }
  531. data.sdata.Add(lc2);
  532. sjds.Add(data); data = new LineChartData();
  533. data.xdata = new List<string>();
  534. data.sdata = new List<LineChartSeriesData>();
  535. //24小时last_weed_temp 温度
  536. lc = new LineChartSeriesData();
  537. lc.name = "温度";
  538. lc.values = new List<float>();
  539. for (int i = 0; i < datamsg["data"]["last_month_temp"].Count; i++)
  540. {
  541. data.xdata.Add(datamsg["data"]["last_month_temp"][i]["date"].ToString().Split(' ')[0]);
  542. lc.values.Add(float.Parse(datamsg["data"]["last_month_temp"][i]["value"].ToString()));
  543. }
  544. data.sdata.Add(lc);
  545. //24小时last_week_humi 温度
  546. lc2 = new LineChartSeriesData();
  547. lc2.name = "湿度";
  548. lc2.values = new List<float>();
  549. for (int i = 0; i < datamsg["data"]["last_month_humi"].Count; i++)
  550. {
  551. lc2.values.Add(float.Parse(datamsg["data"]["last_month_humi"][i]["value"].ToString()));
  552. }
  553. data.sdata.Add(lc2);
  554. sjds.Add(data);
  555. callback.Invoke(sjds);
  556. }
  557. catch{
  558. }
  559. }));
  560. }
  561. public void GetTwoWsd(int id, Action<List<ServerjiguiData>> callback)
  562. {
  563. JsonData data = new JsonData();
  564. data["server_room_id"] = id;
  565. StartCoroutine(Post_Demo("/detail/rackTempHumi", data.ToJson(), (string msg) =>
  566. {
  567. try{
  568. List<ServerjiguiData> sjds = new List<ServerjiguiData>();
  569. JsonData data = JsonMapper.ToObject(msg);
  570. for (int i = 0; i < data["data"]["racks"].Count; i++)
  571. {
  572. ServerjiguiData sjd = new ServerjiguiData();
  573. sjd.id =int.Parse( data["data"]["racks"][i]["id"].ToString());
  574. sjd.name = data["data"]["racks"][i]["name"].ToString();
  575. sjd.shidu = float.Parse(data["data"]["racks"][i]["temp"].ToString());
  576. sjd.wendu = float.Parse(data["data"]["racks"][i]["humi"].ToString());
  577. sjds.Add(sjd);
  578. }
  579. callback.Invoke(sjds);
  580. }
  581. catch{
  582. }
  583. }));
  584. }
  585. public void GetWSD(Action<ServerData> callback)
  586. {
  587. Debug.Log("获取温湿度===》");
  588. StartCoroutine(Post_Demo("/overview/serverroom","",(string msg)=> {
  589. try{
  590. JsonData data = JsonMapper.ToObject(msg);
  591. ServerData sd = new ServerData();
  592. sd.serverList = new List<ServerRoomData>();
  593. for (int i = 0; i < data["data"]["item_info"].Count; i++)
  594. {
  595. ServerRoomData srd = new ServerRoomData();
  596. srd.id = int.Parse(data["data"]["item_info"][i]["server_room_id"].ToString());
  597. srd.name = data["data"]["item_info"][i]["item_name"].ToString();
  598. srd.wendu = float.Parse(data["data"]["item_info"][i]["item_temp"].ToString());
  599. srd.shidu = float.Parse(data["data"]["item_info"][i]["item_humi"].ToString());
  600. try
  601. {
  602. srd.shangridl = float.Parse(data["data"]["item_info"][i]["item_lastday_usage"].ToString());
  603. srd.zonggonglv = float.Parse(data["data"]["item_info"][i]["item_total_power"].ToString());
  604. }
  605. catch
  606. {
  607. }
  608. sd.serverList.Add(srd);
  609. }
  610. callback.Invoke(sd);
  611. }
  612. catch{
  613. }
  614. }));
  615. return;
  616. ServerData sd = new ServerData();
  617. sd.serverList = new List<ServerRoomData>();
  618. for (int i = 0; i < 8; i++)
  619. {
  620. ServerRoomData srd = new ServerRoomData();
  621. srd.id = i;
  622. srd.name = i + "_机房";
  623. srd.wendu = UnityEngine.Random.Range(30.0f, 40.0f);
  624. srd.shidu = UnityEngine.Random.Range(30.0f, 40.0f);
  625. srd.jilonglist = new List<ServerJiLongData>();
  626. for (int j = 0; j < i; j++)
  627. {
  628. ServerJiLongData jilong = new ServerJiLongData();
  629. jilong.id = j;
  630. jilong.name = i + "_" + j;
  631. jilong.jiguilist = new List<ServerjiguiData>();
  632. int rand = UnityEngine.Random.Range(2, 4) > 2 ? 4 : 2;
  633. for (int z = 0; z < rand; z++)
  634. {
  635. ServerjiguiData jg = new ServerjiguiData();
  636. jg.name = i + "_" + j + "_" + z;
  637. jg.wendu = 123;
  638. jg.shidu = 123;
  639. jilong.jiguilist.Add(jg);
  640. }
  641. srd.jilonglist.Add(jilong);
  642. }
  643. sd.serverList.Add(srd);
  644. }
  645. callback.Invoke(sd);
  646. }
  647. ServerRoomData checkroom(int id , List<ServerRoomData> roomdata )
  648. {
  649. for (int i = 0; i < roomdata.Count; i++)
  650. {
  651. if(roomdata[i].id == id)
  652. {
  653. return roomdata[i];
  654. }
  655. }
  656. return null;
  657. }
  658. public void GetVideo(Action<ServerData> callback)
  659. {
  660. Debug.Log("获取video===》");
  661. StartCoroutine(Post_Demo("/overview/serverLiveOverview", "", (string msg) => {
  662. try{
  663. JsonData data = JsonMapper.ToObject(msg);
  664. ServerData sd = new ServerData();
  665. sd.serverList = new List<ServerRoomData>();
  666. for (int i = 0; i < data["data"]["items"].Count; i++)
  667. {
  668. ServerRoomData srd = new ServerRoomData();
  669. srd.id = int.Parse(data["data"]["items"][i]["server_room_id"].ToString());
  670. srd.name = data["data"]["items"][i]["server_name"].ToString();
  671. srd.videolist = new List<ServerVideoData>();
  672. ServerVideoData svd = new ServerVideoData();
  673. svd.id = 1;
  674. svd.type = 0;
  675. svd.name = "机房摄像头";
  676. svd.url = new List<string>();
  677. srd.videolist.Add(svd);
  678. for (int j = 0; j < data["data"]["items"][i]["video_list"]["room"].Count; j++)
  679. {
  680. svd.url.Add(data["data"]["items"][i]["video_list"]["room"][j].ToString());
  681. }
  682. ServerVideoData svd2 = new ServerVideoData();
  683. svd2.id = 1;
  684. svd.type = 1;
  685. svd2.name = "机笼摄像头";
  686. svd2.url = new List<string>();
  687. srd.videolist.Add(svd2);
  688. for (int j = 0; j < data["data"]["items"][i]["video_list"]["rack"].Count; j++)
  689. {
  690. svd2.url.Add(data["data"]["items"][i]["video_list"]["rack"][j].ToString());
  691. }
  692. sd.serverList.Add(srd);
  693. }
  694. callback.Invoke(sd);
  695. }
  696. catch{
  697. }
  698. }));
  699. return;
  700. ServerData sd = new ServerData();
  701. sd.serverList = new List<ServerRoomData>();
  702. for (int i = 0; i < 8; i++)
  703. {
  704. ServerRoomData srd = new ServerRoomData();
  705. srd.id = i;
  706. srd.videolist = new List<ServerVideoData>();
  707. ServerVideoData svd = new ServerVideoData();
  708. svd.id = 1;
  709. svd.name = "机房摄像头";
  710. svd.url = new List<string>();
  711. for (int j = 0; j < 8; j++)
  712. {
  713. svd.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8");
  714. }
  715. srd.videolist.Add(svd);
  716. ServerVideoData svd2 = new ServerVideoData();
  717. svd2.id = 1;
  718. svd2.name = "机笼摄像头";
  719. svd2.url = new List<string>();
  720. for (int j = 0; j < 8; j++)
  721. {
  722. svd2.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8");
  723. }
  724. srd.videolist.Add(svd2);
  725. sd.serverList.Add(srd);
  726. }
  727. callback.Invoke(sd);
  728. }
  729. public void GetTongSuan(Action<TongSuanData> callback)
  730. {
  731. StartCoroutine(Post_Demo("/overview/generalResourceOverview", "", (string msg) =>
  732. {
  733. try{
  734. JsonData data = JsonMapper.ToObject(msg)["data"];
  735. TongSuanData jdata = new TongSuanData();
  736. jdata.devct = float.Parse(data["network_device_number"].ToString());
  737. jdata.serverct = float.Parse(data["server_number"].ToString());
  738. jdata.zhiji = float.Parse(data["host_number"].ToString());
  739. callback.Invoke(jdata);
  740. }
  741. catch{
  742. }
  743. }));
  744. return;
  745. TongSuanData jdata = new TongSuanData();
  746. jdata.devct = 123;
  747. jdata.serverct = 123;
  748. jdata.zhiji = 123;
  749. callback.Invoke(jdata);
  750. }
  751. public void GetJianKongPt(Action<JianKongPtData> callback)
  752. {
  753. StartCoroutine(Post_Demo("/overview/monitor", "", (string msg) =>
  754. {
  755. JsonData data = JsonMapper.ToObject(msg)["data"];
  756. JianKongPtData jdata = new JianKongPtData();
  757. jdata.shijianct =float.Parse( data["strategy_number"].ToString()) ;
  758. jdata.zhixingct = float.Parse(data["plugin_number"].ToString());
  759. jdata.gaojingct = float.Parse(data["warn_number"].ToString());
  760. callback.Invoke(jdata);
  761. }));
  762. return;
  763. JianKongPtData jdata = new JianKongPtData();
  764. jdata.shijianct = 123;
  765. jdata.zhixingct = 123;
  766. jdata.gaojingct = 123;
  767. callback.Invoke(jdata);
  768. }
  769. public void GetSixServer(Action<List<PieChartData>> callback)
  770. {
  771. Debug.Log("6个服务器===》");
  772. StartCoroutine(Post_Demo("/overview/intelligentResourceOverview", "", (string msg) =>
  773. {
  774. try{
  775. JsonData data = JsonMapper.ToObject(msg);
  776. List<PieChartData> lp = new List<PieChartData>();
  777. for (int i = 0; i < 5; i++)
  778. {
  779. if(i< data["data"]["items"].Count)
  780. {
  781. PieChartData p = new PieChartData();
  782. p.title = data["data"]["items"][i]["name"].ToString();
  783. p.value = float.Parse(data["data"]["items"][i]["count"].ToString());
  784. p.items = new List<PieChartItemData>();
  785. foreach (var k in data["data"]["items"][i].Keys)
  786. {
  787. if (k != "name" && k != "count")
  788. {
  789. PieChartItemData idata1 = new PieChartItemData();
  790. idata1.name = k;
  791. idata1.value = float.Parse(data["data"]["items"][i][k].ToString().Split('%')[0]);
  792. p.items.Add(idata1);
  793. }
  794. }
  795. lp.Add(p);
  796. }
  797. else
  798. {
  799. PieChartData p = new PieChartData();
  800. p.title ="空";
  801. p.value = 0;
  802. p.items = new List<PieChartItemData>();
  803. PieChartItemData idata1 = new PieChartItemData();
  804. idata1.name = "空";
  805. idata1.value =0;
  806. p.items.Add(idata1);
  807. lp.Add(p);
  808. }
  809. }
  810. PieChartData p2 = new PieChartData();
  811. p2.title = data["data"]["flops"]["name"].ToString();
  812. p2.value = float.Parse(data["data"]["flops"]["value"].ToString().Split(' ')[0]);
  813. lp.Add(p2);
  814. callback.Invoke(lp);
  815. }
  816. catch{
  817. }
  818. }));
  819. return;
  820. List<PieChartData> lp = new List<PieChartData>();
  821. for (int i = 0; i < 6; i++)
  822. {
  823. PieChartData p = new PieChartData();
  824. p.title = i.ToString();
  825. p.value = 1000000;
  826. p.items = new List<PieChartItemData>();
  827. PieChartItemData idata1 = new PieChartItemData();
  828. idata1.name = "RUN";
  829. idata1.value = 27;
  830. p.items.Add(idata1);
  831. PieChartItemData idata2 = new PieChartItemData();
  832. idata2.name = "IDLE";
  833. idata2.value = 27;
  834. p.items.Add(idata2);
  835. lp.Add(p);
  836. }
  837. callback.Invoke(lp);
  838. }
  839. public void GetK8s(Action<List<RingValueData>> callback)
  840. {
  841. Debug.Log("获取k8s===》");
  842. List<RingValueData> rvs = new List<RingValueData>();
  843. StartCoroutine(Post_Demo("/overview/kubernetsCluster", "", (string msg) =>
  844. {
  845. JsonData datamsg = JsonMapper.ToObject(msg);
  846. RingValueData d1 = new RingValueData();
  847. d1.value = datamsg["data"]["cluster_name"].ToString();
  848. RingValueData d2 = new RingValueData();
  849. d2.value = datamsg["data"]["cluster_status"].ToString();
  850. datamsg["data"]["cluster_status"].ToString();
  851. RingValueData d3 = new RingValueData();
  852. d3.value = datamsg["data"]["cluster_node_count"][0].ToString();
  853. d3.max = datamsg["data"]["cluster_node_count"][1].ToString();
  854. rvs.Add(d1);
  855. rvs.Add(d2);
  856. rvs.Add(d3);
  857. callback.Invoke(rvs);
  858. }));
  859. return;
  860. }
  861. public void GetGPUData(Action<LineChartData> callback)
  862. {
  863. Debug.Log("获取gpu===》");
  864. StartCoroutine(Post_Demo("/overview/gpupower", "", (string msg) => {
  865. try{
  866. JsonData datamsg = JsonMapper.ToObject(msg);
  867. LineChartData data = new LineChartData();
  868. data.xdata = new List<string>();
  869. data.sdata = new List<LineChartSeriesData>();
  870. LineChartSeriesData lc = new LineChartSeriesData();
  871. lc.name = "今日";
  872. lc.values = new List<float>();
  873. for (int i = 0; i < datamsg["data"][ "today_info"].Count; i++)
  874. {
  875. data.xdata.Add(datamsg["data"]["today_info"][i]["time"].ToString().Split(' ')[1]);
  876. lc.values.Add(float.Parse(datamsg["data"]["today_info"][i]["value"].ToString()));
  877. }
  878. data.sdata.Add(lc);
  879. LineChartSeriesData lc2 = new LineChartSeriesData();
  880. lc2.name = "昨日";
  881. lc2.values = new List<float>();
  882. for (int i = 0; i < datamsg["data"]["yesterday_info"].Count; i++)
  883. {
  884. lc2.values.Add(float.Parse( datamsg["data"]["yesterday_info"][i]["value"].ToString()));
  885. }
  886. data.sdata.Add(lc2);
  887. callback.Invoke(data);
  888. }
  889. catch{
  890. }
  891. }));
  892. return;
  893. LineChartData data = new LineChartData();
  894. data.xdata = new List<string>();
  895. data.sdata = new List<LineChartSeriesData>();
  896. for (int i = 0; i < 10; i++)
  897. {
  898. data.xdata.Add("xdata_" + i);
  899. }
  900. LineChartSeriesData lc = new LineChartSeriesData();
  901. lc.name = "数据1";
  902. lc.values = new List<float>();
  903. for (int i = 0; i < 10; i++)
  904. {
  905. lc.values.Add(UnityEngine.Random.Range(1, 800));
  906. }
  907. data.sdata.Add(lc);
  908. LineChartSeriesData lc2 = new LineChartSeriesData();
  909. lc2.name = "数据2";
  910. lc2.values = new List<float>();
  911. for (int i = 0; i < 10; i++)
  912. {
  913. lc2.values.Add(UnityEngine.Random.Range(1, 800));
  914. }
  915. data.sdata.Add(lc2);
  916. callback.Invoke(data);
  917. }
  918. public void GetGaoJingData(Action<LineChartData> callback)
  919. {
  920. StartCoroutine(Post_Demo("/overview/warnData", "", (string msg) =>
  921. {
  922. try{
  923. JsonData datamsg = JsonMapper.ToObject(msg);
  924. LineChartData data = new LineChartData();
  925. data.xdata = new List<string>();
  926. data.sdata = new List<LineChartSeriesData>();
  927. for (int i = 0; i < datamsg["data"]["prop_ame"].Count; i++)
  928. {
  929. LineChartSeriesData lc = new LineChartSeriesData();
  930. lc.name = datamsg["data"]["prop_ame"][i].ToString();
  931. lc.values = new List<float>();
  932. data.sdata.Add(lc);
  933. }
  934. for (int i = 0; i < datamsg["data"]["items"].Count; i++)
  935. {
  936. data.xdata.Add(datamsg["data"]["items"][i]["date"].ToString());
  937. for (int j = 0; j < data.sdata.Count; j++)
  938. {
  939. data.sdata[j].values.Add(float.Parse(datamsg["data"]["items"][i]["prop_value"][j].ToString()));
  940. }
  941. }
  942. callback.Invoke(data);
  943. }
  944. catch{
  945. }
  946. }));
  947. return;
  948. LineChartData data = new LineChartData();
  949. data.xdata = new List<string>();
  950. data.sdata = new List<LineChartSeriesData>();
  951. for (int i = 0; i < 20; i++)
  952. {
  953. data.xdata.Add("xdata_" + i);
  954. }
  955. LineChartSeriesData lc = new LineChartSeriesData();
  956. lc.name = "数据1";
  957. lc.values = new List<float>();
  958. for (int i = 0; i < 20; i++)
  959. {
  960. lc.values.Add(UnityEngine.Random.Range(1, 1000));
  961. }
  962. data.sdata.Add(lc);
  963. LineChartSeriesData lc2 = new LineChartSeriesData();
  964. lc2.name = "数据2";
  965. lc2.values = new List<float>();
  966. for (int i = 0; i < 20; i++)
  967. {
  968. lc2.values.Add(UnityEngine.Random.Range(1, 1000));
  969. }
  970. data.sdata.Add(lc2);
  971. LineChartSeriesData lc3 = new LineChartSeriesData();
  972. lc3.name = "数据3";
  973. lc3.values = new List<float>();
  974. for (int i = 0; i < 20; i++)
  975. {
  976. lc3.values.Add(UnityEngine.Random.Range(1, 1000));
  977. }
  978. data.sdata.Add(lc2);
  979. callback.Invoke(data);
  980. }
  981. public void GetGaoJingJiLuData(Action<GaoJingListData> callback)
  982. {
  983. StartCoroutine(Post_Demo("/overview/warnRecord", "", (string msg) =>
  984. {
  985. try{
  986. JsonData datamsg = JsonMapper.ToObject(msg);
  987. GaoJingListData gjl = new GaoJingListData();
  988. gjl.list = new List<GaoJingItemData>();
  989. for (int i = 0; i < datamsg["data"]["items"].Count; i++)
  990. {
  991. GaoJingItemData gjid = new GaoJingItemData();
  992. gjid.lv = datamsg["data"]["items"][i]["level"].ToString();
  993. gjid.time = datamsg["data"]["items"][i]["time"].ToString();
  994. gjid.dev = datamsg["data"]["items"][i]["device"].ToString();
  995. gjid.type = datamsg["data"]["items"][i]["status"].ToString();
  996. gjl.list.Add(gjid);
  997. }
  998. callback.Invoke(gjl);
  999. }
  1000. catch{
  1001. }
  1002. }));
  1003. return;
  1004. GaoJingListData gjl = new GaoJingListData();
  1005. gjl.list = new List<GaoJingItemData>();
  1006. for (int i = 0; i < 2; i++)
  1007. {
  1008. GaoJingItemData gjid = new GaoJingItemData();
  1009. gjid.lv = "一般";
  1010. gjid.time = "2024-1-1 00:11";
  1011. gjid.dev = "111机房";
  1012. gjid.type = "已解决";
  1013. gjl.list.Add(gjid);
  1014. }
  1015. for (int i = 0; i < 2; i++)
  1016. {
  1017. GaoJingItemData gjid = new GaoJingItemData();
  1018. gjid.lv = "紧急";
  1019. gjid.time = "2024-1-1 00:11";
  1020. gjid.dev = "111机房";
  1021. gjid.type = "待解决";
  1022. gjl.list.Add(gjid);
  1023. }
  1024. for (int i = 0; i < 2; i++)
  1025. {
  1026. GaoJingItemData gjid = new GaoJingItemData();
  1027. gjid.lv = "严重";
  1028. gjid.time = "2024-1-1 00:11";
  1029. gjid.dev = "111机房";
  1030. gjid.type = "已解决";
  1031. gjl.list.Add(gjid);
  1032. }
  1033. callback.Invoke(gjl);
  1034. }
  1035. }