ningshuxia
2022-12-01 ad494f13d2ddf31f142cf7fb908b3a6e90395a1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.AspNetCore.Http.Extensions;
using IStation.Untity;
using Furion.DynamicApiController;
using System.ComponentModel.DataAnnotations;
using Mapster;
using System.Text;
using IStation.Calculation.Epanet;
 
namespace IStation.Application
{
    /// <summary>
    /// 调度分析(标准版,简易版)
    /// </summary>
    [Route("Dispatch/ParallelConnectAnaly/Std")]
    [NonUnify]
    [ApiDescriptionSettings("Eta", Name = "并联运行分析", Order = 595)]
    public class ParallelConnect_StdController : IDynamicApiController
    {
        /// <summary>
        /// 根据扬程计算并联后的流量
        /// </summary> 
        /// <returns></returns>
        [Route("CalcFlowByHead@V1.0")]
        [HttpGet]
        public IStation.Dto.ApiResult CalcFlowByHead(IStation.Dto.ParallelConnectCalcByHeadInput Request)
        {
            if (Request.CorpID <= 0)
            {
                return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Error, "CorpID为空");
            }
            if (Request.StationID <= 0)
            {
                return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Error, "StationID为空");
            }
            if (Request.Head <= 0)
            {
                return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Error, "Head为空");
            }
            IStation.Service.PumpCurve bllCurve = new IStation.Service.PumpCurve();
            IStation.Service.Product bllProduct = new IStation.Service.Product();
 
 
 
            List<IStation.Model.CurveExpress> curveListQH = new List<IStation.Model.CurveExpress>();
            List<IStation.Model.CurveExpress> curveListQP = new List<IStation.Model.CurveExpress>();
            double r_maxH = double.MaxValue, r_minH = double.MinValue;
            List<IStation.Dto.DispatchAna.CurveItem> ParallelCurve = new List<IStation.Dto.DispatchAna.CurveItem>();
 
            foreach (var s in Request.MachineList)
            {
                if (s == null)
                    continue;
 
                var frequence = s.Frequence;
                if (frequence < 10 || frequence > 55)
                    continue;
                var machineID = s.MachineID;
                var product = bllProduct.GetByID(Request.CorpID, machineID);
                if (product == null)
                    continue;
                var pump = bllProduct.GetChildPumpByEnginePumpID(Request.CorpID, machineID);
                if (pump == null)
                    continue;
 
                var curve_default = bllCurve.GetDefaultWorkingByPumpID(Request.CorpID, pump.ID);
                //.GetDefaultCurveByPumpID(CorpID, pumpID);
                if (curve_default == null)
                    continue;
                if (curve_default.CurveInfo == null)
                    continue;
                if (frequence > 49.5)
                {
                    var curve_qh = curve_default.CurveInfo.CurveQH;
                    curve_qh.Max = curve_qh.Max * IStation.Calculation.DispatchAna.Common.DispatchAnaGeneralHelper压力.ExtendMaxRatio;
                    curveListQH.Add(curve_qh);
 
                    var curve_qp = curve_default.CurveInfo.CurveQP;
                    curve_qp.Max = curve_qp.Max * IStation.Calculation.DispatchAna.Common.DispatchAnaGeneralHelper压力.ExtendMaxRatio;
                    curveListQP.Add(curve_qp);
                }
                else
                {
                    var ration = frequence / 50.0;
 
                    var maxCurveQH = IStation.Model.FitCurveHelper.GetFitPointsByExtend(curve_default.CurveInfo.CurveQH,
                        IStation.Calculation.DispatchAna.Common.DispatchAnaGeneralHelper压力.ExtendMaxRatio, 20);
                    var maxCurveQP = IStation.Model.FitCurveHelper.GetFitPointsByExtend(curve_default.CurveInfo.CurveQP,
                        IStation.Calculation.DispatchAna.Common.DispatchAnaGeneralHelper压力.ExtendMaxRatio, 20);
 
                    List<IStation.Model.CurvePoint> simuPointsQH = new List<IStation.Model.CurvePoint>();
                    foreach (var pt in maxCurveQH)
                    {
                        simuPointsQH.Add(new IStation.Model.CurvePoint(pt.X * ration, pt.Y * ration * ration));
                    }
 
                    List<IStation.Model.CurvePoint> simuPointsQP = new List<IStation.Model.CurvePoint>();
                    foreach (var pt in maxCurveQP)
                    {
                        simuPointsQP.Add(new IStation.Model.CurvePoint(pt.X * ration, pt.Y * ration * ration * ration));
                    }
                    curveListQH.Add(new IStation.Model.CurveExpress(simuPointsQH));
                    curveListQP.Add(new IStation.Model.CurveExpress(simuPointsQP));
                }
                double maxH, minH;
                IStation.Model.FitCurveHelper.GetMinMaxPointY(curveListQH.Last(), out maxH, out minH);
                r_maxH = Math.Min(r_maxH, maxH);
                r_minH = Math.Max(r_minH, minH);
            }
 
            if (curveListQH.Count < 1)
            {
                return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Alert, "不适合并联1");
            }
 
 
            if (r_maxH < r_minH)
            {
                return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Alert, "不适合并联2");
            }
 
            double space_h = (r_maxH - r_minH) / 19;
            List<IStation.Model.CurvePoint> conne_curve_qp = new List<IStation.Model.CurvePoint>();
            List<IStation.Model.CurvePoint> conne_curve_qh = new List<IStation.Model.CurvePoint>();
            for (var h = r_minH; h <= r_maxH; h = h + space_h)
            {
                double total_flow = 0;
                double total_power = 0;
 
                for (int j = 0; j < curveListQH.Count; j++)
                {
                    var curveQH = curveListQH[j];
                    var curveQP = curveListQP[j];
                    var pts = IStation.Model.FitCurveHelper.GetInterPointX(curveQH, h);
                    if (pts != null && pts.Count > 0)
                    {
                        var q = pts.Last().X;
                        total_flow += q;
                        total_power += IStation.Model.FitCurveHelper.GetFitPointY(curveQP, q);
                    }
                }
                conne_curve_qh.Add(new IStation.Model.CurvePoint(total_flow, h));
                conne_curve_qp.Add(new IStation.Model.CurvePoint(total_flow, total_power));
            }
 
 
            var sectPointQHs = IStation.Model.FitCurveHelper.GetInterPointX(conne_curve_qh, Request.Head);
            if (sectPointQHs == null || sectPointQHs.Count == 0)
            {
                return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Alert, "不适合并联3");
            }
            var sect_q = sectPointQHs.Last().X;
 
            return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Success, String.Format("流量为:{0}", Math.Round(sect_q, 1)));
 
        }
 
 
        /// <summary>
        /// Epanet测试
        /// </summary> 
        /// <returns></returns>
        [Route("EpanetDebug@V1.0")]
        [HttpGet]
        public IStation.Dto.ApiResult EpanetDebug()
        {
            var str = new StringBuilder();
            try
            {
                //方法1
                //var item = new EpanetMethod1ContextItem();
                //item.Level = 2.697;
                //item.Flow1 = 3011;
                //item.Flow2 = 6;
                //item.Hz1 = 33;
                //item.Hz2 = 0;
                //item.Hz3 = 0;
                //item.Hz4 = 32;
 
 
                //var helper = new CalcCxd2();
                //var list = helper.CalcuPressByLevelAndFlow(item);
                //var json = JsonHelper.Object2Json(list);
                //str.AppendLine(json);
 
                //方法2 
                //var item = new EpanetMethod2ContextItem();
                //item.Level = 2.697;
                //item.Press1 = IStation.Formula.CalcuHelper.Mpa2M(0.1124);
                //item.Press2 = IStation.Formula.CalcuHelper.Mpa2M(0.1199);
                //item.Hz1 = 33;
                //item.Hz2 = 0;
                //item.Hz3 = 0;
                //item.Hz4 = 32;
 
 
                //var helper = new CalcCxd();
                //var list = helper.CalcuFlowByPressAndPumpStatus(item);
                //var json = JsonHelper.Object2Json(list);
                //str.AppendLine(json);
 
                //方法3
                var item = new EpanetMethod3ContextItem();
                item.Level = 2.558;
                item.Flow1 = 2573;
                item.Flow2 = 0;
                item.Press1 = 2.929;
                item.Press2 = 0;
                item.RunStatus2 = false;
                item.RunStatus3 = false;
 
 
                var helper = new CalcCxd2();
                var list = helper.CalcuPumpStatusByFlowAndPress(item);
                var json = JsonHelper.Object2Json(list);
                str.AppendLine(json);
            }
            catch (Exception e)
            {
                str.AppendLine("输入错误" + e.ToString());
            }
            return new IStation.Dto.ApiResult(IStation.Dto.ApiResultCode.Success, str.ToString());
 
        }
    }
}