Browse Source

功率算法接入 ps由于算法调用的是mclmcrrt9_4.dll.因此将MATLAB Runtime\v95\runtime\win64里的mclmcrrt9_5.dll改为mclmcrrt9_4.dll

wrinkle17 2 months ago
parent
commit
5e75c83371

+ 4 - 0
DPTools/Uninpho.Railway.Tools.csproj

@@ -234,6 +234,10 @@
     <Reference Include="Package_turnout_identify_wrf">
       <HintPath>libs\matlabSuanFa\Package_turnout_identify_wrf.dll</HintPath>
     </Reference>
+    <Reference Include="Sub_module_power_analysis, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>bin\Debug\Sub_module_power_analysis.dll</HintPath>
+    </Reference>
     <Reference Include="System">
       <Private>True</Private>
     </Reference>

+ 13 - 0
DPTools/components/DataAnalysis/AnalysisAlgorithmcs.cs

@@ -11,6 +11,7 @@ using JH = Package_turnout_analysis;
 using MathWorks.MATLAB.NET.Arrays;
 using JHWX = Package_geo_change_analysis_for_turnout;//微小算法
 using System.Windows.Forms;
+using GL = sub_module_power_analysis;//功率算法
 
 namespace Uninpho.Tools.components.DataAnalysis
 {
@@ -174,5 +175,17 @@ namespace Uninpho.Tools.components.DataAnalysis
 
             return agrsOut;
         }
+        /// 功率算法
+        public static MWArray[] GLFX(string fname_dir0, string fname0,string xianlu,string chezhan, string filename)
+        {
+            GL.Class1 glfx = new GL.Class1();
+ 
+            MWArray[] agrsIn = new MWArray[] { fname_dir0, fname0};
+            MWArray[] agrsOut = new MWArray[10];
+
+            glfx.sub_power_analysis_main(1, ref agrsOut, agrsIn);//只输出一个cell表
+            //Console.WriteLine("算法输出:" + agrsOut[0]);
+            return agrsOut;
+        }
     }
 }

+ 186 - 11
DPTools/components/DataAnalysis/DataAnalysisClass.cs

@@ -11,6 +11,7 @@ using Uninpho.DBOperation.Operation;
 using System.Windows.Forms;
 using DevExpress.XtraEditors;
 using MathWorks.MATLAB.NET.Arrays;
+using System.Globalization;
 using System.Threading;
 //数据库表重置;
 //TRUNCATE TABLE public.t_jihefenxi_boxing;//删除表内所有数据
@@ -110,15 +111,8 @@ namespace Uninpho.Tools.components.DataAnalysis
                                     }
                                 }
 
-                                DataAnalysisToPG.DelUpdataData(GV.GetRowCellValue(selectrow[i], "Id").ToString(), type);
-                        
-                        }
-                        else if (GV.GetRowCellValue(selectrow[i], "Rwzt").ToString() == "算法未执行" && type == "微小")
-                        {
-                            XtraMessageBox.Show("请先执行几何算法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                            iszhengc = false;
-                            break;
-                        }
+                                DataAnalysisToPG.DelUpdataDataDWGL(GV.GetRowCellValue(selectrow[i], "Id").ToString(), type);                    
+                        }                       
                     }
                 }
                 else
@@ -246,8 +240,39 @@ namespace Uninpho.Tools.components.DataAnalysis
                     }
                 }
             }
