Ejemplo n.º 1
0
        public void SaveTestData(CandidateClassifier clsInfo, DateTime nowDate)
        {
            if (TestParameters.OnlyNewestTestDataSaved)
            {
                string sql = string.Format("DELETE FROM {0}", m_testDataTableName);
                Feng.Data.DbHelper.Instance.ExecuteNonQuery(sql);
            }

            string str = WekaUtils.DoubleArrayToIntString(clsInfo.CurrentTestRet);
            string scv = WekaUtils.DoubleArrayToIntString(clsInfo.CurrentClassValue);

            if (m_testDataInsertTable == null)
            {
                m_testDataInsertTable = new System.Data.DataTable();
                m_testDataInsertTable.Columns.Add("Id", typeof(int));
                m_testDataInsertTable.Columns.Add("Time", typeof(long));
                //m_testDataInsertTable.Columns.Add("Type", typeof(int));
                m_testDataInsertTable.Columns.Add("ClsName", typeof(string));
                m_testDataInsertTable.Columns.Add("TestResult", typeof(string));
                m_testDataInsertTable.Columns.Add("ClassValue", typeof(string));
                m_testDataInsertTable.Columns.Add("DealsInfo", typeof(byte[]));
                m_testDataInsertTable.Columns.Add("DealsData", typeof(byte[]));
            }
            var row = m_testDataInsertTable.NewRow();

            row["ClsName"] = clsInfo.Name;
            //row["Type"] = m_testDataType;
            row["Time"]       = WekaUtils.GetTimeFromDate(nowDate);
            row["TestResult"] = str;
            row["ClassValue"] = scv;
            row["DealsInfo"]  = Feng.Windows.Utils.SerializeHelper.Serialize(clsInfo.Deals);

            bool shouldSave = false;

            if (nowDate.DayOfWeek != DayOfWeek.Sunday && nowDate.DayOfWeek != DayOfWeek.Saturday && nowDate.Day == 20)
            {
                shouldSave = true;
            }
            if (nowDate.Day == 21 && nowDate.DayOfWeek == DayOfWeek.Monday)
            {
                shouldSave = true;
            }
            if (nowDate.Day == 22 && nowDate.DayOfWeek == DayOfWeek.Monday)
            {
                shouldSave = true;
            }

            if (TestParameters.OnlyNewestTestDataSaved)
            {
                shouldSave = true;
            }

            if (shouldSave)
            {
                byte[] dealsData = Feng.Windows.Utils.SerializeHelper.Serialize(clsInfo.Deals.Deals);
                System.IO.MemoryStream outStream = new System.IO.MemoryStream();
                using (System.IO.Compression.GZipStream zipStream =
                           new System.IO.Compression.GZipStream(outStream, System.IO.Compression.CompressionMode.Compress))
                {
                    System.IO.MemoryStream inStream = new System.IO.MemoryStream(dealsData);
                    inStream.CopyTo(zipStream);
                }
                row["DealsData"] = outStream.ToArray();
            }
            else
            {
                row["DealsData"] = System.DBNull.Value;
            }
            m_testDataInsertTable.Rows.Add(row);

            if (m_testDataInsertTable.Rows.Count > 100)
            {
                //WekaUtils.Instance.WriteLog("Save Test Data.");

                try
                {
                    Feng.Data.DbHelper.Instance.BulkCopy(m_testDataInsertTable, m_testDataTableName);
                }
                catch (Exception ex)
                {
                    WekaUtils.Instance.WriteLog(ex.Message);
                }
                m_testDataInsertTable.Rows.Clear();
            }
            //SqlCommand cmd = new SqlCommand("INSERT INTO TestData ([ClsName],[Time], [Type], TestResult, ClassValue, DealsData) VALUES (@ClsName, @Time, @Type, @TestResult, @ClassValue, @DealsData)");
            //cmd.Parameters.AddWithValue("@ClsName", clsInfo.Name);
            //cmd.Parameters.AddWithValue("@Type", m_testDataType);
            //cmd.Parameters.AddWithValue("@Time", WekaUtils.GetTimeFromDate(currentDate));
            //cmd.Parameters.AddWithValue("@TestResult", str);
            //cmd.Parameters.AddWithValue("@ClassValue", scv);
            //cmd.Parameters.AddWithValue("@DealsData", Feng.Utils.SerializeHelper.Serialize(clsInfo.Deals));
            //SetTransaction(cmd);
        }