예제 #1
0
        protected static async Task <bool> UpdateValue(PuskStopData dataRecord, PuskStopReaderRecord readerRecord)
        {
            if (String.IsNullOrEmpty(readerRecord.ValueIess))
            {
                return(false);
            }
            double val0 = await EDSClass.getValFromServer(readerRecord.ValueIess, dataRecord.TimeOn);

            double val1 = await EDSClass.getValFromServer(readerRecord.ValueIess, dataRecord.TimeOff);

            dataRecord.ValueStart = val0;
            dataRecord.ValueEnd   = val1;
            return(true);
        }
예제 #2
0
        protected void UpdateGGData(string typeGG, AnalizeNasosData nasosData)
        {
            DiagDBEntities             diagDB = new DiagDBEntities();
            IEnumerable <PuskStopData> ggData = from g in FullGGData where g.TypeData.Contains(typeGG) select g;
            int sign = NasosType == "MNU" ? -1 : 1;

            foreach (PuskStopData ggRec in ggData)
            {
                if ((ggRec.TimeOff - ggRec.TimeOn).TotalHours < 1)
                {
                    continue;
                }
                SortedList <DateTime, double> vals = new SortedList <DateTime, double>();

                IEnumerable <AnalogData> innerData = (from a in diagDB.AnalogDatas
                                                      where
                                                      a.Date >= ggRec.TimeOn && a.Date <= ggRec.TimeOff &&
                                                      a.pointType == NasosType && a.gg == GG
                                                      orderby a.Date
                                                      select a);
                if (innerData.Count() > 0)
                {
                    foreach (AnalogData ad in innerData)
                    {
                        if (!vals.ContainsKey(ad.Date))
                        {
                            vals.Add(ad.Date, ad.value);
                        }
                    }
                }

                IEnumerable <PuskStopData> req = from nd in FullNasosData
                                                 where
                                                 (nd.TimeOn > ggRec.TimeOn && nd.TimeOn < ggRec.TimeOff) ||
                                                 (nd.TimeOff > ggRec.TimeOn && nd.TimeOff < ggRec.TimeOff)
                                                 orderby nd.TimeOn
                                                 select nd;
                if (req.Count() == 0)
                {
                    if (vals.Count >= 2)
                    {
                        double   v1 = vals.First().Value;
                        double   v2 = vals.Last().Value;
                        DateTime d1 = vals.First().Key;
                        DateTime d2 = vals.Last().Key;
                        nasosData.VInfo.AddV(d1, d2, v1, v2, sign);
                    }
                }
                else
                {
                    List <PuskStopData> list = req.ToList();
                    if (list.Count() > 0 && innerData.Count() > 0)
                    {
                        PuskStopData first = list.First();
                        if (first.TimeOn > vals.First().Key)
                        {
                            double   v1 = vals.First().Value;
                            double   v2 = first.ValueStart;
                            DateTime d1 = vals.First().Key;
                            DateTime d2 = first.TimeOn;
                            nasosData.VInfo.AddV(d1, d2, v1, v2, sign);
                        }
                        PuskStopData last = list.Last();
                        if (last.TimeOff < vals.Last().Key)
                        {
                            double   v1 = last.ValueEnd;
                            double   v2 = vals.Last().Value;
                            DateTime d1 = last.TimeOff;
                            DateTime d2 = vals.Last().Key;
                            double   v  = v2 - v1;
                            nasosData.VInfo.AddV(d1, d2, v1, v2, sign);
                        }
                    }
                }
            }
        }
