tangxu
2022-11-03 e50aa0608755bb4fbb2729912850b6ba4a5c75bc
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
using System;
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Calculation.DispatchAna 
{
    /// <summary>
    /// 
    /// </summary>
    public class CalculatorOptAnaBase: CalculatorBase
    {
        /// <summary>
        /// 计算最优方案
        /// </summary>
        /// <param name="complex_request_paras"></param>
        /// <param name="machine_run_status"></param>
        /// <param name="error_info"></param>
        /// <returns></returns>
        protected virtual List<Calculation.DispatchAna.Model.AnaScheme> CalcSchemes压力(
           IStation.Calculation.DispatchAna.Model.RequestParasComplex complex_request_paras,
           IStation.Calculation.DispatchAna.Model.MachineRunPara machine_run_status,
           out string error_info)
        {
            error_info = "未实例化";
            return null;
        }
 
        Dictionary<string, IStation.Calculation.DispatchAna.Model.AnaScheme> _dict = new Dictionary<string, Model.AnaScheme>();
 
        /// <summary>
        /// 计算汇总数据 :成功返回null, 失败返回错误信息
        /// </summary>
        /// <param name="Month">月份</param>
        /// <param name="HourRequests"></param>
        /// <param name="isUseCache">是否用缓存</param>
        /// <param name="daySumData"></param>
        /// <returns></returns>
        public virtual string  CalcSumData(
             int Month,
             List<Model.HourRequest> HourRequests,
             bool isUseCache,
             out IStation.Calculation.DispatchAna.Model.DaySumData daySumData)
        { 
            daySumData = new Model.DaySumData();
            daySumData.Qt = 0;
            foreach (var hourRequest in HourRequests)
            {
                var complex_request_paras = hourRequest.Request;
 
                #region 检查数据
                if (complex_request_paras.OutletPipePara == null || complex_request_paras.OutletPipePara.Count < 1)
                {
                    return string.Format("{0}月的{1}时,分析出错,原因是:{2}",
                        Month, hourRequest.Hour  , "出口管路参数有误, 请确认是否赋值, ERROR 35"); 
                }
 
                StringBuilder cacheNameBuilder = new StringBuilder();
 
                double target_flow = 0;
                bool isHaveSetPress = false;
                foreach (var pipe in complex_request_paras.OutletPipePara)
                {
                    target_flow += pipe.TargetFlow;
                    if (pipe.TargetPress > 0.01)
                    {
                        isHaveSetPress = true;
                    }
                    cacheNameBuilder.AppendFormat("Q{0}H{1}", Math.Round(pipe.TargetFlow, 0), Math.Round(pipe.TargetPress, 3));
                }
                if (target_flow < 50)
                {//检查流量
                    continue;
                }
                if (!isHaveSetPress)
                {//检查压力
                    continue;
                }
                if (complex_request_paras.InletPipePara != null)
                {
                    foreach (var wl in complex_request_paras.InletPipePara)
                    {
                        cacheNameBuilder.AppendFormat("V{0}", Math.Round(wl.Value, 0));
                    }
                } 
                #endregion
 
 
                //由于循环调取,所以以前分析数据缓存起来
                var cacheName = cacheNameBuilder.ToString();
                IStation.Calculation.DispatchAna.Model.AnaScheme opt_anaScheme;
                if (_dict.ContainsKey(cacheName))
                {
                    opt_anaScheme = _dict[cacheName];
                }
                else
                {
                    string error_info;
                    var result_anaSchemes = CalcSchemes压力(complex_request_paras, null, out error_info);
                    if (result_anaSchemes == null || result_anaSchemes.Count == 0)
                    {
                        if (string.IsNullOrEmpty(error_info))
                        {
                            return  string.Format("{0}月的{1}时,分析出错,可能是入参数据不合理,请检查",
                                                  Month, hourRequest.Hour  );
                        }
                        else
                        {
                            return string.Format("{0}月的{1}时,分析出错,原因是:{2}",
                                                   Month, hourRequest.Hour  ,
                                                   error_info);
                        }
                    }
                    opt_anaScheme = result_anaSchemes.First();
                    _dict[cacheName] = opt_anaScheme;
                }
 
 
                //汇总
                daySumData.Qt = daySumData.Qt + opt_anaScheme.TotalWrkQ;
                daySumData.Dt = daySumData.Dt + opt_anaScheme.TotalWrkP;
 
                //
                if(!string.IsNullOrEmpty(opt_anaScheme.ResultStatusInfo))
                daySumData.Info = opt_anaScheme.ResultStatusInfo;
            }
            daySumData.WP = CalculateWP(daySumData.Dt, daySumData.Qt);
            return null;
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pipes"></param>
        /// <returns></returns>
        protected static double CalcConnectPipeEta(List<IStation.Calculation.DispatchAna.Model.AnaScheme> pipes)
        {
            double eta = 0;
            double qh = 0;
            int count = 0;
            foreach (var pipe in pipes)
            {
                if (pipe == null)
                    continue;
                if (pipe.TotalWrkQ < 1 || pipe.TotalWrkH < 0.1)
                    continue;
                qh += pipe.TotalWrkQ * pipe.TotalWrkH;
                eta += pipe.TotalWrkQ * pipe.TotalWrkH * pipe.TotalWrkE;
                count++;
            }
            if (count <= 0)
                return 0;
            return Math.Round(eta / qh, 2);
        }
    }
}