From d3fc18fb1fe878306d16d4d6829c2ac82a385335 Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期二, 09 七月 2024 12:30:26 +0800
Subject: [PATCH] 修改预测

---
 WebApi/Controllers/PumpRunController.cs |   94 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 83 insertions(+), 11 deletions(-)

diff --git a/WebApi/Controllers/PumpRunController.cs b/WebApi/Controllers/PumpRunController.cs
index 9b3e6d2..b082193 100644
--- a/WebApi/Controllers/PumpRunController.cs
+++ b/WebApi/Controllers/PumpRunController.cs
@@ -5,6 +5,7 @@
 using IStation.ZyModel;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Security.Policy;
 using System.Threading.Tasks;
@@ -19,8 +20,6 @@
     [RoutePrefix("PumpRun")]
     public class PumpRunController : ApiController
     {
-        private bool isdebug = true;
-
         /// <summary>
         ///  鑾峰彇娉靛疄闄呰繍琛屽弬鏁�(涓�澶�)
         /// </summary>
@@ -47,7 +46,7 @@
             PumpRunParasHelper pumpRunParasHelper = new PumpRunParasHelper();
             result = Common.PumpRunParasHelper.ReadPumpRunParas(d);
             string geterroer = null;
-            if (result != null && isdebug)
+            if (result != null)
             {
                 result.Electric = Math.Round(result.Electric, 2);
                 result.Money = Math.Round(result.Money, 2);
@@ -102,7 +101,7 @@
             {
                 var PumpTotalElecty = await ZyConnectHelper.GetPumpTotalElectricity(d, d);    //鑾峰彇鏌愭鏃堕棿鐨勭敤鐢甸噺
                 var PumpState = await ZyConnectHelper.GetPumpOpenStatusBySingleDay(d);  //鑾峰彇娉电殑寮�鏈烘儏鍐�
-                var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d, d);    //鍙栨按閲�
+                var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d.AddDays(-1), d);    //鍙栨按閲�
 
                 /*        PumpHistoryDataFileHelper pumpHistoryDataFileHelper=new PumpHistoryDataFileHelper();
                         var TotalWater = pumpHistoryDataFileHelper.GetAllWaterData();
@@ -324,7 +323,7 @@
         /// <returns></returns>
         [Route("GetPumpHistoryData")]
         [HttpGet]
-        public async Task<IStation.Dto.ApiResult> GetPumpHistoryData(string startday, string endday)
+        public async Task<IStation.Dto.ApiResult> GetPumpHistoryData(string startday, string endday, string resolution)
         {
             if (startday == null || endday == null)
             {
@@ -340,15 +339,22 @@
             {
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
             }
-            var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d, d);    //鍙栨按閲�
-                                                                                            //      ReadPumpAllDayOutAccWater
-                                                                                            //       var TotalWater = PumpRunParasHelper.ReadPumpAllDayOutAccWater(d, d.AddDays(1));
+            var TotalWater = await ZyConnectHelper.GetTotalWaterByTimeRange_Out(Start, d, resolution);    //鍙栨按閲�
+            /*     var one = TotalWater
+                   .SelectMany(otdl => otdl.MonitorRecords);
+                 var two = one.GroupBy(totalDay => totalDay.Time);
+                 var three = two.Select(group =>
+                 {
+                     var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂�
+                     var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰
+                     return new { Time = time, Total = totalSumForTimePoint };
+                 });*/
             var totalSumByTimePoint = TotalWater
               .SelectMany(otdl => otdl.MonitorRecords)
-              .GroupBy(totalDay => totalDay.Time.TimeOfDay) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁�
+              .GroupBy(totalDay => totalDay.Time) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁�
               .Select(group =>
               {
-                  var time = group.First().Time.TimeOfDay; // 浠庣粍涓幏鍙栨椂闂�
+                  var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂�
                   var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰
                   return new { Time = time, Total = totalSumForTimePoint };
               });
@@ -364,9 +370,75 @@
             List<SSAData> totalOneDays = new List<SSAData>();
             foreach (var item in totalSumByTimePoint)
             {
-                totalOneDays.Add(new SSAData() { DateTime = d + item.Time, Total = (double)item.Total });
+                totalOneDays.Add(new SSAData() { DateTime = item.Time, Total = (double)item.Total });
             }
             return new IStation.Dto.ApiResult<List<SSAData>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" };
         }
+
+        /// <summary>
+        /// 鑾峰彇渚涙按寮�鏈虹姸鎬�
+        /// </summary>
+        /// <param name="startday"></param> 寮�濮嬫棩鏈�
+        /// <param name="endday"></param> 缁撴潫鏃ユ湡
+        /// <returns></returns>
+        [Route("GetPumpOpenState")]
+        [HttpGet]
+        public async Task<IStation.Dto.ApiResult> GetPumpOpenState(string startday, string endday)
+        {
+            if (startday == null || endday == null)
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
+            }
+            DateTime Start;
+            if (!DateTime.TryParse(startday, out Start))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            DateTime d;
+            if (!DateTime.TryParse(endday, out d))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            var result = await ZyConnectHelper.GetPumpOpenStatusDay(Start, d, "1h");
+            var totalSumByTimePoint = result
+            .SelectMany(otdl => otdl.MonitorRecords)
+            .GroupBy(totalDay => totalDay.Time) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁�
+            .Select(group =>
+            {
+                var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂�
+                var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰
+                return new { Time = time, Total = totalSumForTimePoint };
+            });
+            List<SSAData> totalOneDays = new List<SSAData>();
+            foreach (var item in totalSumByTimePoint)
+            {
+                totalOneDays.Add(new SSAData() { DateTime = item.Time, Total = (double)item.Total });
+            }
+            return new IStation.Dto.ApiResult<List<SSAData>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" };
+        }
+
+
+
+        [Route("GetPumpRealData")]
+        [HttpGet]
+        public async Task<IStation.Dto.ApiResult> GetPumpRealData(string startday, string endday, string resolution)
+        {
+            if (startday == null || endday == null)
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
+            }
+            DateTime Start;
+            if (!DateTime.TryParse(startday, out Start))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            DateTime d;
+            if (!DateTime.TryParse(endday, out d))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            var TotalWater = await ZyConnectHelper.GetTotalWaterByTimeRange_Out(Start, d, resolution);    //鍙栨按閲�
+            return new IStation.Dto.ApiResult<List<RealScadaData>>(TotalWater) { Code = ApiResultCode.Success, Message = "Success" };
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3