public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier2)
        {
            CheckBuffer();
            List <IList <double> > valuesList = new List <IList <double> >();

            for (int i = 0; i < ((ITimeSpaceInput)Consumers[0]).TimeSet.Times.Count; i++)
            {
                ITime time = ((ITimeSpaceInput)Consumers[0]).TimeSet.Times[i];
                valuesList.Add(_buffer.GetValues(time));
            }
            return(new TimeSpaceValueSet <double>(valuesList));
        }
Example #2
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem basequerySpecifier)
        {
            ITimeSpaceExchangeItem querySpecifier = basequerySpecifier as ITimeSpaceExchangeItem;

            if (querySpecifier == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            //------------------------------------------------------
            // Check if we need to update the output component

            // Time set of query must be defined and have at least 1 time
            if (querySpecifier.TimeSet == null ||
                querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + querySpecifier.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determine query time
            double queryTimeMjd = querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;

            // Determine the times available in the buffer
            double        availableTimeMjd = Double.NegativeInfinity;
            IList <ITime> currentTimes     = TimeSet.Times;

            if (currentTimes.Count > 0)
            {
                availableTimeMjd = currentTimes[currentTimes.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Check if we need to update
            // In case the output component is "busy", this may not actually update values
            // up to queryTimeMjd, in which case the _buffer.GetValues below will extrapolate.
            if (availableTimeMjd < queryTimeMjd)
            {
                if (ComponentUpdater == null)
                {
                    throw new Exception("Failed when trying to update time buffer (no updater is specified)");
                }
                ComponentUpdater.Update(querySpecifier);
            }

            //------------------------------------------------------
            // Retrieve values from the buffer

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (querySpecifier.TimeSet != null && querySpecifier.TimeSet.Times != null)
            {
                for (int t = 0; t < querySpecifier.TimeSet.Times.Count; t++)
                {
                    ITime    queryTime         = querySpecifier.TimeSet.Times[t];
                    double[] valuesForTimeStep = _buffer.GetValues(queryTime);
                    resultValues.Add(valuesForTimeStep);
                }
            }
            ITime earliestConsumerTime = ExchangeItemHelper.GetEarliestConsumerTime(this);

            if (earliestConsumerTime != null)
            {
                _buffer.ClearBefore(earliestConsumerTime);
            }
            return(new TimeSpaceValueSet <double>(resultValues));
        }
Example #3
0
        public void LinearTimeInterpolation()
        {
            Console.Write("Begin Linear Interpolation Test...");

            //create the his component
            DbReader his = new DbReader();

            IArgument[] arguments = new IArgument[1];
            arguments[0] = new Argument("DbPath", @"..\data\cuahsi-his\demo.db", true, "Database");
            his.Initialize(arguments);

            //create a trigger component
            Trigger trigger = new Trigger();

            trigger.Initialize(null);

            //link the two components
            Link link = new Link();

            link.ID = "link-1";
            link.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;
            link.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;
            link.TargetComponent  = trigger;


            link.SourceElementSet = his.GetOutputExchangeItem(1).ElementSet;
            link.SourceQuantity   = his.GetOutputExchangeItem(1).Quantity;
            link.TargetComponent  = his;


            //Spatial interpolation
            IDataOperation dataOp = (his).GetOutputExchangeItem(0).GetDataOperation(7);

            link.AddDataOperation(dataOp);


            //run configuration
            his.AddLink(link);

            trigger.Validate();
            his.Validate();

            //prepare
            his.Prepare();

            DateTime dt = Convert.ToDateTime("2009-08-20T21:40:00");

            SmartBuffer _smartBuffer = new SmartBuffer();

            //Add all values to buffer in 10min intervals
            Console.Write("Storing values in the smart buffer (10min resolution)... ");
            while (dt <= Convert.ToDateTime("2009-08-21T02:00:00"))
            {
                ITimeStamp time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(dt));
                ScalarSet  scalarset = (ScalarSet)his.GetValues(time_stmp, "link-1");

                if (scalarset.Count == 0)
                {
                    int       f         = his.GetOutputExchangeItem(1).ElementSet.ElementCount;
                    ArrayList zeroArray = new ArrayList();
                    for (int i = 0; i <= f - 1; i++)
                    {
                        zeroArray.Add(0.0);
                    }

                    double[] zeros = (double[])zeroArray.ToArray(typeof(double));

                    scalarset = new ScalarSet(zeros);
                }

                _smartBuffer.AddValues(time_stmp, scalarset);

                dt = dt.AddMinutes(10);
            }
            Console.WriteLine("done.\n\n");

            //request values from the smart buffer at 5min intervals
            dt = Convert.ToDateTime("2009-08-20T21:40:00");
            while (dt <= Convert.ToDateTime("2009-08-21T02:00:00"))
            {
                ITimeStamp time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(dt));

                //Get values at requested time
                ScalarSet scalarset = (ScalarSet)_smartBuffer.GetValues(time_stmp);

                Console.WriteLine("GetValues: " + dt.ToString("s"));


                //loop through interpolated values
                int i = 0;
                foreach (double d in scalarset.data)
                {
                    Console.WriteLine(link.SourceElementSet.GetElementID(i).ToString() + " " + d.ToString());
                    ++i;
                }
                dt = dt.AddMinutes(5);
            }

            Console.Write("done. \n");
        }
Example #4
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            if (timeSpaceQuery.TimeSet == null || timeSpaceQuery.TimeSet.Times == null ||
                timeSpaceQuery.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + timeSpaceQuery.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determinee query time and currently available time
            double queryTimeAsMJD =
                timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].StampAsModifiedJulianDay +
                timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].DurationInDays;

            double        availableTimeAsMJD = Double.NegativeInfinity;
            IList <ITime> currentTimes       = TimeSet.Times;

            if (currentTimes.Count > 0)
            {
                availableTimeAsMJD =
                    currentTimes[currentTimes.Count - 1].StampAsModifiedJulianDay +
                    currentTimes[currentTimes.Count - 1].DurationInDays;
            }

            // Check if we need to update
            if (availableTimeAsMJD < queryTimeAsMJD)
            {
                // TODO (JGr): output item should not do the actual update of the component?
                if (Adaptee == null)
                {
                    throw new Exception("Can not update, no parent output defined, calling GetValues() of time bufferer " + Id);
                }
                if (_adaptee.TimeSet == null || _adaptee.TimeSet.Times == null)
                {
                    throw new Exception("Invalid time specifier in decorated output item \"" + Adaptee.Id +
                                        "\" for in GetValues() call to time decorater " + Id);
                }

                // Update as far as needed.
                IBaseLinkableComponent linkableComponent = Adaptee.Component;
                while ((linkableComponent.Status == LinkableComponentStatus.Valid ||
                        linkableComponent.Status == LinkableComponentStatus.Updated) &&
                       availableTimeAsMJD < queryTimeAsMJD)
                {
                    linkableComponent.Update();
                    // Determine newly available time
                    IList <ITime> parentTimes = _adaptee.TimeSet.Times;
                    availableTimeAsMJD =
                        parentTimes[parentTimes.Count - 1].StampAsModifiedJulianDay +
                        parentTimes[parentTimes.Count - 1].DurationInDays;
                }
            }

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (timeSpaceQuery.TimeSet != null && timeSpaceQuery.TimeSet.Times != null)
            {
                for (int t = 0; t < timeSpaceQuery.TimeSet.Times.Count; t++)
                {
                    resultValues.Add(new List <double>());
                    ITime         queryTime         = timeSpaceQuery.TimeSet.Times[t];
                    List <double> valuesForTimeStep = _buffer.GetValues(queryTime);
                    foreach (double d in valuesForTimeStep)
                    {
                        resultValues[t].Add(d);
                    }
                }
            }
            return(new TimeSpaceValueSet <double>(resultValues));
        }
 public double[] GetValues(ITime time, string linkId)
 {
     return buffer.GetValues(time);
 }
