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); } }