public void ValueTest() { TimespanValue tsv = new TimespanValue(new Timespan(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2)), 3.3); tsv.Value = 6.7; Assert.AreEqual(6.7, tsv.Value); }
public void StartTimeTest() { TimespanValue tsv = new TimespanValue(new Timespan(new DateTime(2010, 2, 1), new DateTime(2010, 2, 2)), 3.3); tsv.StartTime = new DateTime(2010, 1, 5); Assert.AreEqual(new DateTime(2010, 1, 5), tsv.StartTime); }
public void TimeSpanTest() { TimespanValue tsv = new TimespanValue(new Timespan(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2)), 3.3); tsv.TimeSpan = new Timespan(new DateTime(2010, 2, 1), new DateTime(2010, 2, 2)); Assert.AreEqual(new DateTime(2010, 2, 1), tsv.TimeSpan.Start); Assert.AreEqual(new DateTime(2010, 2, 2), tsv.TimeSpan.End); }
public void TimespanValue3() { TimespanValue tsv = new TimespanValue(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2), 5.6); Assert.AreEqual(tsv.Value, 5.6); Assert.AreEqual(tsv.StartTime, new DateTime(2010, 1, 1)); Assert.AreEqual(tsv.EndTime, new DateTime(2010, 1, 2)); }
public void TimespanValue() //TimespanValue(TimeSpan timespan, double value) { TimespanValue tsv = new TimespanValue(new Timespan(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2)), 3.3); Assert.AreEqual(tsv.Value, 3.3); Assert.AreEqual(tsv.StartTime, new DateTime(2010, 1, 1)); Assert.AreEqual(tsv.EndTime, new DateTime(2010, 1, 2)); }
public override int GetHashCode() { unchecked { int result = Type.GetHashCode(); result = (result * 397) ^ DoubleValue.GetHashCode(); result = (result * 397) ^ TimespanValue.GetHashCode(); result = (result * 397) ^ (StringValue != null ? StringValue.GetHashCode() : 0); return(result); } }
private void Summarize(int MaxCount, BaseTimeSeries bts) { TimespanSeries tspan = bts as TimespanSeries; TimestampSeries tstam = bts as TimestampSeries; if (tspan != null) { if (tspan.Items.Count > MaxCount) { List <TimespanValue> temp = new List <TimespanValue>(); DateTime Start = tspan.Items.First().StartTime; DateTime End = tspan.Items.Last().EndTime; double periodDays = End.Subtract(Start).TotalDays / MaxCount; for (int i = 0; i < MaxCount; i++) { TimespanValue TValue = new TimespanValue(Start.AddDays(i * periodDays), Start.AddDays((i + 1) * periodDays), 0); TValue.Value = tspan.GetValue(TValue.StartTime, TValue.EndTime); temp.Add(TValue); } tspan.Items.Clear(); foreach (var v in temp) { tspan.Items.Add(v); } } } if (tstam != null) { if (tstam.Items.Count > MaxCount) { List <TimestampValue> temp = new List <TimestampValue>(); DateTime Start = tstam.Items.First().Time; DateTime End = tstam.Items.Last().Time; double periodDays = End.Subtract(Start).TotalDays / MaxCount; for (int i = 0; i < MaxCount; i++) { TimestampValue TValue = new TimestampValue(Start.AddDays(i * periodDays), 0); TValue.Value = tstam.GetValue(TValue.Time); temp.Add(TValue); } tstam.Items.Clear(); foreach (var v in temp) { tstam.Items.Add(v); } } } }
public void TimespanValue1() //TimespanValue(TimespanValue obj) { TimespanValue tsv1 = new TimespanValue(); tsv1.StartTime = new DateTime(2010, 1, 1); tsv1.EndTime = new DateTime(2010, 1, 2); tsv1.Value = 4.5; TimespanValue tsv2 = new TimespanValue(tsv1); Assert.AreEqual(tsv1.Value, tsv2.Value); Assert.AreEqual(tsv1.StartTime, tsv2.StartTime); Assert.AreEqual(tsv1.EndTime, tsv2.EndTime); }
public void Equals() { TimespanValue tsv1 = new TimespanValue(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2), 5.5); TimespanValue tsv2 = new TimespanValue(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2), 5.5); Assert.AreEqual(tsv1, tsv2); tsv2.EndTime = new DateTime(2010, 1, 3); Assert.AreNotEqual(tsv1, tsv2); tsv2 = new TimespanValue(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2), 5.5); Assert.AreEqual(tsv1, tsv2); tsv2.StartTime = new DateTime(2009, 12, 31); Assert.AreNotEqual(tsv1, tsv2); tsv2 = new TimespanValue(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2), 5.5); Assert.AreEqual(tsv1, tsv2); tsv2.Value = 44; Assert.AreNotEqual(tsv1, tsv2); }
public override string ToString() { switch (Type) { case UniversalClassType.Numeric: return(DoubleValue.ToString(CultureInfo.InvariantCulture)); case UniversalClassType.TimeSpan: return(TimespanValue.ToString()); case UniversalClassType.String: return(StringValue); default: throw new Exception("Unknown type " + Type); } }
/// <summary> /// Distributes the extractions evenly on the active intakes /// </summary> public void DistributeExtraction(bool clearFirst) { Extractions.Sort(); //The function to determine if an intake is active //The well should be a pumping well and start and end date should cover the year Func <PumpingIntake, int, bool> IsActive = new Func <PumpingIntake, int, bool>((var, var2) => var.Intake.well.UsedForExtraction & (var.StartNullable ?? DateTime.MinValue).Year <= var2 & (var.EndNullable ?? DateTime.MaxValue).Year >= var2); double[] fractions = new double[Extractions.Items.Count()]; //Calculate the fractions based on how many intakes are active for a particular year. for (int i = 0; i < Extractions.Items.Count(); i++) { int CurrentYear = Extractions.Items[i].StartTime.Year; fractions[i] = 1.0 / PumpingIntakes.Count(var => IsActive(var, CurrentYear)); } //Now loop the extraction values for (int i = 0; i < Extractions.Items.Count(); i++) { TimespanValue tsv = new TimespanValue(Extractions.Items[i].StartTime, Extractions.Items[i].EndTime, Extractions.Items[i].Value * fractions[i]); //Now loop the intakes foreach (PumpingIntake PI in PumpingIntakes) { IIntake I = PI.Intake; if (clearFirst) { I.Extractions.Items.Clear(); } //Is it an extraction well? if (IsActive(PI, Extractions.Items[i].StartTime.Year)) { I.Extractions.AddValue(tsv.StartTime, tsv.EndTime, tsv.Value); } } } }
public void NotifyPropertyChangedTest() { TimespanValue tsv = new TimespanValue(new DateTime(2010, 1, 1), new DateTime(2010, 1, 2), 5.6); tsv.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(tsv_PropertyChanged); propertyChanged = false; changedProperty = ""; tsv.StartTime = new DateTime(2009, 12, 31); Assert.IsTrue(propertyChanged); Assert.AreEqual("StartTime", changedProperty); changedProperty = ""; propertyChanged = false; tsv.EndTime = new DateTime(2010, 12, 31); Assert.IsTrue(propertyChanged); Assert.AreEqual("EndTime", changedProperty); changedProperty = ""; propertyChanged = false; tsv.Value = 99; Assert.IsTrue(propertyChanged); Assert.AreEqual("Value", changedProperty); }
public void TimespanValue2() { TimespanValue tsv = new TimespanValue(); }