Esempio n. 1
0
        public PspTimeValTuple GetPSPMeasVal(PspMeasurement pspMeasurement, int fromTime)
        {
            TableRowsApiResultModel fetchedData = GetLabelData(pspMeasurement, fromTime, fromTime);
            List <List <object> >   rows        = fetchedData.TableRows;
            List <string>           colNames    = fetchedData.TableColNames;
            int timeInd = colNames.IndexOf(pspMeasurement.PspTimeCol);
            int valInd  = colNames.IndexOf(pspMeasurement.PspValCol);

            if (timeInd == -1 || valInd == -1)
            {
                // desired result was not found
                return(null);
            }
            if (rows.Count == 0)
            {
                // desired result was not found
                return(null);
            }
            // todo check val types also
            int             timeInt = Convert.ToInt32((decimal)rows.ElementAt(0).ElementAt(timeInd));
            decimal?        val     = (decimal)rows.ElementAt(0).ElementAt(valInd);
            PspTimeValTuple result  = new PspTimeValTuple {
                TimeInt = timeInt, Val = val
            };

            return(result);
        }
Esempio n. 2
0
        public static List <LabelCheckResult> GetLabelCheckResults(string connStr, LabelCheck labelCheck, DateTime fromTime, DateTime toTime)
        {
            // get measurement fetch helper
            PspDbHelper helper = new PspDbHelper()
            {
                ConnStr = connStr
            };

            // fetch the measurement values
            List <PspTimeValTuple> tuples = helper.GetPSPMeasVals(labelCheck.PspMeasurement, ConvertDateTimeToInt(fromTime), ConvertDateTimeToInt(toTime));

            // do the checking algorithm on each tuple to produce check results
            List <LabelCheckResult> labelCheckResults = new List <LabelCheckResult>();

            // initialize a checkresult for each date with remark, data not found for processing
            for (int dayIter = 0; dayIter <= (toTime - fromTime).Days; dayIter++)
            {
                labelCheckResults.Add(new LabelCheckResult {
                    IsSuccessful = false, CheckProcessStartTime = fromTime.AddDays(dayIter), CheckProcessEndTime = fromTime.AddDays(dayIter), LabelCheckId = labelCheck.Id, Remarks = "data not processed"
                });
            }

            // scan all the tuples to process the checks and replace with initial values
            for (int tupleIter = 0; tupleIter < tuples.Count; tupleIter++)
            {
                int targetResultInd;
                LabelCheckResult targetResult;
                PspTimeValTuple  tuple = tuples[tupleIter];
                // find the tuple to be modified from the list of inititalized results
                targetResultInd = labelCheckResults.FindIndex(res =>
                                                              (res.CheckProcessStartTime.Date == ConvertIntToDateTime(tuple.TimeInt).Date&&
                                                               res.CheckProcessEndTime.Date == ConvertIntToDateTime(tuple.TimeInt).Date));
                if (targetResultInd == -1)
                {
                    continue;
                }
                if (labelCheck.CheckType == CheckTypeNotNull)
                {
                    targetResult = labelCheckResults.ElementAt(targetResultInd);
                    if (tuple.Val == null)
                    {
                        targetResult.CheckProcessEndTime   = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.CheckProcessStartTime = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.IsSuccessful          = false;
                        targetResult.Remarks = "null value found";
                        labelCheckResults[targetResultInd] = targetResult;
                    }
                    else
                    {
                        targetResult.CheckProcessEndTime   = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.CheckProcessStartTime = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.IsSuccessful          = true;
                        targetResult.Remarks = $"passed, value={tuple.Val}";
                        labelCheckResults[targetResultInd] = targetResult;
                    }
                }
                else if (labelCheck.CheckType == CheckTypeLimit)
                {
                    targetResult = labelCheckResults.ElementAt(targetResultInd);
                    if (tuple.Val >= labelCheck.Num1 && tuple.Val <= labelCheck.Num2)
                    {
                        targetResult.CheckProcessEndTime   = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.CheckProcessStartTime = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.IsSuccessful          = true;
                        targetResult.Remarks = $"passed, value={tuple.Val}";
                        labelCheckResults[targetResultInd] = targetResult;
                    }
                    else if (tuple.Val == null)
                    {
                        targetResult.CheckProcessEndTime   = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.CheckProcessStartTime = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.IsSuccessful          = false;
                        targetResult.Remarks = "null value found";
                        labelCheckResults[targetResultInd] = targetResult;
                    }
                    else
                    {
                        targetResult.CheckProcessEndTime   = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.CheckProcessStartTime = ConvertIntToDateTime(tuple.TimeInt);
                        targetResult.IsSuccessful          = false;
                        targetResult.Remarks = $"limits violated, value={tuple.Val}";;
                        labelCheckResults[targetResultInd] = targetResult;
                    }
                }
            }
            return(labelCheckResults);
        }