コード例 #1
0
        public void GetValues()
        {
            Console.Write("Begin Get Values Test...");
            //create the his component
            DbReader his = new DbReader();

            IArgument[] arguments = new IArgument[2];
            arguments[0] = new Argument("DbPath", @"..\data\cuahsi-his\demo.db", true, "Database");
            arguments[1] = new Argument("Relaxation", "1", true, "Time interpolation factor, btwn 0(linear inter.) and 1(nearest neigbor)");
            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(0).ElementSet;
            link.SourceQuantity   = his.GetOutputExchangeItem(0).Quantity;
            link.TargetComponent  = his;

            //run configuration
            his.AddLink(link);

            //prepare
            his.Prepare();

            DateTime dt = Convert.ToDateTime("2009-08-20");

            while (dt <= Convert.ToDateTime("2009-09-20"))
            {
                ITimeStamp time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(dt));
                Application.DoEvents();
                ScalarSet scalarset = (ScalarSet)his.GetValues(time_stmp, "link-1");
                Console.WriteLine("GetValues: " + dt.ToString("s"));
                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");
        }
コード例 #2
0
        public void DataConversion()
        {
            Console.Write("Begin Data Conversion Test...");
            //create the his component
            DbReader his = new DbReader();

            IArgument[] arguments = new IArgument[2];
            arguments[0] = new Argument("DbPath", @"../../../../../Databases/MyDataRepository.sqlite", true, "Database");
            arguments[1] = new Argument("Relaxation", "1", true, "Time interpolation factor, btwn 0(linear inter.) and 1(nearest neigbor)");
            his.Initialize(arguments);

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

            trigger.Initialize(null);

            //
            //-- Test Transfer from ft3/s to m3/s
            //
            int item = 0;

            for (int i = 0; i <= his.OutputExchangeItemCount - 1; i++)
            {
                string quantity   = his.GetOutputExchangeItem(i).Quantity.ID;
                string elementset = his.GetOutputExchangeItem(i).ElementSet.ID;
                if (quantity == "Discharge" && elementset == "Gills Creek Discharge")
                {
                    item = i;
                    break;
                }
            }

            //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(item).ElementSet;
            link.SourceQuantity   = his.GetOutputExchangeItem(item).Quantity;
            link.TargetComponent  = his;
            his.AddLink(link);
            his.Prepare();

            DateTime dt = Convert.ToDateTime("2009-09-07 00:00:00");

            while (dt <= Convert.ToDateTime("2010-09-06 00:00:00"))
            {
                ITimeStamp time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(dt));
                Application.DoEvents();
                ScalarSet scalarset = (ScalarSet)his.GetValues(time_stmp, "link-1");
                Console.WriteLine("GetValues: " + dt.ToString("s"));
                int i = 0;
                foreach (double d in scalarset.data)
                {
                    Console.WriteLine(link.SourceElementSet.GetElementID(i).ToString() + " " + d.ToString());
                    ++i;
                }
                dt = dt.AddDays(1);
            }
            Console.Write("done. \n");
        }
コード例 #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");
        }