Ejemplo n.º 1
0
        public static void ProcessLabelCheck(string labelsConnStr, string connStr, LabelCheck labelCheck, DateTime fromTime, DateTime toTime)
        {
            DbContextOptionsBuilder <LabelChecksDbContext> builder = new DbContextOptionsBuilder <LabelChecksDbContext>().UseSqlServer(labelsConnStr);
            LabelChecksDbContext labelChecksDbContext = new LabelChecksDbContext(builder.Options);

            ProcessLabelCheck(labelChecksDbContext, connStr, labelCheck, fromTime, toTime);
        }
Ejemplo n.º 2
0
        /*
         * public static void SetLabelSeeds(LabelChecksDbContext labelChecksDbContext)
         * {
         *  List<string> labels = new List<string>
         *  {
         *      "gujarat_thermal_mu", "maharashtra_thermal_mu"
         *  };
         *
         *  int labelIdCounter = 0;
         *  for (int labelIter = 0; labelIter < labels.Count; labelIter++)
         *  {
         *      PspMeasurement meas = labelChecksDbContext.PspDbMeasurements.First(m => m.Label == labels.ElementAt(labelIter));
         *      if (meas == null)
         *      {
         *          continue;
         *      }
         *      labelChecksDbContext.LabelChecks.Add(new LabelCheck
         *      {
         *          Id = labelIdCounter++,
         *          PspMeasurement = meas,
         *          CheckType = LabelCheckUtils.CheckTypeNotNull
         *      });
         *  }
         * }
         */

        public static LabelCheck[] GetLabelSeeds()
        {
            LabelCheck[] labelChecks = new LabelCheck[] {
                new LabelCheck {
                    Id = 1,
                    PspMeasurementId = 1,
                    CheckType        = LabelCheckUtils.CheckTypeNotNull
                },
                new LabelCheck {
                    Id = 2,
                    PspMeasurementId = 2,
                    CheckType        = LabelCheckUtils.CheckTypeNotNull
                }
            };

            return(labelChecks);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public static void ProcessLabelCheck(LabelChecksDbContext labelChecksDbContext, string connStr, LabelCheck labelCheck, DateTime fromTime, DateTime toTime)
        {
            PspMeasurement meas = labelChecksDbContext.PspDbMeasurements.Where(m => m.MeasId == labelCheck.PspMeasurementId).FirstOrDefault();

            labelCheck.PspMeasurement = meas;
            List <LabelCheckResult> labelCheckResults = GetLabelCheckResults(connStr, labelCheck, fromTime, toTime);

            //iterate through each result, find if record already exists and update the database
            for (int resIter = 0; resIter < labelCheckResults.Count; resIter++)
            {
                LabelCheckResult targetRes = labelCheckResults[resIter];
                LabelCheckResult foundRes  = labelChecksDbContext.LabelCheckResults.Where(res => res.LabelCheckId == targetRes.LabelCheckId &&
                                                                                          res.CheckProcessEndTime.Date == targetRes.CheckProcessEndTime.Date &&
                                                                                          res.CheckProcessStartTime.Date == targetRes.CheckProcessStartTime.Date).FirstOrDefault();
                if (foundRes == null)
                {
                    // the record doesnot exist, so insert into the db
                    labelChecksDbContext.LabelCheckResults.Add(targetRes);
                }
                else
                {
                    //targetRes.Id = foundRes.Id;
                    // make found result as target result and update
                    foundRes.IsSuccessful          = targetRes.IsSuccessful;
                    foundRes.Remarks               = targetRes.Remarks;
                    foundRes.CheckProcessEndTime   = targetRes.CheckProcessEndTime;
                    foundRes.CheckProcessStartTime = targetRes.CheckProcessStartTime;
                    labelChecksDbContext.LabelCheckResults.Update(foundRes);
                }
            }
            labelChecksDbContext.SaveChanges();
        }