public void Start(DateValuePair Start) { this.Current = Start; CurrentStep = Start.Date; AccumulatedValue = 0.0D; CurrentTime = Start.Date; fFirst = false; }
public DateValuePair Finish() { if (Current.Date == CurrentStep) return null; DateValuePair dvp = new DateValuePair() { Date = CurrentStep.Add(Step), Value = Current.Value }; var ret = Push(dvp); return ret[0]; }
public static System.Collections.IEnumerable TimeNormalize(SqlString statement, SqlInt32 days, SqlInt32 hours, SqlInt32 minutes, SqlInt32 seconds, SqlInt32 milliseconds) { using (SqlConnection conn = new SqlConnection("context connection = true")) { conn.Open(); List<DateValuePair> lDVPs = new List<DateValuePair>(); StreamNormalizer sn = new StreamNormalizer(new TimeSpan( days.Value, hours.Value, minutes.Value, seconds.Value, milliseconds.Value)); using (SqlCommand cmd = new SqlCommand(statement.Value, conn)) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (!(reader[0] is DateTime)) throw new ArgumentException("Field 0 must be a " + typeof(DateTime).FullName + ". It is " + reader[0].GetType().FullName + " instead."); DateValuePair dvp = new DateValuePair { Date = reader.GetDateTime(0) }; object oVal = reader[1]; try { if (oVal is Int32) dvp.Value = (int)oVal; else if (oVal is double) dvp.Value = (double)oVal; else dvp.Value = Decimal.ToDouble((Decimal)oVal); } catch (Exception exce) { throw new ArgumentException("Field 1 must be a numeric value. It is " + oVal.GetType().FullName + " instead. (Internal exception: " + exce.Message + ")."); } lDVPs.AddRange(sn.Push(dvp)); } } } DateValuePair dvpFinish = sn.Finish(); if (dvpFinish != null) lDVPs.Add(dvpFinish); return lDVPs; } }
public DateValuePair Finish() { if (Current.Date == CurrentStep) { return(null); } DateValuePair dvp = new DateValuePair() { Date = CurrentStep.Add(Step), Value = Current.Value }; var ret = Push(dvp); return(ret[0]); }
public List <DateValuePair> Push(DateValuePair dvp) { List <DateValuePair> lDVPs = new List <DateValuePair>(); if (fFirst) { Start(dvp); // Add itself as first event lDVPs.Add(dvp); return(lDVPs); } DateTime NextStep = CurrentStep.Add(Step); while (dvp.Date >= NextStep) { double dUsedMS = Math.Min((NextStep - CurrentTime).TotalMilliseconds, 1000); AccumulatedValue += (dUsedMS * Current.Value) / 1000.0D; lDVPs.Add(new DateValuePair(-1) { Date = NextStep, Value = AccumulatedValue }); AccumulatedValue = 0; CurrentStep = NextStep; CurrentTime = NextStep; NextStep = NextStep.Add(Step); } double dRemainining = Math.Min((dvp.Date - CurrentTime).TotalMilliseconds, 1000); AccumulatedValue += (dRemainining * Current.Value) / 1000.0D; CurrentTime = dvp.Date; Current = dvp; return(lDVPs); }
public List<DateValuePair> Push(DateValuePair dvp) { List<DateValuePair> lDVPs = new List<DateValuePair>(); if (fFirst) { Start(dvp); // Add itself as first event lDVPs.Add(dvp); return lDVPs; } DateTime NextStep = CurrentStep.Add(Step); while (dvp.Date >= NextStep) { double dUsedMS = Math.Min((NextStep - CurrentTime).TotalMilliseconds, 1000); AccumulatedValue += (dUsedMS * Current.Value) / 1000.0D; lDVPs.Add(new DateValuePair(-1) { Date = NextStep, Value = AccumulatedValue }); AccumulatedValue = 0; CurrentStep = NextStep; CurrentTime = NextStep; NextStep = NextStep.Add(Step); } double dRemainining = Math.Min((dvp.Date - CurrentTime).TotalMilliseconds, 1000); AccumulatedValue += (dRemainining * Current.Value) / 1000.0D; CurrentTime = dvp.Date; Current = dvp; return lDVPs; }
public void Start(DateValuePair Start) { this.Current = Start; CurrentStep = Start.Date; AccumulatedValue = 0.0D; CurrentTime = Start.Date; fFirst = false; }