public static void RefreshPuskStopData(DateTime DateStart, DateTime DateEnd) { DiagDBEntities diagDB = new DiagDBEntities(); for (int gg = 1; gg <= 10; gg++) { if (gg == 8) { continue; } IEnumerable <PuskStopInfo> reqGG = from r in diagDB.PuskStopInfoes where r.GG == gg && r.TypeData.StartsWith("GG_") && r.TimeOn <DateEnd && r.TimeOff> DateStart select r; Logger.Info(String.Format("GG {0} - {1}", gg, reqGG.Count())); foreach (PuskStopInfo rec in reqGG) { IEnumerable <PuskStopInfo> reqPI = from r in diagDB.PuskStopInfoes where r.GG == gg && (!r.TypeData.StartsWith("GG")) && r.TimeOn >= rec.TimeOn && r.TimeOff <= rec.TimeOff select r; Logger.Info(String.Format("GG {0} {1} - {2}", rec.TypeData, rec.TimeOn, reqPI.Count())); foreach (PuskStopInfo pi in reqPI) { if (!pi.Comment.Contains(rec.TypeData)) { pi.Comment += String.Format("{0}; ", rec.TypeData, rec.ID); } } } diagDB.SaveChanges(); } }
public static bool CheckCrossData(DateTime DateStart, DateTime DateEnd) { DiagDBEntities diagDB = new DiagDBEntities(); for (int gg = 1; gg <= 10; gg++) { if (gg == 8) { continue; } Logger.Info(String.Format("GG {0}", gg)); List <PuskStopInfo> data = ( from d in diagDB.PuskStopInfoes where d.TimeOn <= DateEnd && d.TimeOff >= DateStart && d.GG == gg && d.TypeData.Contains("GG") select d).ToList(); List <int> removedItems = new List <int>(); foreach (PuskStopInfo pi in data) { if (removedItems.Contains(pi.ID)) { continue; } IEnumerable <PuskStopInfo> crossData = from d in data where d.GG == pi.GG && d.TypeData == pi.TypeData && d.ID != pi.ID && (d.TimeOff >= pi.TimeOn && d.TimeOff <= pi.TimeOff || d.TimeOn >= pi.TimeOn && d.TimeOn <= pi.TimeOff) select d; if (crossData.Count() > 0) { Logger.Info(String.Format("Delete {0}", crossData.Count())); foreach (PuskStopInfo d in crossData) { removedItems.Add(d.ID); pi.TimeOn = d.TimeOn < pi.TimeOn ? d.TimeOn : pi.TimeOn; pi.TimeOff = d.TimeOff > pi.TimeOff ? d.TimeOff : pi.TimeOff; pi.Length = (pi.TimeOff - pi.TimeOn).TotalSeconds; diagDB.PuskStopInfoes.Remove(d); } } diagDB.SaveChanges(); } } return(true); }
public static async Task <bool> FillAnalogData(DateTime DateStart, DateTime DateEnd, List <string> Types) { DiagDBEntities diagDB = new DiagDBEntities(); for (int gg = 1; gg <= 10; gg++) { if (gg == 8) { continue; } try { EDSClass.Disconnect(); } catch { } EDSClass.Connect(); Logger.Info(string.Format("GG{0}", gg)); List <PuskStopPoint> points = (from p in diagDB.PuskStopPoints where p.gg == gg && p.analog == true && Types.Contains(p.pointType) select p).ToList(); List <AnalogData> existData = (from a in diagDB.AnalogDatas where a.gg == gg && Types.Contains(a.pointType) && a.Date >= DateStart && a.Date <= DateEnd select a).ToList(); Dictionary <string, string> pointsDict = new Dictionary <string, string>(); foreach (String type in Types) { try { PuskStopPoint pt = (from p in diagDB.PuskStopPoints where p.gg == gg && p.pointType == type select p).First(); pointsDict.Add(type, pt.point); } catch { pointsDict.Add(type, ""); } } List <PuskStopInfo> data = ( from d in diagDB.PuskStopInfoes where d.TimeOn <= DateEnd && d.TimeOff >= DateStart && d.GG == gg && d.TypeData.Contains("GG_RUN") select d).ToList(); foreach (PuskStopInfo ggRec in data) { Logger.Info(String.Format("GG {0} {1} -{2}", gg, ggRec.TimeOn, ggRec.TimeOff)); foreach (string type in Types) { if (string.IsNullOrEmpty(pointsDict[type])) { continue; } foreach (DateTime dt in new DateTime[] { ggRec.TimeOn, ggRec.TimeOff }) { IEnumerable <AnalogData> datas = (from a in existData where a.Date == dt && a.pointType == type select a); AnalogData dat = null; if (datas.Count() == 0) { dat = new AnalogData(); diagDB.AnalogDatas.Add(dat); dat.pointType = type; dat.gg = gg; dat.Date = dt; dat.value = await EDSClass.getValFromServer(pointsDict[type], dt); } else { dat = datas.First(); } } } diagDB.SaveChanges(); } DateTime date = DateTime.Parse(DateStart.ToString("dd.MM.yyyy HH:00")); while (date <= DateEnd) { Logger.Info(String.Format("GG {0} {1} ", gg, date)); if (gg == 5 && date < DateTime.Parse("01.06.2019")) { date = DateTime.Parse("01.06.2019"); continue; } if (gg == 3 && date < DateTime.Parse("07.05.2020")) { date = DateTime.Parse("07.05.2020"); continue; } if (gg == 1 && date < DateTime.Parse("21.04.2021")) { date = DateTime.Parse("21.04.2020"); continue; } foreach (string type in Types) { if (string.IsNullOrEmpty(pointsDict[type])) { continue; } IEnumerable <AnalogData> datas = (from a in existData where a.Date == date && a.pointType == type select a); AnalogData dat = null; if (datas.Count() == 0) { dat = new AnalogData(); diagDB.AnalogDatas.Add(dat); dat.pointType = type; dat.gg = gg; dat.Date = date; dat.value = await EDSClass.getValFromServer(pointsDict[type], date); } else { dat = datas.First(); } } date = date.AddHours(3); } } return(true); }
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); }
public static async void fillDBPoints() { List <PuskStopReader.PuskStopReaderRecord> request = new List <PuskStopReader.PuskStopReaderRecord>(); foreach (string gg in new string[] { "01", "04", "05", "07", "03" }) { int ggInt = Int32.Parse(gg); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_RUN", iess = gg + "VT_GC02D-45.MCR@GRARM", inverted = true, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_STOP", iess = gg + "VT_GC02D-45.MCR@GRARM", inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_UST", iess = gg + "VT_GC03D-01.MCR@GRARM", inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_1", iess = gg + "VT_PS01DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_2", iess = gg + "VT_PS02DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_3", iess = gg + "VT_PS03DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "LN_1", iess = gg + "VT_PS04DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00AI-07.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "LN_2", iess = gg + "VT_PS05DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00AI-07.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_1", iess = gg + "VT_DS01DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_2", iess = gg + "VT_DS02DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01.MCR@GRARM" }); } foreach (string gg in new string[] { "02", "06", "08", "09", "10" }) { int ggInt = Int32.Parse(gg); string suffix = ""; suffix = ggInt <= 2 ? ".UNIT01@BLOCK1" : ggInt <= 6 ? ".UNIT05@BLOCK3" : ggInt <= 8 ? ".UNIT07@BLOCK4" : ".UNIT09@BLOCK5"; request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_RUN", iess = gg + "VT_GC00D-115" + suffix, inverted = true, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_STOP", iess = gg + "VT_GC00D-115" + suffix, inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_UST", iess = gg + "VT_GC05D-01" + suffix, inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_1", iess = gg + "VT_PS01DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-11" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_2", iess = gg + "VT_PS02DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-11" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_3", iess = gg + "VT_PS03DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-11" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "LN_1", iess = gg + "VT_PS04DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS04AI-01" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_1", iess = gg + "VT_DS01DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_2", iess = gg + "VT_DS02DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01" + suffix }); } DiagDBEntities diagDB = new DiagDBEntities(); foreach (PuskStopReader.PuskStopReaderRecord rec in request) { string ggStr = rec.iess.Substring(0, 2); int gg = Int32.Parse(ggStr); string typeAnalog = "---"; if (!string.IsNullOrEmpty(rec.ValueIess)) { int pos = rec.DBRecord.IndexOf("_"); typeAnalog = rec.DBRecord.Substring(0, pos); } IEnumerable <PuskStopPoint> req = from p in diagDB.PuskStopPoints where p.gg == gg && (p.pointType == rec.DBRecord || p.pointType == typeAnalog) select p; if (req.Count() > 0) { foreach (PuskStopPoint p in req) { diagDB.PuskStopPoints.Remove(p); } diagDB.SaveChanges(); } PuskStopPoint pt = new PuskStopPoint(); pt.gg = gg; pt.inverted = rec.inverted; pt.pointType = rec.DBRecord; pt.point = rec.iess; pt.analog = false; diagDB.PuskStopPoints.Add(pt); if (!string.IsNullOrEmpty(rec.ValueIess)) { int pos = rec.DBRecord.IndexOf("_"); typeAnalog = rec.DBRecord.Substring(0, pos); pt = new PuskStopPoint(); pt.gg = gg; pt.inverted = false; pt.analog = true; pt.pointType = typeAnalog; pt.point = rec.ValueIess; diagDB.PuskStopPoints.Add(pt); } diagDB.SaveChanges(); } }