123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- 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<Text> 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<string> 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<string, float> dicNoise = new Dictionary<string, float>();
- dicNoise = JsonConvert.DeserializeObject<Dictionary<string, float>>(data["data"]["point"]["NOISEÖµ"].ToJson());
- List<Vector3> listNoise = new List<Vector3>();
- List<string> listTimerStr = new List<string>();
- 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<Vector3> listNoiseData = new List<Vector3>();
- 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<string> GetListTime()
- {
- List<string> listTimer = new List<string>();
- 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;
- }
- }
|