예제 #1
0
 public ExchangeItem(string location, string quantity, Unit unit, TimeType timetype)
   {
     Location = location;
     Quantity = quantity;
     this.Unit = unit;
     this.timeType = timeType;
   }
예제 #2
0
 public override void ConvertUnit(HydroNumerics.Core.Unit newUnit)
 {
     foreach (TimespanValue timespanValue in items)
     {
         timespanValue.Value = this.unit.FromThisUnitToUnit(timespanValue.Value, newUnit);
     }
     this.unit = new Unit(newUnit);
 }
예제 #3
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">The unit to copy</param>
 public Unit(Unit source)
 {
   Description = source.Description;
   ID = source.ID;
   ConversionFactorToSI = source.ConversionFactorToSI;
   OffSetToSI = source.OffSetToSI;
   this.dimension = new Dimension(source.Dimension);
   this.dimension.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(dimension_PropertyChanged);
 }
예제 #4
0
        public void ConvertUnit()
        {
            TimespanSeries timeSeries = new TimespanSeries();

            timeSeries.Items.Add(new TimespanValue(new DateTime(2010, 1, 3, 0, 0, 0), new DateTime(2010, 1, 4, 0, 0, 0), 2));
            timeSeries.Items.Add(new TimespanValue(new DateTime(2010, 1, 4, 0, 0, 0), new DateTime(2010, 1, 6, 0, 0, 0), 4));
            timeSeries.Items.Add(new TimespanValue(new DateTime(2010, 1, 6, 0, 0, 0), new DateTime(2010, 1, 7, 0, 0, 0), 8));
            timeSeries.Unit = new HydroNumerics.Core.Unit("Decimenters", 0.1, 0.0);
            HydroNumerics.Core.Unit newUnit = new HydroNumerics.Core.Unit("centimeters", 0.01, 0.0);
            timeSeries.ConvertUnit(newUnit);
            Assert.AreEqual("centimeters", timeSeries.Unit.ID);
            Assert.AreEqual(0.01, timeSeries.Unit.ConversionFactorToSI);
            Assert.AreEqual(20, timeSeries.Items[0].Value);
            Assert.AreEqual(40, timeSeries.Items[1].Value);
            Assert.AreEqual(80, timeSeries.Items[2].Value);
        }
예제 #5
0
 /// <summary>
 /// Converts the value provided as argument for this method from this unit to the unit
 /// provided in the argument list. The value provided must be defined by this unit.
 /// </summary>
 /// <param name="value">value (in the unit of this unit)</param>
 /// <param name="toUnit">the unit to which the value is converted</param>
 /// <returns></returns>
 public double FromThisUnitToUnit(double valueInThisUnit, Unit toUnit)
 {
   double xSI = ToSiUnit(valueInThisUnit);
   return (xSI - toUnit.OffSetToSI) / toUnit.ConversionFactorToSI;
 }
예제 #6
0
 public void FromUnitToThisUnit()
 {
     Unit thisUnit = new Unit("ThisUnit", 10, 5);
     Unit fromUnit = new Unit("FromUnit", 3, 8);
     Assert.AreEqual(5.4, thisUnit.FromUnitToThisUnit(17.0, fromUnit));
 }
예제 #7
0
 public TimestampSeries2(string name, DateTime startTime, int numberOfTimesteps, int timestepLength, TimestepUnit timestepLengthUnit, double defaultValue, Unit unit) : this (name, startTime, numberOfTimesteps, timestepLength, timestepLengthUnit, defaultValue)
 {
     this.unit = unit;
 }
예제 #8
0
        public void UnitConstructorTest3()
        {
            Unit unitA = new Unit("something", 3.4, 17.4, "somedescription");
            unitA.Dimension = new Dimension(1, 2, 3, 4, 5, 6, 7, 8);
            Unit unitB = new Unit(unitA);
            Assert.AreEqual("somedescription", unitB.Description);
            Assert.AreEqual(3.4, unitB.ConversionFactorToSI);
            Assert.AreEqual(17.4, unitB.OffSetToSI);
            Assert.IsTrue(unitB.Dimension.Equals(new Dimension(1, 2, 3, 4, 5, 6, 7, 8)));
            Assert.AreEqual("something", unitB.ID);

            try
            {
                unitA = new Unit("something", 0, 17.4, "somedescription");
            }
            catch (System.Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(System.Exception));
            }
        }
