コード例 #1
0
        private MeasurementStateFlags ConvertStatusFlags(AFValueStatus status)
        {
            MeasurementStateFlags flags = MeasurementStateFlags.Normal;

            if ((status & AFValueStatus.Bad) > 0)
            {
                flags |= MeasurementStateFlags.BadData;
            }

            if ((status & AFValueStatus.Questionable) > 0)
            {
                flags |= MeasurementStateFlags.SuspectData;
            }

            if ((status & AFValueStatus.BadSubstituteValue) > 0)
            {
                flags |= MeasurementStateFlags.CalculationError | MeasurementStateFlags.BadData;
            }

            if ((status & AFValueStatus.UncertainSubstituteValue) > 0)
            {
                flags |= MeasurementStateFlags.CalculationError | MeasurementStateFlags.SuspectData;
            }

            if ((status & AFValueStatus.Substituted) > 0)
            {
                flags |= MeasurementStateFlags.CalculatedValue;
            }

            return(flags);
        }
コード例 #2
0
        public JsonResult LoadGraph(string PlantStartDateTime, string PlantEndDateTime, string SubRefinery)
        {
            var sessionObj = Session["SessionBO"] as UserModel;

            if (sessionObj != null)
            {
                string PlantStartDateTime1 = PlantStartDateTime;
                string PlantEndDateTime1   = PlantEndDateTime;

                BOMDetails objBOMDetails = new BOMDetails();

                AFLocaleIndependentFormatProvider myTimeZone = new AFLocaleIndependentFormatProvider();
                //  DateTime StartDate = Convert.ToDateTime(PlantStartDateTime1);
                //  DateTime EndDate = Convert.ToDateTime(PlantEndDateTime1);


                DateTime StartDate = Convert.ToDateTime(PlantStartDateTime1, System.Globalization.CultureInfo.CurrentCulture);
                DateTime EndDate   = Convert.ToDateTime(PlantEndDateTime1, System.Globalization.CultureInfo.CurrentCulture);
                PIPoint  feedInTag;
                PIPoint  feedOutTag;
                AFValues feedInVal;
                AFValues feedOutVal;
                AFValues filteredfeedInVal = new AFValues();
                AFValues filteredoutInVal  = new AFValues();

                try
                {
                    PIServerDetails   piServerDetails = new PIServerDetails();
                    PISystems         myPISystems     = new PISystems();
                    PISystem          mypiSystem      = myPISystems[piServerDetails.PIServerName];
                    PIServer          myPiServer      = PIServer.FindPIServer(mypiSystem, piServerDetails.PIServerName);
                    NetworkCredential Credentials     = new NetworkCredential(piServerDetails.UserName, piServerDetails.Password);
                    mypiSystem.Connect(Credentials);


                    StartDate = StartDate.AddMinutes(-330);
                    AFTime sAFTime = new AFTime(StartDate);
                    //DateTime endDT = Convert.ToDateTime(szDTend);
                    EndDate = EndDate.AddMinutes(-330);
                    AFTime      eAFTime        = new AFTime(EndDate);
                    AFTimeRange GraphTimeRange = new AFTimeRange(sAFTime, eAFTime);
                    //   mypiSystem.Connect(Credentials);

                    objBOMDetails = objBOMDetails.getFeedInFeedOutTag(SubRefinery);



                    feedInTag = PIPoint.FindPIPoint(myPiServer, objBOMDetails.feedInTag);
                    feedInVal = feedInTag.RecordedValues(GraphTimeRange, 0, null, true, 0);

                    foreach (AFValue val in feedInVal)
                    {
                        if (val.IsGood)
                        {
                            filteredfeedInVal.Add(val);
                        }
                        else
                        {
                            val.Value = 0;
                            filteredfeedInVal.Add(val);
                        }
                    }

                    feedOutTag = PIPoint.FindPIPoint(myPiServer, objBOMDetails.feedOutTag);
                    feedOutVal = feedOutTag.RecordedValues(GraphTimeRange, 0, null, true, 0);

                    foreach (AFValue val in feedOutVal)
                    {
                        if (val.IsGood)
                        {
                            filteredoutInVal.Add(val);
                        }
                        else
                        {
                            val.Value = 0;
                            filteredoutInVal.Add(val);
                        }
                    }

                    int             inLenArray      = filteredfeedInVal.Count;
                    object[]        feedInValArr    = new object[inLenArray];
                    DateTime[]      feedInDateArr   = new DateTime[inLenArray];
                    AFValueStatus[] feedInValStatus = new AFValueStatus[inLenArray];
                    filteredfeedInVal.GetValueArrays(out feedInValArr, out feedInDateArr, out feedInValStatus);
                    int      outLenArray   = feedOutVal.Count;
                    object[] feedOutValArr = new object[outLenArray];

                    DateTime[]      feedOutDateArr   = new DateTime[outLenArray];
                    AFValueStatus[] feedOutValStatus = new AFValueStatus[outLenArray];
                    filteredoutInVal.GetValueArrays(out feedOutValArr, out feedOutDateArr, out feedOutValStatus);
                    List <KeyValuePair <string, double> > fInlist  = new List <KeyValuePair <string, double> >();
                    List <KeyValuePair <string, double> > fOutlist = new List <KeyValuePair <string, double> >();
                    //  double[] fInDateValdouble = new double[inLenArray];
                    double[] fOutDateVal = new double[outLenArray];
                    double[] fInDateVal  = new double[inLenArray];
                    for (int i = 0; i < feedInValArr.Length; i++)
                    {
                        //string fIn = feedInValArr[i].ToString();
                        double fint = Convert.ToInt32(feedInValArr[i]);
                        if (fint == 0.0)
                        {
                            fInDateVal[i] = -99999;
                        }
                        else if (fint < 0.0)
                        {
                            fInDateVal[i] = -99999;
                        }
                        else
                        {
                            fInDateVal[i] = Math.Round(Convert.ToDouble(feedInValArr[i]), 2);
                        }
                    }
                    string[] fInDateArr = new string[inLenArray];
                    for (int i = 0; i < feedInDateArr.Length; i++)
                    {
                        fInDateArr[i] = feedInDateArr[i].ToString("MM-dd-yyyy HH:mm:ss");
                        var element = new KeyValuePair <string, double>(fInDateArr[i], fInDateVal[i]);
                        fInlist.Add(element);
                    }

                    string[] fOutDateArr = new string[outLenArray];

                    for (int i = 0; i < feedOutDateArr.Length; i++)   //feedOutDateArr
                    {
                        //string fOut = feedOutValArr[i].ToString();    //fOutDateArr
                        double fout = Convert.ToInt32(feedOutValArr[i]);
                        if (fout == 0.0)
                        {
                            fOutDateVal[i] = -99999;
                        }
                        else if (fout < 0.0)
                        {
                            fOutDateVal[i] = -99999;
                        }
                        else
                        {
                            fOutDateVal[i] = Math.Round(Convert.ToDouble(feedOutValArr[i]), 2);
                        }
                    }
                    // string[] fOutDateArr = new string[inLenArray];
                    for (int i = 0; i < feedOutDateArr.Length; i++)
                    {
                        fOutDateArr[i] = feedOutDateArr[i].ToString("MM-dd-yyyy HH:mm:ss");
                        var element1 = new KeyValuePair <string, double>(fOutDateArr[i], fOutDateVal[i]);
                        fOutlist.Add(element1);
                    }


                    Dictionary <string, List <KeyValuePair <string, double> > > dec = new Dictionary <string, List <KeyValuePair <string, double> > >();

                    dec.Add("feedIn", fInlist);
                    dec.Add("feedOut", fOutlist);



                    JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                    // string json = javaScriptSerializer.Serialize(feedInDateArr);

                    JsonResult js = Json(new { value = dec }, JsonRequestBehavior.AllowGet);

                    return(js);

                    // return Json(new { value = dec }, JsonRequestBehavior.AllowGet);
                }
                catch (Exception e)
                {
                    return(Json(new { value = "Exception Occured" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        private MeasurementStateFlags ConvertStatusFlags(AFValueStatus status)
        {
            MeasurementStateFlags flags = MeasurementStateFlags.Normal;

            if ((status & AFValueStatus.Bad) > 0)
                flags |= MeasurementStateFlags.BadData;

            if ((status & AFValueStatus.Questionable) > 0)
                flags |= MeasurementStateFlags.SuspectData;

            if ((status & AFValueStatus.BadSubstituteValue) > 0)
                flags |= MeasurementStateFlags.CalculationError | MeasurementStateFlags.BadData;

            if ((status & AFValueStatus.UncertainSubstituteValue) > 0)
                flags |= MeasurementStateFlags.CalculationError | MeasurementStateFlags.SuspectData;

            if ((status & AFValueStatus.Substituted) > 0)
                flags |= MeasurementStateFlags.CalculatedValue;

            return flags;
        }