예제 #3
0
        protected List <PuskStopData> createPuskStopData(string type_data, Dictionary <string, List <PuskStopData> > DiffData)
        {
            List <PuskStopData>        result = new List <PuskStopData>();
            DiagDBEntities             diagDB = new DiagDBEntities();
            IEnumerable <PuskStopInfo> req    =
                (from pi in diagDB.PuskStopInfoes
                 where
                 pi.GG == GG && pi.TypeData.Contains(type_data) &&
                 pi.TimeOff > DateStart && pi.TimeOn < DateEnd
                 orderby pi.TimeOn
                 select pi);



            PuskStopData prevData = null;
            PuskStopData last     = null;
            bool         first    = true;

            foreach (PuskStopInfo pi in req)
            {
                if (first && pi.TimeOn > DateStart)
                {
                    try
                    {
                        PuskStopInfo rf =
                            (from p in diagDB.PuskStopInfoes
                             where
                             p.GG == GG && p.TypeData.Contains(type_data) &&
                             p.TimeOff < DateStart
                             orderby p.TimeOff descending
                             select p).First();

                        prevData            = new PuskStopData();
                        prevData.TimeOff    = rf.TimeOff;
                        prevData.ValueStart = rf.ValueStart;
                        prevData.ValueEnd   = rf.ValueEnd;
                    }
                    catch { }
                }

                first = false;
                PuskStopData dat = new PuskStopData();
                dat.Length     = pi.Length;
                dat.TimeOn     = pi.TimeOn;
                dat.TimeOff    = pi.TimeOff;
                dat.ValueEnd   = pi.ValueEnd;
                dat.ValueStart = pi.ValueStart;
                dat.TypeData   = pi.TypeData;
                dat.Comment    = "";
                dat.PrevRecord = prevData;

                prevData = dat;

                result.Add(dat);

                if (DiffData != null && !DiffData.ContainsKey(pi.TypeData))
                {
                    DiffData.Add(pi.TypeData, new List <PuskStopData>());
                }
                DiffData[pi.TypeData].Add(dat);
                last = dat;
            }



            return(result);
        }
예제 #4
0
        public static async Task <List <PuskStopData> > AnalizePuskStopData(string pointName, DateTime dateStart, DateTime dateEnd, bool inverted)
        {
            List <PuskStopData> result = new List <PuskStopData>();

            try
            {
                DateTime ds = dateStart.AddSeconds(0);
                DateTime de = dateEnd.AddSeconds(0);

                double val0 = await EDSClass.getValFromServer(pointName, ds);

                if ((inverted && val0 < 0.5) || (!inverted && val0 > 0.9))
                {
                    PuskStopData record = new PuskStopData();
                    DateTime     dt     = await EDSClass.getValNextDate(pointName, ds, de, inverted? "F_INTOOVER_DT" : "F_INTOUNDER_DT", 0.5);

                    if (dt > ds && dt < de)
                    {
                        ds             = dt;
                        record.TimeOn  = dateStart;
                        record.TimeOff = dt;
                        result.Add(record);
                    }
                    else
                    {
                        record.TimeOn  = dateStart;
                        record.TimeOff = dateEnd;
                        result.Add(record);
                        return(result);
                    }
                }
                while (ds < de)
                {
                    PuskStopData record = new PuskStopData();
                    DateTime     dt     = await EDSClass.getValNextDate(pointName, ds.AddSeconds(1), de, inverted? "F_INTOUNDER_DT" : "F_INTOOVER_DT", 0.5);

                    Logger.Info(String.Format("Pusk {0}", dt));
                    if (dt > ds && dt < de)
                    {
                        record.TimeOn = dt;
                        DateTime dt1 = await EDSClass.getValNextDate(pointName, dt.AddSeconds(1), de, inverted? "F_INTOOVER_DT" : "F_INTOUNDER_DT", 0.5);

                        Logger.Info(String.Format("Stop {0}", dt1));
                        if (dt1 > dt && dt1 < de)
                        {
                            record.TimeOff = dt1;
                            record.Length  = (int)(record.TimeOff - record.TimeOn).TotalSeconds;
                            result.Add(record);
                            record = new PuskStopData();
                            ds     = dt1.AddSeconds(1);
                        }
                        else
                        {
                            record.TimeOff = dateEnd;
                            record.Length  = (int)(record.TimeOff - record.TimeOn).TotalSeconds;
                            result.Add(record);
                            return(result);
                        }
                    }
                    else
                    {
                        return(result);
                    }
                }
                return(result);
            }
            catch
            {
                return(result);
            }
        }