예제 #9
0
   public void UnitConstructorTest2()
   {
       Unit unit = new Unit("something", 3.4, 17.4, "somedescription");
       Assert.AreEqual("somedescription", unit.Description);
       Assert.AreEqual(3.4, unit.ConversionFactorToSI);
       Assert.AreEqual(17.4, unit.OffSetToSI);
       Assert.IsTrue(unit.Dimension.Equals(new Dimension(0, 0, 0, 0, 0, 0, 0, 0)));
       Assert.AreEqual("something", unit.ID);
 
   }
        public override IValueSet GetValues(ITime time, string LinkID)
        {
            if (!initializeWasInvoked)
            {
                throw new Exception("Method \"GetValues\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked");
            }

            ILink link = this.GetLink(LinkID);
            SendSourceAfterGetValuesCallEvent(time, link);

            // -- handle incoming links (where this component is the target)
            if (!isBusy) //avoiding deadlocks 
            {
                isBusy = true;
                foreach (ILink acceptingLink in _acceptingLinks)
                {
                    if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimestampSeries)
                    {
                        TimestampSeries timestampSeries = (TimestampSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimestampValue timestampValue in timestampSeries.Items)
                        {
                            TimeStamp getValuesTime = new TimeStamp(timestampValue.Time);
                            SendTargetBeforeGetValuesCall(getValuesTime, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(getValuesTime, acceptingLink.ID);
                            timestampValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timestampValue.Value, acceptingLink);
                        }
                    }
                    else if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimespanSeries)
                    {
                        TimespanSeries timespanSeries = (TimespanSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimespanValue timespanValue in timespanSeries.Items)
                        {
                            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.StartTime), new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.EndTime));
                            SendTargetBeforeGetValuesCall(timeSpan, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(timeSpan, acceptingLink.ID);
                            timespanValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timespanValue.Value, acceptingLink);
                        }
                    }
                    else
                    {
                        throw new Exception("Unexpected exception : Undefined timeseries type (occured in HydroNumerics.Time.OpenMI.LinkableTimeSeriesGroup class)");
                    }
                }
                isBusy = false;
            }

            // -- handle outgoing links (where this component is the source)
            HydroNumerics.Core.Unit toUnit = new HydroNumerics.Core.Unit();
            toUnit.ConversionFactorToSI = link.TargetQuantity.Unit.ConversionFactorToSI;
            toUnit.OffSetToSI = link.TargetQuantity.Unit.OffSetToSI;

            if (time is ITimeStamp)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp t = new TimeStamp((ITimeStamp)time);

                double x = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(t.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return scalarSet;
            }
            else
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp start = new TimeStamp(((ITimeSpan)time).Start);
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp end = new TimeStamp(((ITimeSpan)time).End);

                double x = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(start.ToDateTime(), end.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return scalarSet;
            }
        }
예제 #11
0
 public double GetValue(DateTime fromTime, DateTime toTime, Unit toUnit)
 {
     double x = GetValue(fromTime, toTime);
     return this.unit.FromThisUnitToUnit(x, toUnit);
 }
예제 #12
0
 public BaseTimeSeries(string name, Unit unit) : this()
 {
     this.Unit = unit;
     this.name = name;
 }
예제 #13
0
        public void UnitConstructorTest1()
        {
            Unit unit = new Unit("something", 3.4, 17.4);
            Assert.AreEqual("", unit.Description);
            Assert.AreEqual(3.4, unit.ConversionFactorToSI);
            Assert.AreEqual(17.4, unit.OffSetToSI);
            Assert.IsTrue(unit.Dimension.Equals(new Dimension(0, 0, 0, 0, 0, 0, 0, 0)));
            Assert.AreEqual("something", unit.ID);

            try
            {
                unit = new Unit("something", 0, 17.4);
            }
            catch (System.Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(System.Exception));
            }
        }
예제 #14
0
 public void ToSiUnit()
 {
     Unit thisUnit = new Unit("ThisUnit", 10, 5);
     Assert.AreEqual(175, thisUnit.ToSiUnit(17));
 }
예제 #15
0
 public void FromSiToThisUnit()
 {
     Unit thisUnit = new Unit("ThisUnit", 10, 5);
     Assert.AreEqual(1.2, thisUnit.FromSiToThisUnit(17.0));
 }
예제 #16
0
 public void OffSetToSITest()
 {
     Unit unit = new Unit();
     unit.OffSetToSI = 232;
     Assert.AreEqual(232, unit.OffSetToSI);
 }
예제 #17
0
 public void UnitConstructorTest()
 {
     Unit unit = new Unit();
     Assert.AreEqual("", unit.Description);
     Assert.AreEqual(1.0, unit.ConversionFactorToSI);
     Assert.AreEqual(0, unit.OffSetToSI);
     Assert.IsTrue(unit.Dimension.Equals(new Dimension(0,0,0,0,0,0,0,0)));
     Assert.AreEqual("", unit.ID);
 }
