Пример #1
0
        public void TestTwoSnapshots()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            CastDate previousDate = new CastDate {
                Time = 1484866800000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCresults.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, @".\Data\PreviousBCresults.json", "AED/applications/3/snapshots/3", "PreVersion 1.4.1 before release", "V-1.4.1", previousDate);

            var component = new TQI();
            Dictionary <string, string> config = new Dictionary <string, string>();
            var table = component.Content(reportData, config);

            var expectedData = new List <string>();

            expectedData.AddRange(new List <string> {
                "Statistics", "Current score", "Previous score"
            });
            expectedData.AddRange(new List <string> {
                "TQI", "2.78", "2.73"
            });
            TestUtility.AssertTableContent(table, expectedData, 3, 2);
        }
Пример #2
0
        /// <summary>
        /// 计算TQI
        /// </summary>
        /// <param name="citFilePath">cit文件路径</param>
        /// <param name="listIC">索引数据类集合</param>
        /// <param name="channelNums">需要计算的通道号集合</param>
        /// <param name="fscale"></param>
        /// <param name="fi"></param>
        /// <returns></returns>
        private List <TQI> CalculateTQI(string citFilePath, List <IndexSta> listIC, int[] channelNums, float[] fscale, FileInformation fi)
        {
            int    channelCount = fi.iChannelNumber;
            string sKmInc       = "";

            if (fi.iKmInc == 0)
            {
                sKmInc = "增";
            }
            else if (fi.iKmInc == 1)
            {
                sKmInc = "减";
            }


            List <TQI> listTQI = new List <TQI>();

            for (int i = 0; i < listIC.Count; i++)
            {
                List <TQIMile> listWM     = new List <TQIMile>();
                double         dStartMile = 0d;
                double         dEndMile   = 0d;
                dStartMile = double.Parse(listIC[i].lStartMeter);
                dEndMile   = double.Parse(listIC[i].LEndMeter);

                int iKM    = (int)float.Parse(listIC[i].lStartMeter);
                int iMeter = (int)(float.Parse(listIC[i].lStartMeter) * 1000) - (iKM * 1000);
                if (sKmInc.Equals("增"))
                {
                    while (true)
                    {
                        TQIMile wm   = new TQIMile();
                        int     iMod = iMeter % 200;
                        wm.iMeter = iMeter + (200 - iMod);

                        wm.iKM = iKM;
                        if (listIC[i].sType.Equals("正常"))
                        {
                            if (wm.iMeter == 1000)
                            {
                                wm.iMeter = 0;
                                wm.iKM    = iKM + 1;
                            }
                        }
                        else
                        {
                        }
                        wm.lPostion = GetNewIndexMeterPositon(listIC, wm.iKM * 1000 + wm.iMeter, channelCount, sKmInc, 0);
                        iMeter      = wm.iMeter;
                        iKM         = wm.iKM;
                        if ((iKM + iMeter / 1000f) < dEndMile)
                        {
                            listWM.Add(wm);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else//jian
                {
                    if (listIC[i].sType.Equals("长链"))
                    {
                        iMeter = (int)(float.Parse(listIC[i].lContainsMeter) * 1000);
                    }
                    while (true)
                    {
                        TQIMile wm   = new TQIMile();
                        int     iMod = iMeter % 200;
                        wm.iMeter = iMeter - (iMod == 0 ? 200 : iMod);
                        wm.iKM    = iKM;
                        if (listIC[i].sType.Equals("正常"))
                        {
                            if (wm.iMeter < 0)
                            {
                                wm.iMeter = 800;
                                wm.iKM    = iKM - 1;
                            }
                        }
                        else
                        {
                        }
                        wm.lPostion = GetNewIndexMeterPositon(listIC, wm.iKM * 1000 + wm.iMeter, channelCount, sKmInc, 0);
                        iMeter      = wm.iMeter;
                        iKM         = wm.iKM;
                        if (wm.iMeter == 0 && listIC[i].sType.Equals("正常"))
                        {
                            wm.iMeter = 800;
                            wm.iKM   -= 1;
                        }
                        else
                        {
                            wm.iMeter -= 200;
                        }
                        if ((iKM + iMeter / 1000f) > dEndMile)
                        {
                            listWM.Add(wm);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                //


                FileStream   fs = new FileStream(citFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                BinaryReader br = new BinaryReader(fs);

                int iRate = (int)(200 / (float.Parse(listIC[i].lContainsMeter) * 1000 / listIC[i].lContainsPoint));
                for (int k = 0; k < listWM.Count; k++)
                {
                    if (listWM[k].lPostion == -1)
                    {
                        continue;
                    }
                    br.BaseStream.Position = listWM[k].lPostion;
                    double[][] fArray = new double[10][];
                    for (int j = 0; j < 10; j++)
                    {
                        fArray[j] = new double[iRate];
                    }
                    for (int l = 0; l < iRate; l++)
                    {
                        if (br.BaseStream.Position < br.BaseStream.Length)
                        {
                            byte[] b = br.ReadBytes(channelCount * 2);
                            if (Encryption.IsEncryption(fi.sDataVersion))
                            {
                                b = Encryption.Translate(b);
                            }
                            //处理数据通道
                            for (int n = 0; n < channelNums.Length; n++)
                            {
                                float fValue = float.Parse((BitConverter.ToInt16(b, channelNums[n] * 2)).ToString()) / fscale[channelNums[n]];
                                //sb.Append("," + fValue.ToString("f2"));
                                fArray[n][l] = fValue;
                            }
                        }
                    }
                    //计算
                    TQI tqic = new TQI();
                    tqic.zgd    = Math.Round(CalcStardard(fArray[0]), 2);
                    tqic.ygd    = Math.Round(CalcStardard(fArray[1]), 2);
                    tqic.zgx    = Math.Round(CalcStardard(fArray[2]), 2);
                    tqic.ygx    = Math.Round(CalcStardard(fArray[3]), 2);
                    tqic.gj     = Math.Round(CalcStardard(fArray[4]), 2);
                    tqic.sp     = Math.Round(CalcStardard(fArray[5]), 2);
                    tqic.sjk    = Math.Round(CalcStardard(fArray[6]), 2);
                    tqic.hj     = Math.Round(CalcStardard(fArray[7]), 2);
                    tqic.cj     = Math.Round(CalcStardard(fArray[8]), 2);
                    tqic.pjsd   = CalcAvgSpeed(fArray[9]);
                    tqic.iKM    = listWM[k].iKM;
                    tqic.iMeter = listWM[k].iMeter;
                    listTQI.Add(tqic);
                }
            }

            return(listTQI);
        }
        /// <summary>
        /// TQI拷贝,把车上计算出来的tqi由纵向排列变为横向排列
        /// </summary>
        /// <param name="sIICFileName">iic文件名</param>
        /// <param name="sKmInc">增减里程</param>
        /// <param name="listIDC">无效区段</param>
        public void TQICopy(string sIICFileName, string sKmInc, List <InvalidData> listIDC)
        {
            int    iKMLast            = 0;
            int    iMeterLast         = 0;
            int    iKMNow             = 0;
            int    iMeterNow          = 0;
            String channelNameGeo     = null;
            double channelTqiValueGeo = 0.0d;
            float  basePost           = 0f;
            int    baseMinor          = 0;

            //geo文件中的通道名
            string[] sTQIItem = new string[] { "L_STDSURF", "R_STDSURF", "L_STDALIGN",
                                               "R_STDALIGN", "STDGAUGE", "STDCROSSLEVEL", "STDTWIST", "STDLATACCEL", "STDVERTACCEL", "MAXSPEED" };

            List <TQI> listTQI = new List <TQI>();
            TQI        tqiCls  = new TQI();

            String   subCode = null; //ashx
            DateTime runDate = DateTime.Now;



            #region 获取TQI,并写入到listTQI
            try
            {
                using (OleDbConnection sqlconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sIICFileName + ";Persist Security Info=True"))
                {
                    string       sqlCreate = "select FromPost,FromMinor,TQIMetricName,TQIValue,BasePost,SubCode,RunDate from tqi order by BasePost";
                    OleDbCommand sqlcom    = new OleDbCommand(sqlCreate, sqlconn);
                    sqlconn.Open();
                    OleDbDataReader oleDBdr = sqlcom.ExecuteReader();

                    if (!oleDBdr.HasRows)
                    {
                        MessageBox.Show("TQI列表为空!");
                        return;
                    }

                    while (oleDBdr.Read())
                    {
                        basePost           = float.Parse(oleDBdr.GetValue(4).ToString());
                        baseMinor          = (int)(Math.Round(basePost, 2) * 1000) % 1000;
                        iKMNow             = (int)basePost;
                        iMeterNow          = baseMinor;
                        channelNameGeo     = oleDBdr.GetValue(2).ToString();
                        channelTqiValueGeo = Math.Round(double.Parse(oleDBdr.GetValue(3).ToString()), 2);

                        subCode = oleDBdr.GetValue(5).ToString();
                        runDate = DateTime.Parse(oleDBdr.GetValue(6).ToString());

                        if ((iKMNow != iKMLast) || (iMeterNow != iMeterLast))
                        {
                            tqiCls = new TQI();

                            listTQI.Add(tqiCls);

                            tqiCls.iKM    = iKMNow;
                            tqiCls.iMeter = iMeterNow;

                            tqiCls.subCode = subCode;
                            tqiCls.runDate = runDate;

                            iKMLast    = iKMNow;
                            iMeterLast = iMeterNow;
                        }

                        #region TQI赋值
                        foreach (String tqiName in sTQIItem)
                        {
                            if (tqiName == channelNameGeo)
                            {
                                //左高低
                                if (channelNameGeo == "L_STDSURF")
                                {
                                    tqiCls.zgd = channelTqiValueGeo;
                                }
                                //右高低
                                if (channelNameGeo == "R_STDSURF")
                                {
                                    tqiCls.ygd = channelTqiValueGeo;
                                }
                                //左轨向
                                if (channelNameGeo == "L_STDALIGN")
                                {
                                    tqiCls.zgx = channelTqiValueGeo;
                                }
                                //右轨向
                                if (channelNameGeo == "R_STDALIGN")
                                {
                                    tqiCls.ygx = channelTqiValueGeo;
                                }
                                //轨距
                                if (channelNameGeo == "STDGAUGE")
                                {
                                    tqiCls.gj = channelTqiValueGeo;
                                }
                                //水平
                                if (channelNameGeo == "STDCROSSLEVEL")
                                {
                                    tqiCls.sp = channelTqiValueGeo;
                                }
                                //三角坑
                                if (channelNameGeo == "STDTWIST")
                                {
                                    tqiCls.sjk = channelTqiValueGeo;
                                }
                                //车体横向加速度
                                if (channelNameGeo == "STDLATACCEL")
                                {
                                    tqiCls.hj = channelTqiValueGeo;
                                }
                                //车体垂向加速度
                                if (channelNameGeo == "STDVERTACCEL")
                                {
                                    tqiCls.cj = channelTqiValueGeo;
                                }
                                //平均速度
                                if (channelNameGeo == "MAXSPEED")
                                {
                                    tqiCls.pjsd = (int)channelTqiValueGeo;
                                }


                                break;
                            }
                        }
                        #endregion
                    }
                    sqlconn.Close();
                }
                Application.DoEvents();
            }
            catch
            {
            }
            #endregion

            #region 插入TQI
            try
            {
                using (OleDbConnection sqlconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sIICFileName + ";Persist Security Info=True"))
                {
                    string       sqlCreate = "";
                    OleDbCommand sqlcom    = new OleDbCommand(sqlCreate, sqlconn);
                    sqlconn.Open();
                    for (int i = 0; i < listTQI.Count; i++)
                    {
                        sqlcom.CommandText = "insert into fix_tqi " +
                                             "values('" + listTQI[i].subCode + "','" + listTQI[i].runDate + "'," + listTQI[i].iKM.ToString()
                                             + "," + listTQI[i].iMeter.ToString()
                                             + "," + listTQI[i].zgd.ToString()
                                             + "," + listTQI[i].ygd.ToString()
                                             + "," + listTQI[i].zgx.ToString()
                                             + "," + listTQI[i].ygx.ToString()
                                             + "," + listTQI[i].gj.ToString()
                                             + "," + listTQI[i].sp.ToString()
                                             + "," + listTQI[i].sjk.ToString()
                                             + "," + listTQI[i].GetTQISum().ToString()
                                             + "," + listTQI[i].hj.ToString()
                                             + "," + listTQI[i].cj.ToString()
                                             + "," + listTQI[i].pjsd.ToString()
                                             + "," + listTQI[i].iValid.ToString() + ")";
                        sqlcom.ExecuteNonQuery();
                    }
                    sqlconn.Close();
                }
                Application.DoEvents();
            }
            catch
            {
            }
            #endregion

            #region  除无效的TQI
            try
            {
                using (OleDbConnection sqlconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sIICFileName + ";Persist Security Info=True"))
                {
                    string       sqlCreate = "TQISum_Value=0 or AVERAGE_SPEED=0";
                    OleDbCommand sqlcom    = new OleDbCommand(sqlCreate, sqlconn);
                    sqlconn.Open();
                    sqlcom.CommandText = "delete from fix_tqi where " + sqlCreate;
                    sqlcom.ExecuteNonQuery();
                    sqlconn.Close();
                }
                Application.DoEvents();
            }
            catch
            {
            }
            #endregion
        }