Example #6
0
        public override IValueSet GetValues(IExchangeItem querySpecifier)
        {
            if (querySpecifier.TimeSet == null || querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + querySpecifier.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }
            if (ParentOutput.TimeSet == null || ParentOutput.TimeSet.Times == null)
            {
                throw new Exception("Invalid time specifier in decorated output item \"" + ParentOutput.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determinee query time and currently available time
            double queryTimeAsMJD =
                querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].StampAsModifiedJulianDay +
                querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].DurationInDays;
            double        availableTimeAsMJD       = Double.NegativeInfinity;
            IList <ITime> decoratedOutputItemTimes = ParentOutput.TimeSet.Times;

            if (decoratedOutputItemTimes.Count > 0)
            {
                availableTimeAsMJD =
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].StampAsModifiedJulianDay +
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].DurationInDays;
            }

            // Update as far as needed.
            ILinkableComponent linkableComponent = ParentOutput.Component;

            while ((linkableComponent.Status == LinkableComponentStatus.Valid ||
                    linkableComponent.Status == LinkableComponentStatus.Updated) &&
                   availableTimeAsMJD < queryTimeAsMJD)
            {
                linkableComponent.Update();
                // Determine newly available time
                decoratedOutputItemTimes = ParentOutput.TimeSet.Times;
                availableTimeAsMJD       =
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].StampAsModifiedJulianDay +
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].DurationInDays;
            }

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (querySpecifier.TimeSet != null && querySpecifier.TimeSet.Times != null)
            {
                for (int t = 0; t < querySpecifier.TimeSet.Times.Count; t++)
                {
                    resultValues.Add(new List <double>());
                    ITime         queryTime         = querySpecifier.TimeSet.Times[t];
                    List <double> valuesForTimeStep = _buffer.GetValues(queryTime);
                    foreach (double d in valuesForTimeStep)
                    {
                        resultValues[t].Add(d);
                    }
                }
            }
            return(new ValueSet <double>(resultValues));
        }