예제 #18
0
 public void ConvertUnit()
 {
     TimespanSeries timeSeries = new TimespanSeries();
     timeSeries.Items.Add(new TimespanValue(new DateTime(2010, 1, 3, 0, 0, 0), new DateTime(2010, 1, 4, 0, 0, 0), 2));
     timeSeries.Items.Add(new TimespanValue(new DateTime(2010, 1, 4, 0, 0, 0), new DateTime(2010, 1, 6, 0, 0, 0), 4));
     timeSeries.Items.Add(new TimespanValue(new DateTime(2010, 1, 6, 0, 0, 0), new DateTime(2010, 1, 7, 0, 0, 0), 8));
     timeSeries.Unit = new HydroNumerics.Core.Unit("Decimenters", 0.1, 0.0);
     HydroNumerics.Core.Unit newUnit = new HydroNumerics.Core.Unit("centimeters", 0.01, 0.0);
     timeSeries.ConvertUnit(newUnit);
     Assert.AreEqual("centimeters", timeSeries.Unit.ID);
     Assert.AreEqual(0.01, timeSeries.Unit.ConversionFactorToSI);
     Assert.AreEqual(20, timeSeries.Items[0].Value);
     Assert.AreEqual(40, timeSeries.Items[1].Value);
     Assert.AreEqual(80, timeSeries.Items[2].Value);
 }
예제 #19
0
 public void FromThisUnitToUnit()
 {
     Unit thisUnit = new Unit("ThisUnit", 10, 6);
     Unit toUnit = new Unit("toUnit", 4, 8);
     Assert.AreEqual(42.0, thisUnit.FromThisUnitToUnit(17.0, toUnit));
 }
예제 #20
0
 public abstract void ConvertUnit(Unit newUnit);
예제 #21
0
        public void PropertyChangedEvent()
        {
            Unit unit = new Unit("Test unit", 3.4, 9.3);
            unit.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(unit_PropertyChanged);

            propertyChanged = false; changedPropertyName = "";
            unit.ConversionFactorToSI = 22.2;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("ConversionFactorToSI", changedPropertyName);

            propertyChanged = false; changedPropertyName = "";
            unit.OffSetToSI = 2.2;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("OffSetToSI", changedPropertyName);

            propertyChanged = false; changedPropertyName = "";
            unit.ID = "new unit name";
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("ID", changedPropertyName);

            propertyChanged = false; changedPropertyName = "";
            unit.Description = "new description";
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("Description", changedPropertyName);

            propertyChanged = false; changedPropertyName = "";
            unit.Dimension = new Dimension(1, 1, 1, 1, 1, 1, 1, 1);
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("Dimension", changedPropertyName);

            propertyChanged = false; changedPropertyName = "";
            unit.Dimension.AmountOfSubstance = 6;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("AmountOfSubstance", changedPropertyName);

            unit = new Unit();
            unit.PropertyChanged+=new System.ComponentModel.PropertyChangedEventHandler(unit_PropertyChanged);
            propertyChanged = false; changedPropertyName = "";
            unit.Dimension.AmountOfSubstance = 6;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("AmountOfSubstance", changedPropertyName);

            unit = new Unit(new Unit());
            unit.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(unit_PropertyChanged);
            propertyChanged = false; changedPropertyName = "";
            unit.Dimension.AmountOfSubstance = 6;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("AmountOfSubstance", changedPropertyName);

            unit = new Unit("id", 3.4, 3.5);
            unit.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(unit_PropertyChanged);
            propertyChanged = false; changedPropertyName = "";
            unit.Dimension.AmountOfSubstance = 6;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("AmountOfSubstance", changedPropertyName);

            unit = new Unit("id", 4.5, 3.2, "description");
            unit.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(unit_PropertyChanged);
            propertyChanged = false; changedPropertyName = "";
            unit.Dimension.AmountOfSubstance = 6;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("AmountOfSubstance", changedPropertyName);

            unit = new Unit("id", 4.3, 2.1, "description", new Dimension());
            unit.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(unit_PropertyChanged);
            propertyChanged = false; changedPropertyName = "";
            unit.Dimension.AmountOfSubstance = 6;
            Assert.IsTrue(propertyChanged);
            Assert.AreEqual("AmountOfSubstance", changedPropertyName);

        }
예제 #22
0
 public void IDTest()
 {
     Unit unit = new Unit();
     unit.ID = "someUnitID";
     Assert.AreEqual("someUnitID", unit.ID);
 }
