using LitJson; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using XCharts.Runtime; public class NoiseControl : MonoBehaviour { public LineChart noiseLine; public List listTimer; private void Start() { StartCoroutine(Timer(0.3f)); } private IEnumerator Timer(float timers) { yield return new WaitForSeconds(timers); GetData(); } private IEnumerable Timer2(float timers) { yield return new WaitForSeconds(timers); GetData(); while (true) { yield return new WaitForSeconds(1800); GetData(); } } private void GetData() { List listTimerData = GetListTime(); JsonData data = new JsonData(); data["deviceClassification"] = "VOICE"; data["ago"] = 24; PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/device/getDatapoint", data.ToJson(), (msg) => { Debug.Log(msg); JsonData data = JsonMapper.ToObject(msg); if (data["code"].ToString() == "200") { Dictionary dicNoise = new Dictionary(); dicNoise = JsonConvert.DeserializeObject>(data["data"]["point"]["NOISEÖµ"].ToJson()); List listNoise = new List(); List listTimerStr = new List(); foreach (var item in dicNoise) { string[] str1 = item.Key.Split(' '); string[] str2 = str1[1].Split(':'); if (str2[1] == "00") { int timers = int.Parse(str2[0]); timers++; timers = timers % 24; string timer; if (timers < 10) { timer = "0" + timers.ToString() + ":00"; } else { timer = timers.ToString() + ":00"; } listTimerStr.Add(timer); listNoise.Add(new Vector3(0, item.Value, 0)); } } List listNoiseData = new List(); for (int i = 0; i < listTimerData.Count - 1; i++) { bool finish = false; for (int j = 0; j < listTimerStr.Count; j++) { if (listTimerData[i] == listTimerStr[j]) { finish = true; listNoiseData.Add(listNoise[i]); break; } } if (finish == false) { listNoiseData.Add(Vector3.up); } } if (listTimerData[listNoiseData.Count - 1] == listTimerStr[listTimerStr.Count - 1]) { listNoiseData.Add(listNoise[listTimerStr.Count - 1]); } else { listNoiseData.Add(Vector3.up); } for (int i = 0; i < listTimerData.Count; i++) { listTimer[i].text = listTimerData[i]; } for (int i = 0; i < listNoiseData.Count; i++) { noiseLine.UpdateData("ÔëÉù", i, listNoiseData[i].y); } } }); } private List GetListTime() { List listTimer = new List(); int hour = DateTime.Now.Hour; for (int i = 0; i < 7; i++) { int hTimer = hour - 24 + i * 4 - 1; if (hTimer < 0) hTimer = 24 + hTimer; if (hTimer < 10) { listTimer.Add("0" + hTimer.ToString() + ":00"); } else { listTimer.Add(hTimer.ToString() + ":00"); } Debug.Log(listTimer[i]); } return listTimer; } }