Esempio n. 1
0
 /// <summary>
 /// 是否满足计算条件
 /// </summary>
 /// <returns></returns>
 public static bool CanRun()
 {
     if (!DBAccess.GetRealTime().Connection())
     {
         LogUtil.LogMessage("实时库连接异常,终止计算");
         return(false);
     }
     if (!WS_ExcelDBClient.Connection())
     {
         LogUtil.LogMessage("关系库连接异常,终止计算");
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
        /// <summary>
        /// 从实时数据库抽取历史数据进行处理,处理结束后存入关系型数据库
        /// </summary>
        /// <param name="strExcel">各机组值点配置文件</param>
        /// <param name="strSheet">工作簿</param>
        /// <param name="dtSTime">开始时间</param>
        /// <param name="dtETime">截止时间</param>
        /// <param name="nLength"></param>
        /// <param name="nSecond"></param>
        /// <returns></returns>
        public static bool HistoryCalc(string strExcel, string strSheet,
                                       string strUnit, string strKPI,
                                       DateTime dtSTime, DateTime dtETime, int nLength, int nOffset, int nSecond)
        {
            //获取ExcelTag
            if (ltExcelTags == null || ltExcelTags.Count <= 0)
            {
                if (!ImportExcelToList(strExcel, strSheet))
                {
                    return(false);
                }
            }

            if (ltExcelTags.Count <= 0)
            {
                LogUtil.LogMessage("无有效数据!");
                return(true);
            }

            //////////////////////////////////////////////////////////////////////////
            while (dtSTime <= dtETime)
            {
                bool bCalc  = false;
                int  nCS    = dtSTime.Second;
                int  nCM    = dtSTime.Minute;
                int  nCMmod = nCM % nLength;

                if (nOffset <= 0)
                {
                    if (nCMmod == 0)
                    {
                        bCalc = true;
                    }
                    else
                    {
                        bCalc = false;
                    }
                }
                else
                {
                    if (nCMmod == nOffset)
                    {
                        bCalc = true;
                    }
                    else
                    {
                        bCalc = false;
                    }
                }

                //自动一分钟循环
                DateTime dtTime = dtSTime.AddMinutes(-1 * nOffset);
                dtSTime = dtSTime.AddMinutes(1);

                if (!bCalc)
                {
                    continue;
                }

                #region 历史计算

                string   strUnitFilter = "";
                string   strKPIFilter  = "";
                string[] arrUnit       = strUnit.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries);
                string[] arrKPI        = strKPI.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries);

                string strTime = dtTime.ToString("yyyy-MM-dd HH:mm:ss");

                if (arrUnit.Length == 0 && arrKPI.Length == 0)
                {
                    //所有机组、所有指标的情况
                    //删除
                    WS_ExcelDBClient.DeleteData("", "", strTime);

                    //读写
                    ReadAndWrite(ltExcelTags, dtTime, nLength, nSecond);
                }
                else if (arrUnit.Length > 0 && arrKPI.Length == 0)
                {
                    //个别机组、所有指标的情况
                    for (int i = 0; i < arrUnit.Length; i++)
                    {
                        strUnitFilter = arrUnit[i].ToLower();

                        List <WS_ExcelTag> ltTags = ltExcelTags.Where(p => p.UnitCode.ToLower().Contains(strUnitFilter)).ToList();

                        //删除
                        WS_ExcelDBClient.DeleteData(strUnitFilter, "", strTime);

                        //读写
                        ReadAndWrite(ltTags, dtTime, nLength, nSecond);
                    }
                }
                else
                {
                    //个别机组、个别指标的情况
                    for (int i = 0; i < arrUnit.Length; i++)
                    {
                        strUnitFilter = arrUnit[i].ToLower();

                        for (int j = 0; j < arrKPI.Length; j++)
                        {
                            strKPIFilter = arrKPI[j].ToLower();

                            List <WS_ExcelTag> ltTags = ltExcelTags.Where(p => (p.UnitCode.ToLower().Contains(strUnitFilter) && p.TagCode.ToLower().Contains(strKPIFilter))).ToList();

                            if (ltTags.Count <= 0)
                            {
                                continue;
                            }

                            //删除
                            WS_ExcelDBClient.DeleteData(strUnitFilter, strKPIFilter, strTime);

                            //读写
                            ReadAndWrite(ltTags, dtTime, nLength, nSecond);
                        }
                    }
                }

                #endregion
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// 从实时数据库抽取数据进行处理,处理结束后存入关系型数据库
        /// </summary>
        /// <param name="ltTags">各机组值点</param>
        /// <param name="dtTime"></param>
        /// <param name="nLength"></param>
        /// <param name="nSecond"></param>
        /// <returns></returns>
        private static bool ReadAndWrite(List <WS_ExcelTag> ltTags, DateTime dtTime, int nLength, int nSecond)
        {
            //如果nSecond==0时,没有变化
            DateTime dtValid = dtTime.AddSeconds(nSecond);
            //////////////////////////////////////////////////////////////////////////
            //整理点表
            DataTable dt = WS_ExcelDBClient.GetTableSchema();

            //获得机组列表
            var unitresult = (from kpi in ltTags
                              orderby kpi.UnitCode
                              select kpi.UnitCode).Distinct().ToList();

            foreach (string unitcode in unitresult)
            {
                var kpiresult = from kpi in ltTags
                                where (kpi.UnitCode == unitcode && kpi.TagIsValid == "1")
                                select kpi;

                if (kpiresult.Count() <= 0)
                {
                    continue;
                }

                string strCondition = kpiresult.ElementAt(0).TagRunExp;
                Double dRunning     = DBAccess.GetRealTime().TimedCalculate(strCondition, dtValid);

                //机组停运
                if (dRunning < 0.5)
                {
                    string strTime = dtValid.ToString("yyyy-MM-dd HH:mm:ss");
                    LogUtil.LogMessage("机组:" + unitcode + ",在" + strTime + "负荷太低或停运,本次不采集本机组数据!");
                    continue;
                }
                else
                {
                    LogUtil.LogMessage("开始采集机组数据:" + unitcode);
                }

                //机组相关标签点
                Dictionary <string, TagValue> dicTags = new Dictionary <string, TagValue>();
                foreach (WS_ExcelTag tagcode in kpiresult)
                {
                    String strCode = tagcode.TagShiftExp.Trim();
                    if (strCode != "")
                    {
                        dicTags[strCode] = new TagValue(strCode);
                    }

                    strCode = tagcode.TagPeriodExp.Trim();
                    if (strCode != "")
                    {
                        dicTags[strCode] = new TagValue(strCode);
                    }

                    strCode = tagcode.TagMWExp.Trim();
                    if (strCode != "")
                    {
                        dicTags[strCode] = new TagValue(strCode);
                    }

                    strCode = tagcode.TagSnapExp.Trim();
                    if (strCode != "")
                    {
                        dicTags[strCode] = new TagValue(strCode);
                    }

                    strCode = tagcode.TagTargetExp.Trim();
                    if (strCode != "")
                    {
                        dicTags[strCode] = new TagValue(strCode);
                    }

                    strCode = tagcode.TagScoreExp.Trim();
                    if (strCode != "")
                    {
                        dicTags[strCode] = new TagValue(strCode);
                    }
                }

                string strError = "";

                if (!DBAccess.GetRealTime().GetArchiveListData(ref dicTags, dtValid, out strError))
                {
                    LogUtil.LogMessage(strError);
                }

                foreach (WS_ExcelTag tagcode in kpiresult)
                {
                    DataRow dr = dt.NewRow();

                    dr["TagID"]      = Guid.NewGuid().ToString();
                    dr["UnitCode"]   = tagcode.UnitCode;
                    dr["TagCode"]    = tagcode.TagCode;
                    dr["TagType"]    = tagcode.TagType;
                    dr["TagEngunit"] = tagcode.TagEngunit;
                    dr["TagTime"]    = dtTime.ToString("yyyy-MM-dd HH:mm:ss");

                    if (dicTags.ContainsKey(tagcode.TagShiftExp) &&
                        dicTags[tagcode.TagShiftExp].TagQulity == 0 &&
                        dicTags[tagcode.TagShiftExp].TagStringValue != null)
                    {
                        dr["TagShift"] = dicTags[tagcode.TagShiftExp].TagStringValue;
                    }
                    else
                    {
                        dr["TagShift"] = System.DBNull.Value;
                    }

                    if (dicTags.ContainsKey(tagcode.TagPeriodExp) &&
                        dicTags[tagcode.TagPeriodExp].TagQulity == 0 &&
                        dicTags[tagcode.TagPeriodExp].TagStringValue != null)
                    {
                        dr["TagPeriod"] = dicTags[tagcode.TagPeriodExp].TagStringValue;
                    }
                    else
                    {
                        dr["TagPeriod"] = System.DBNull.Value;
                    }

                    if (dicTags.ContainsKey(tagcode.TagMWExp) &&
                        dicTags[tagcode.TagMWExp].TagQulity == 0 &&
                        dicTags[tagcode.TagMWExp].TagStringValue != null)
                    {
                        dr["TagMW"] = dicTags[tagcode.TagMWExp].TagStringValue;
                    }
                    else
                    {
                        dr["TagMW"] = System.DBNull.Value;
                    }

                    if (dicTags.ContainsKey(tagcode.TagSnapExp) &&
                        dicTags[tagcode.TagSnapExp].TagQulity == 0 &&
                        dicTags[tagcode.TagSnapExp].TagStringValue != null)
                    {
                        dr["TagSnap"] = dicTags[tagcode.TagSnapExp].TagStringValue;
                    }
                    else
                    {
                        dr["TagSnap"] = System.DBNull.Value;
                    }

                    if (dicTags.ContainsKey(tagcode.TagTargetExp) &&
                        dicTags[tagcode.TagTargetExp].TagQulity == 0 &&
                        dicTags[tagcode.TagTargetExp].TagStringValue != null)
                    {
                        dr["TagTarget"] = dicTags[tagcode.TagTargetExp].TagStringValue;
                    }
                    else
                    {
                        dr["TagTarget"] = System.DBNull.Value;
                    }

                    if (dicTags.ContainsKey(tagcode.TagScoreExp) &&
                        dicTags[tagcode.TagScoreExp].TagQulity == 0 &&
                        dicTags[tagcode.TagScoreExp].TagStringValue != null)
                    {
                        dr["TagScore"] = dicTags[tagcode.TagScoreExp].TagStringValue;
                    }
                    else
                    {
                        dr["TagScore"] = System.DBNull.Value;
                    }

                    dr["TagLength"]  = nLength.ToString();
                    dr["TagRemoved"] = "0";


                    dt.Rows.Add(dr);
                }
            }

            if (dt.Rows.Count > 0)
            {
                WS_ExcelDBClient.BulkToDB(dt);
            }

            dt.Dispose();

            return(true);
        }