예제 #23
0
 public void DescriptionTest()
 {
     Unit unit = new Unit();
     unit.Description = "someDescription";
     Assert.AreEqual("someDescription", unit.Description);
 }
        public override IValueSet GetValues(ITime time, string LinkID)
        {
            if (!initializeWasInvoked)
            {
                throw new Exception("Method \"GetValues\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked");
            }

            ILink link = this.GetLink(LinkID);

            SendSourceAfterGetValuesCallEvent(time, link);

            // -- handle incoming links (where this component is the target)
            if (!isBusy) //avoiding deadlocks
            {
                isBusy = true;
                foreach (ILink acceptingLink in _acceptingLinks)
                {
                    if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimestampSeries)
                    {
                        TimestampSeries timestampSeries = (TimestampSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimestampValue timestampValue in timestampSeries.Items)
                        {
                            TimeStamp getValuesTime = new TimeStamp(timestampValue.Time);
                            SendTargetBeforeGetValuesCall(getValuesTime, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(getValuesTime, acceptingLink.ID);
                            timestampValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timestampValue.Value, acceptingLink);
                        }
                    }
                    else if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimespanSeries)
                    {
                        TimespanSeries timespanSeries = (TimespanSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimespanValue timespanValue in timespanSeries.Items)
                        {
                            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.StartTime), new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.EndTime));
                            SendTargetBeforeGetValuesCall(timeSpan, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(timeSpan, acceptingLink.ID);
                            timespanValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timespanValue.Value, acceptingLink);
                        }
                    }
                    else
                    {
                        throw new Exception("Unexpected exception : Undefined timeseries type (occured in HydroNumerics.Time.OpenMI.LinkableTimeSeriesGroup class)");
                    }
                }
                isBusy = false;
            }

            // -- handle outgoing links (where this component is the source)
            HydroNumerics.Core.Unit toUnit = new HydroNumerics.Core.Unit();
            toUnit.ConversionFactorToSI = link.TargetQuantity.Unit.ConversionFactorToSI;
            toUnit.OffSetToSI           = link.TargetQuantity.Unit.OffSetToSI;

            if (time is ITimeStamp)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp t = new TimeStamp((ITimeStamp)time);

                double    x         = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(t.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return(scalarSet);
            }
            else
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp start = new TimeStamp(((ITimeSpan)time).Start);
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp end   = new TimeStamp(((ITimeSpan)time).End);

                double    x         = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(start.ToDateTime(), end.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return(scalarSet);
            }
        }
예제 #25
0
 public void ConversionFactorToSITest()
 {
     Unit unit = new Unit();
     unit.ConversionFactorToSI = 17;
     Assert.AreEqual(17, unit.ConversionFactorToSI);
     try
     {
         unit.ConversionFactorToSI = 0;
     }
     catch (System.Exception ex)
     {
         Assert.IsTrue(ex.GetType() == typeof(System.Exception));
     }
 }
예제 #26
0
 public TimestampSeries2(string name, Unit unit) : this()
 {
     this.Unit = unit;
     this.name = name;
 }
예제 #27
0
 /// <summary>
 /// Converts the value provided as argument for this method to this unit. The provided 
 /// value must be represented in the unit provided as argument for this method.
 /// </summary>
 /// <param name="value">The value to convert (must be in the unit as defined in the fromUnit argument)</param>
 /// <param name="fromUnit">The value converted to this unit</param>
 /// <returns></returns>
 public double FromUnitToThisUnit(double valueInFromUnit, Unit fromUnit)
 {
   return FromSiToThisUnit(fromUnit.ToSiUnit(valueInFromUnit));
 }
예제 #28
0
 public override void ConvertUnit(Unit newUnit)
 {
   foreach (TimestampValue timeValue in items)
   {
     timeValue.Value = this.unit.FromThisUnitToUnit(timeValue.Value, newUnit);
   }
   this.unit = new HydroNumerics.Core.Unit(newUnit);
 }
예제 #29
0
        public void EqualsTest()
        {
            Unit unitA;
            Unit unitB;
            unitA = new Unit("something", 3.4, 17.4, "somedescription", new Dimension(1, 2, 3, 4, 5, 6, 7, 8));
            unitB = new Unit("something", 3.4, 17.4, "somedescription", new Dimension(1, 2, 3, 4, 5, 6, 7, 8));
            Assert.IsTrue(unitA.Equals(unitB));

            unitB = new Unit("somethingElse", 3.4, 17.4, "somedescription", new Dimension(1, 2, 3, 4, 5, 6, 7, 8));
            Assert.IsFalse(unitA.Equals(unitB));

            unitB = new Unit("something", 100, 17.4, "somedescription", new Dimension(1, 2, 3, 4, 5, 6, 7, 8));
            Assert.IsFalse(unitA.Equals(unitB));

            unitB = new Unit("something", 3.4, 100, "somedescription", new Dimension(1, 2, 3, 4, 5, 6, 7, 8));
            Assert.IsFalse(unitA.Equals(unitB));

            unitB = new Unit("something", 3.4, 17.4, "someOtherDescription", new Dimension(1, 2, 3, 4, 5, 6, 7, 8));
            Assert.IsFalse(unitA.Equals(unitB));

            unitB = new Unit("something", 3.4, 17.4, "somedescription", new Dimension(0, 2, 3, 4, 5, 6, 7, 8));
            Assert.IsFalse(unitA.Equals(unitB));
        }