DataManager.cs 46 KB

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