模擬開始時間、結束時間生成歷史時間生成曲線模擬資料
阿新 • • 發佈:2020-12-02
/// <summary> /// 生成模擬資料 /// </summary> /// <param name="vp">間隔時間秒</param> /// <param name="StartDate">統計的時間段</param> /// <param name="EndDate"></param> /// <returns></returns> public ResultEntity<List<NodeValueModel>> SimulationData(intvp, DateTime StartDate, DateTime EndDate) { ResultEntity<List<NodeValueModel>> resultEntiy = new ResultEntity<List<NodeValueModel>>(); List<NodeValueModel> list = new List<NodeValueModel>(); NodeValueModel model;//迴圈獲取值 byte[] ed = new byte[250]; List<ValueModel> valuelist; ValueModel obj; Random random = new Random(); model = new NodeValueModel(); model.name = "模擬資料"; model.Status = 0; valuelist = new List<ValueModel>();int n = 0; model.ValueCount = n; //值的個數 for (DateTime dt = StartDate; dt <= EndDate; dt = dt.AddSeconds(vp)) { var Node_Time = dt.ToString("yyyy-MM-dd HH:mm:ss"); obj = new ValueModel(); obj.NodeStatus = 0; obj.NodeValue = Math.Round(random.NextDouble() * (600 - 100) + 100, 2);//生成隨機資料 obj.TM = Node_Time;//時間 valuelist.Add(obj); n++; } model.ValueList = valuelist; list.Add(model); resultEntiy.Data = list; return resultEntiy; }