예제 #1
0
        static WaterML11.TimeSeriesResponseType LoadDataValueInfo(string siteCode, string varCode,
                                                                  WaterML11.WaterOneFlowClient WofClient,
                                                                  DateTime beginDateTime, DateTime endDateTime,
                                                                  ref string queryParam, ref string errMsg)
        {
            string beginDT = string.Format("{0:s}", beginDateTime);
            string endDT   = string.Format("{0:s}", endDateTime);

            errMsg     = "";
            queryParam = String.Format(" <{0}--{1}> ", beginDT, endDT);
            Console.WriteLine("......Getting values from <{0}> to <{1}>.", beginDT, endDT);

            WaterML11.TimeSeriesResponseType tsRt = null;
            try
            {
                tsRt = WofClient.GetValuesObject(siteCode, varCode, beginDT, endDT, "");
            }
            catch (Exception e)
            {
                errMsg = "Exception@LoadData: " + e.Message;
                Console.WriteLine(errMsg);
            }

            return(tsRt);
        }
예제 #2
0
        // Get DataValueInfo for 3 time periods: begin, middle, end.
        // As corresponding to the first, mid, and last 30 data values
        static WaterML11.TimeSeriesResponseType[] LoadDataValueInfoSplit(string siteCode, string varCode,
                                                                         WaterML11.WaterOneFlowClient WofClient,
                                                                         int valuecount, DateTime beginDateTime, DateTime endDateTime,
                                                                         ref string queryParam, ref string errMsg)
        {
            queryParam = "";
            errMsg     = "";

            WaterML11.TimeSeriesResponseType[] tsRtAll = new WaterML11.TimeSeriesResponseType[3];

            string beginDT = string.Format("{0:s}", beginDateTime);
            string endDT   = string.Format("{0:s}", endDateTime);

            Console.WriteLine("......Getting values from <{0}> to <{1}>.", beginDT, endDT);
            DateTime[] fromDateTime = new DateTime[3];
            DateTime[] toDateTime = new DateTime[3];
            string     fromDT, toDT;

            int[] count = new int[3] {
                0, 0, 0
            };

            // Timespan between beginDT and endDT
            TimeSpan delta = endDateTime - beginDateTime;
            double   step0 = delta.TotalSeconds * Program.CompareRecordCount * 2 / valuecount;

            // The first 30 records
            fromDateTime[0] = beginDateTime;
            toDateTime[0]   = beginDateTime.AddSeconds(step0);

            // The middle 30 records
            fromDateTime[1] = beginDateTime.AddSeconds(delta.TotalSeconds / 2);
            toDateTime[1]   = fromDateTime[1].AddSeconds(step0);

            // The last 30 records
            fromDateTime[2] = endDateTime.AddSeconds(-step0);
            toDateTime[2]   = endDateTime;


            //...Site[25] UCRB_USBR:USBR_LNH with 1 catalogs from http://drought.usu.edu/usbrreservoirs/cuahsi_1_1.asmx?WSDL.
            //......Series[0] varCode: UCRB_USBR:STOR valCount: 995
            //......Getting values from <2009-06-09T00:00:00> to <2012-02-29T00:00:00>.
            //...
            //......Getting values from <2008-04-16T00:00:00> to <2012-02-29T00:00:00>.
            //......Series[3] varCode: UCRB_USBR:ELEV valCount: 7048
            //......Getting values from <1992-11-12T00:00:00> to <2012-02-29T00:00:00>.
            //......Getting values, Segment <1>: from <1992-11-12T00:00:00> to <1993-01-11T00:00:00>.
            //......Getting values, Segment <2>: from <2002-07-07T00:00:00> to <2002-09-05T00:00:00>.
            //......Getting values, Segment <3>: from <2011-12-31T00:00:00> to <2012-02-29T00:00:00>.

            for (int i = 0; i < 3; i++)
            {
                bool lastTry = false;
                tsRtAll[i] = null;
                double step = step0;
                while (!lastTry)
                {
                    if ((i < 2) && (DateTime.Compare(toDateTime[i], endDateTime) >= 0))
                    {
                        toDateTime[i] = endDateTime;
                        lastTry       = true;
                    }
                    else if ((i == 2) && (DateTime.Compare(fromDateTime[i], beginDateTime) <= 0))
                    {
                        fromDateTime[i] = beginDateTime;
                        lastTry         = true;
                    }

                    fromDT = string.Format("{0:s}", fromDateTime[i]);
                    toDT   = string.Format("{0:s}", toDateTime[i]);

                    Console.WriteLine("......Getting values, Segment <{0}>: from <{1}> to <{2}>.",
                                      i + 1, fromDT, toDT);
                    try
                    {
                        tsRtAll[i] = WofClient.GetValuesObject(siteCode, varCode, fromDT, toDT, "");
                    }
                    catch (Exception e)
                    {
                        errMsg = "Exception@LoadDataSplit: " + e.Message;
                        Console.WriteLine(errMsg);
                        return(null);
                    }

                    if (tsRtAll[i].timeSeries[0].values[0].value != null)
                    {
                        count[i] = tsRtAll[i].timeSeries[0].values[0].value.Count();
                    }
                    if (count[i] >= Program.CompareRecordCount)
                    {
                        queryParam += String.Format(" <{0}--{1}> ", fromDT, toDT);
                        break;
                    }
                    else
                    {
                        step *= 2;
                        if (i < 2)
                        {
                            toDateTime[i] = toDateTime[i].AddSeconds(step);
                        }
                        else
                        {
                            fromDateTime[i] = fromDateTime[i].AddSeconds(-step);
                        }
                    }
                }
            }

            return(tsRtAll);
        }