예제 #5
0
        public async static Task <bool> FillPuskStopData(List <PuskStopReaderRecord> reqList, DateTime dateStart, DateTime dateEnd)
        {
            try
            {
                EDSClass.Disconnect();
            }
            catch { }
            EDSClass.Connect();
            if (!EDSClass.Connected)
            {
                return(false);
            }

            /*bool ok = await RefreshLevelsMNU(reqList, dateStart, dateEnd);
             * return ok;*/

            SortedList <int, List <PuskStopData> > FullResult = await AnalizePuskStopDataFull(reqList, dateStart, dateEnd);


            for (int index = 0; index < reqList.Count; index++)
            {
                List <PuskStopData>  data      = FullResult[index];
                PuskStopReaderRecord reqRecord = reqList[index];
                int    gg       = reqRecord.gg;
                string typeData = reqRecord.DBRecord;

                if (data.Count > 0)
                {
                    DiagDBEntities diagDB = new DiagDBEntities();

                    PuskStopData first = data.First();
                    PuskStopData last  = data.Last();
                    IQueryable <PuskStopInfo> reqFirst = from pi in diagDB.PuskStopInfoes where pi.GG == gg && pi.TypeData == typeData && pi.TimeOff == first.TimeOn select pi;

                    if (reqFirst.Count() > 0)
                    {
                        PuskStopInfo firstDB = reqFirst.First();
                        firstDB.TimeOff  = first.TimeOff;
                        firstDB.Length   = (firstDB.TimeOff - firstDB.TimeOn).TotalSeconds;
                        firstDB.ValueEnd = first.ValueEnd;

                        diagDB.SaveChanges();

                        if (data.Count > 1)
                        {
                            data.RemoveAt(0);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    IQueryable <PuskStopInfo> reqLast = from pi in diagDB.PuskStopInfoes where pi.GG == gg && pi.TypeData == typeData && pi.TimeOn == last.TimeOff select pi;
                    if (reqLast.Count() > 0)
                    {
                        PuskStopInfo lastDB = reqLast.First();
                        lastDB.TimeOn     = last.TimeOn;
                        lastDB.Length     = (lastDB.TimeOff - lastDB.TimeOn).TotalSeconds;
                        lastDB.ValueStart = last.ValueStart;
                        diagDB.SaveChanges();
                        if (data.Count > 0)
                        {
                            data.Remove(last);
                        }
                        else
                        {
                            continue;
                        }
                    }



                    IQueryable <PuskStopInfo>           req    = from pi in diagDB.PuskStopInfoes where pi.GG == gg && pi.TypeData == typeData && pi.TimeOn > dateStart && pi.TimeOn <= dateEnd select pi;
                    SortedList <DateTime, PuskStopInfo> dataDB = new SortedList <DateTime, PuskStopInfo>();
                    foreach (PuskStopInfo pi in req)
                    {
                        if (!dataDB.ContainsKey(pi.TimeOn))
                        {
                            dataDB.Add(pi.TimeOn, pi);
                        }
                    }

                    foreach (PuskStopData rec in data)
                    {
                        PuskStopInfo recDB = new PuskStopInfo();
                        if (dataDB.ContainsKey(rec.TimeOn))
                        {
                            recDB = dataDB[rec.TimeOn];
                        }

                        recDB.GG         = gg;
                        recDB.TypeData   = typeData;
                        recDB.TimeOn     = rec.TimeOn;
                        recDB.TimeOff    = rec.TimeOff;
                        recDB.Length     = rec.Length;
                        recDB.ValueEnd   = rec.ValueEnd;
                        recDB.ValueStart = rec.ValueStart;
                        recDB.Comment    = "";

                        if (!dataDB.ContainsKey(rec.TimeOn))
                        {
                            diagDB.PuskStopInfoes.Add(recDB);
                        }
                    }
                    diagDB.SaveChanges();
                }
            }

            return(true);
        }
예제 #6
0
        public static async Task <SortedList <int, List <PuskStopData> > > AnalizePuskStopDataFull(List <PuskStopReaderRecord> req, DateTime dateStart, DateTime dateEnd)
        {
            EDSReport report = new EDSReport(dateStart, dateEnd, EDSReportPeriod.sec);
            Dictionary <string, EDSReportRequestRecord> records = new Dictionary <string, EDSReportRequestRecord>();

            foreach (PuskStopReaderRecord de in req)
            {
                EDSReportRequestRecord pointRec = null;
                if (!records.ContainsKey(de.iess))
                {
                    EDSPointInfo point = await EDSPointInfo.GetPointInfo(de.iess);

                    pointRec = report.addRequestField(point, EDSReportFunction.val);
                    records.Add(de.iess, pointRec);
                }
                else
                {
                    pointRec = records[de.iess];
                }
                de.rec = pointRec;

                if (!String.IsNullOrEmpty(de.ValueIess) && !records.ContainsKey(de.ValueIess))
                {
                    EDSPointInfo point = await EDSPointInfo.GetPointInfo(de.ValueIess);

                    pointRec = report.addRequestField(point, EDSReportFunction.val);
                    records.Add(de.ValueIess, pointRec);
                }
            }
            bool ok = await report.ReadData();

            List <DateTime> keys = report.ResultData.Keys.ToList();

            SortedList <int, List <PuskStopData> > FullResult = new SortedList <int, List <PuskStopData> >();

            foreach (PuskStopReaderRecord readField in req)
            {
                bool inverted = readField.inverted;
                List <PuskStopData> result = new List <PuskStopData>();
                FullResult.Add(FullResult.Count, result);
                SortedList <DateTime, double> data = new SortedList <DateTime, double>();
                foreach (DateTime dt in keys)
                {
                    data.Add(dt, report.ResultData[dt][readField.rec.Id]);
                }
                double val0 = data.Values.First();

                PuskStopData record = new PuskStopData();

                DateTime ds = dateStart.AddSeconds(0);
                if ((inverted && val0 < 0.5) || (!inverted && val0 > 0.9))
                {
                    try
                    {
                        DateTime dt = inverted ? data.First(de => de.Value > 0.5).Key : data.First(de => de.Value < 0.5).Key;
                        record.TimeOff = dt;
                        record.TimeOn  = dateStart;
                        record.Length  = (dt - dateStart).TotalSeconds;
                        ds             = dt.AddSeconds(0);
                        result.Add(record);
                    }
                    catch
                    {
                        record.TimeOn  = dateStart;
                        record.TimeOff = dateEnd;
                        record.Length  = (dateEnd - dateStart).TotalSeconds;
                        result.Add(record);
                        continue;
                    }
                }

                while (ds <= dateEnd)
                {
                    try
                    {
                        DateTime dt = inverted ? data.First(de => de.Key > ds && de.Value < 0.5).Key :
                                      data.First(de => de.Key > ds && de.Value > 0.5).Key;
                        record        = new PuskStopData();
                        record.TimeOn = dt;
                        try
                        {
                            DateTime dt1 = inverted ? data.First(de => de.Key > dt && de.Value > 0.5).Key :
                                           data.First(de => de.Key > dt && de.Value < 0.5).Key;
                            record.TimeOff = dt1;
                            record.Length  = (record.TimeOff - record.TimeOn).TotalSeconds;
                            result.Add(record);
                            ds = dt1.AddSeconds(0);
                        }
                        catch
                        {
                            record.TimeOff = dateEnd;
                            record.Length  = (record.TimeOff - record.TimeOn).TotalSeconds;
                            result.Add(record);
                            break;
                        }
                    }
                    catch
                    {
                        break;
                    }
                }
            }
            for (int i = 0; i < FullResult.Keys.Count; i++)
            {
                List <PuskStopData>  data   = FullResult[i];
                PuskStopReaderRecord reqRec = req[i];
                if (String.IsNullOrEmpty(reqRec.ValueIess))
                {
                    continue;
                }
                EDSReportRequestRecord requestRecord = records[reqRec.ValueIess];
                foreach (PuskStopData pi in data)
                {
                    if (report.ResultData.Keys.Contains(pi.TimeOn))
                    {
                        pi.ValueStart = report.ResultData[pi.TimeOn][requestRecord.Id];
                    }
                    else
                    {
                        pi.ValueStart = await EDSClass.getValFromServer(reqRec.ValueIess, pi.TimeOn);
                    }

                    if (report.ResultData.Keys.Contains(pi.TimeOff))
                    {
                        pi.ValueEnd = report.ResultData[pi.TimeOff][requestRecord.Id];
                    }
                    else
                    {
                        pi.ValueEnd = await EDSClass.getValFromServer(reqRec.ValueIess, pi.TimeOff);
                    }
                }
            }

            return(FullResult);
        }