-            //提示
-            if (boo)
+            else if (type == "功率")
+            {
+                for (int i = 0; i < selectrow.Length; i++)
+                {
+                    boo = true;
+                    GV.SetRowCellValue(selectrow[i], "Taskstatus", "正在执行" + type + "算法...");
+                    T_dwfile_account whichfile = (T_dwfile_account)DataAnalysisToPG.QueryToPGByIdGL(Convert.ToInt32(GV.GetRowCellValue(selectrow[i], "Id").ToString().Trim()));
+                    try
+                    {
+                        await Task.Run(() =>
+                        {                         
+                               GL_new(whichfile);              
+                        });
+                    }
+                    catch (Exception ex)
+                    {
+                        boo = false;
+                        throw;
+                    }
+                    if (boo)
+                    {
+                        GV.SetRowCellValue(selectrow[i], "Taskstatus", type + "算法执行完毕");
+                    }
+                    else
+                    {
+                        GV.SetRowCellValue(selectrow[i], "Taskstatus", "算法执行失败");
+                    }
+
+                }
+
+            }
+                //提示
+                if (boo)
             {
                 XtraMessageBox.Show(type + "算法执行完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
@@ -273,6 +298,8 @@ namespace Uninpho.Tools.components.DataAnalysis
             WXSFFun(whichfile);
         }
 
+
+
         #region 几何算法
         public void JH_new(T_file_account whichfile)
         {
@@ -809,8 +836,156 @@ namespace Uninpho.Tools.components.DataAnalysis
         #endregion
 
 
+        /// 功率算法
+        public void GL_new(T_dwfile_account whichfile)
+        {
+            //List<T_daocha_account> daochabiao = (List<T_daocha_account>)DataAnalysisToPG.QueryDCTZ(whichfile.Xlm, whichfile.Yswjm.Split('-')[0].ToCharArray());
+            //List<T_quxian_account> quxianbiao = (List<T_quxian_account>)DataAnalysisToPG.QueryQXTZ(whichfile.Xlm, whichfile.Yswjm.Split('-')[0].ToCharArray());
+            string fname_dir0 = Path.GetDirectoryName(whichfile.Srlj) + "\\";
+            string fname0 = Path.GetFileName(whichfile.Srlj);
+            Console.Write(fname_dir0);
+            Console.Write(fname0);
 
+            string xianlu = whichfile.Xianlu;
+            string chezhan = whichfile.Chezhan;
+            string filename = whichfile.Filename;
 
+            try
+            {
+                var data = AnalysisAlgorithmcs.GLFX(fname_dir0, fname0, xianlu, chezhan, filename);
+                readGLFX(data, whichfile);
+                //readGLFX_TEST(data, whichfile);
+            }
+            catch (Exception ex)
+            {
+                XtraMessageBox.Show("文件:" + whichfile.Filename + "执行失败!" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                throw;
+            }
+        }
+
+        /// 读功率分析数据     
+        private void readGLFX(MWArray[] agrsOut, T_dwfile_account whichfile)
+        {
+            try
+            {
+                MWCellArray output1 = agrsOut[0] as MWCellArray;
+                var table_data = output1.ToArray();
+
+                //// 打印原始数据结构
+                //Console.WriteLine("数据类型: " + table_data.GetType());
+                //Console.WriteLine("数据维度: " + (table_data as Array).Rank);
+
+                List<T_glanalysis_account> GLobjs = new List<T_glanalysis_account>();
+
+                // 假设是二维数组,从第2行开始
+                for (int i = 2; i < (table_data as Array).GetLength(0); i++)
+                {
+                    T_glanalysis_account gldata = new T_glanalysis_account();
+
+                    // 安全地获取每列数据
+                    gldata.Curvenumber = SafeExtractInt(table_data, i, 2);
+                    gldata.Time = SafeExtractDecimal(table_data, i, 3);
+                    gldata.Directionalmarker = SafeExtractInt(table_data, i, 4);
+                    gldata.Curvetype = SafeExtractInt(table_data, i, 5);
+                    gldata.Totalwork = SafeExtractDecimal(table_data, i, 6);
+                    gldata.Changerate = SafeExtractDecimal(table_data, i, 7);
+                    gldata.Offsetvalue = SafeExtractDecimal(table_data, i, 8);
+                    gldata.Powervariance = SafeExtractDecimal(table_data, i, 9);
+
+                    gldata.Filename = whichfile.Filename;
+                    gldata.Xianlu = whichfile.Xianlu;
+                    gldata.Chezhan = whichfile.Chezhan;
+
+                    GLobjs.Add(gldata);
+                }
+
+                //Console.WriteLine("解析完成,共 " + GLobjs.Count + " 条记录");
+                DataAnalysisToPG.updataTaskstatus(new string[] { whichfile.Id.ToString(), type + "算法执行完毕" });
+                DataAnalysisToPG.InsertGLFXDataToPG(GLobjs);
+              
+            }
+            catch (Exception ex)
+            {
+                //Console.WriteLine("解析出错: " + ex.Message);
+               // Console.WriteLine("堆栈跟踪: " + ex.StackTrace);
+            }
+        }
+
+        private int SafeExtractInt(object table_data, int row, int col)
+        {
+            try
+            {
+                // 尝试直接获取数组元素
+                var cellArray = (table_data as Array).GetValue(row, col);
+
+                // 处理 MWNumericArray
+                if (cellArray is MWNumericArray)
+                {
+                    var numArray = cellArray as MWNumericArray;
+                    return (int)Math.Round(numArray.ToScalarDouble());
+                }
+
+                // 处理 double 数组
+                if (cellArray is double[,])
+                {
+                    var doubleArray = cellArray as double[,];
+                    return (int)Math.Round(doubleArray[0, 0]);
+                }
+
+                // 其他转换尝试
+                return Convert.ToInt32(cellArray);
+            }
+            catch (Exception ex)
+            {
+                //Console.WriteLine($"提取整数失败(row:{row},col:{col}): {ex.Message}");
+                return 0;
+            }
+        }
+
+        private decimal SafeExtractDecimal(object table_data, int row, int col)
+        {
+            try
+            {
+                // 尝试直接获取数组元素
+                var cellArray = (table_data as Array).GetValue(row, col);
+
+                // 处理 MWNumericArray
+                if (cellArray is MWNumericArray)
+                {
+                    var numArray = cellArray as MWNumericArray;
+                    return (decimal)Math.Round(numArray.ToScalarDouble(), 15);
+                }
+
+                // 处理 double 数组
+                if (cellArray is double[,])
+                {
+                    var doubleArray = cellArray as double[,];
+                    return (decimal)Math.Round(doubleArray[0, 0], 15);
+                }
+
+                // 其他转换尝试
+                return Convert.ToDecimal(cellArray);
+            }
+            catch (Exception ex)
+            {
+               // Console.WriteLine($"提取小数失败(row:{row},col:{col}): {ex.Message}");
+                return 0;
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="jhfe_account"></param>
+        /// <param name="date"></param>
+        /// <param name="car"></param>
+        /// <param name="mile"></param>
+        /// <param name="wave_data"></param>
+        /// <param name="id_wave_all"></param>
+        /// <param name="jx_loc_all"></param>
+        /// <param name="line"></param>
+        /// <param name="velo"></param>
+        /// <param name="zc"></param>
         private void getdataWXSF(List<T_jihefenxi_account> jhfe_account, ref string[] date, ref string[] car, ref double[] mile, ref List<double> wave_data, ref List<double> id_wave_all, ref List<double> jx_loc_all, ref string[] line, ref double[] velo, ref string[] zc)
         {
             int bxindex = 0;

+ 23 - 0
Uninpho.DBOperation/Model/T_glanalysis_account.cs

@@ -0,0 +1,23 @@
+using SqlSugar;
+using System;
+
+namespace Uninpho.DBOperation.Model
+{
+      public class T_glanalysis_account
+    {
+        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+        public int Id { get; set; }
+        public string Xianlu { get; set; }
+        public string Chezhan { get; set; }
+        public decimal Time { get; set; }
+        public string Filename { get; set; }
+        public int Curvetype { get; set; }
+        public decimal Totalwork { get; set; }
+        public decimal Changerate { get; set; }
+        public decimal Offsetvalue { get; set; }
+        public int Curvenumber { get; set; }
+        public decimal Powervariance { get; set; }
+        public int Directionalmarker { get; set; }
+
+    }
+}

+ 57 - 6
Uninpho.DBOperation/Operation/DataAnalysisToPG.cs

@@ -117,6 +117,18 @@ namespace Uninpho.DBOperation.Operation
         /// <summary>
         /// 更新任务状态
         /// </summary>
+        public static void updataTaskstatus(string[] Yswjm)
+        {
+            NpgsqlConnection conn = new NpgsqlConnection();
+            conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
+            NpgsqlCommand comm = new NpgsqlCommand();
+            comm.Connection = conn;
+            conn.Open();
+            comm.CommandText = "UPDATE \"t_dwfile_account\" SET taskstatus = '" + Yswjm[1] + "' WHERE id =" + Yswjm[0];
+            comm.ExecuteNonQuery();
+            conn.Close();
+        }
+
         public static void updataRWZT(string[] Yswjm)
         {
             NpgsqlConnection conn = new NpgsqlConnection();
@@ -279,6 +291,13 @@ namespace Uninpho.DBOperation.Operation
                 db.Insertable(updateObjs).ExecuteCommand();
         }
         /// <summary>
+        /// 道岔功率分析表添加新数据
+        /// </summary>
+        public static void InsertGLFXDataToPG(List<T_glanalysis_account> updateObjs)
+        {
+            db.Insertable(updateObjs).ExecuteCommand();
+        }
+        /// <summary>
         /// 轮轨力表添加新数据
         /// </summary>
         public static void InsertLGLDataToPG(List<T_lunguili_account> updateObjs)
@@ -386,13 +405,26 @@ namespace Uninpho.DBOperation.Operation
                 DelToPGJHBX(whichupdata);
                 DelToPGJH(file);
             }
-            //else if (type == "功率")
-            //{
-            //    List<T_dwfile_account> whichupdata = (List<T_dwfile_account>)QueryToPGByName(yswjm);
-            //    DelToPGJHBX(whichupdata);
-            //    DelToPGJH(file);
-            //}
+            else if (type == "功率")
+            {
+                List<T_glanalysis_account> whichupdata = (List<T_glanalysis_account>)QueryToPGByNameGL(yswjm);              
+                DelToPGJH(file);
+            }
         }
+        /// 删除电务数据
+      
+        public static void DelUpdataDataDWGL(string yswjm, string type)
+        {
+            T_dwfile_account file = db.SqlQueryable<T_dwfile_account>("select * from \"t_dwfile_account\" where id = " + yswjm).ToList()[0];
+           if (type == "功率")
+            {
+                List<T_glanalysis_account> whichupdata = (List<T_glanalysis_account>)QueryToPGByNameGL(yswjm);
+                DelToPGGL(file);
+            }
+        }
+
+
+
         /// <summary>
         /// 删除数据 by ID
         /// </summary>
@@ -459,6 +491,12 @@ namespace Uninpho.DBOperation.Operation
         {
             db.Deleteable<T_jihefenxi_account>().Where(it => it.Filename_jh  == updateObjs.Id.ToString()).ExecuteCommand();
         }
+        /// 删除功率account表数据
+        /// </summary>
+        public static void DelToPGGL(T_dwfile_account updateObjs)
+        {
+            db.Deleteable<T_glanalysis_account>().Where(it => it.Filename == updateObjs.Id.ToString()).ExecuteCommand();
+        }
         /// <summary>
         /// 删除几何波形表数据
         /// </summary>
@@ -557,6 +595,11 @@ namespace Uninpho.DBOperation.Operation
         {
             return db.Queryable<T_file_account>().Where(it => it.Id == id_).Single();
         }
+        ///按id查询功率
+        public static Object QueryToPGByIdGL(int id_)
+        {
+            return db.Queryable<T_dwfile_account>().Where(it => it.Id == id_).Single();
+        }
         /// <summary>
         /// 按文件名查询文件
         /// </summary>
@@ -622,6 +665,14 @@ namespace Uninpho.DBOperation.Operation
         {
             return db.Queryable<T_lunguili_account>().Where(it => it.Filename_lgl == yswjm).ToList();
         }
+        /// <summary>
+        /// 算法按文件名查询GL
+        /// </summary>
+        public static Object QueryToPGByNameGL(string yswjm)
+        {
+            return db.Queryable<T_glanalysis_account>().Where(it => it.Filename == yswjm).ToList();
+        }
+
         /// <summary>
         /// 查询几何提取算法线路里程值
         /// </summary>

+ 1 - 0
Uninpho.DBOperation/Uninpho.DBOperation.csproj

@@ -78,6 +78,7 @@
     <Compile Include="Model\Assist_quxian.cs" />
     <Compile Include="Model\Assist_xxxwcsvdata.cs" />
     <Compile Include="Model\T_daocha_account.cs" />
+    <Compile Include="Model\T_glanalysis_account.cs" />
     <Compile Include="Model\T_dwqkfile_account.cs" />
     <Compile Include="Model\T_dwfile_account .cs" />
     <Compile Include="Model\T_file_account.cs" />