private static void AddQueryInfo(string StartDate, string EndDate, string Variable, string SiteNumber, TimeSeriesResponseType response)
            {
                response.queryInfo          = new QueryInfoType();
                response.queryInfo.criteria = new QueryInfoTypeCriteria();

                response.queryInfo.creationTime           = DateTime.UtcNow;
                response.queryInfo.creationTimeSpecified  = true;
                response.queryInfo.criteria.locationParam = SiteNumber;
                response.queryInfo.criteria.variableParam = Variable;
                response.queryInfo.criteria.timeParam     = CuahsiBuilder.createQueryInfoTimeCriteria(StartDate, EndDate);
                NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service");

                response.queryInfo.note = CuahsiBuilder.addNote(response.queryInfo.note,
                                                                sourceNote);
            }
Exemple #2
0
            /// <summary>
            /// GetValues custom implementation
            /// </summary>
            /// <param name="SiteNumber">network:SiteCode</param>
            /// <param name="Variable">vocabulary:VariableCode</param>
            /// <param name="StartDate">yyyy-MM-dd</param>
            /// <param name="EndDate">yyyy-MM-dd</param>
            /// <returns></returns>
            public TimeSeriesResponseType GetValues(string SiteNumber,
                                                    string Variable,
                                                    string StartDate,
                                                    string EndDate)
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();

                // queryLog.Info("GetValues|" + SiteNumber + "|" + Variable + "|" + StartDate + "|" + EndDate);
                //String network,method,location, variable, start, end, , processing time,count
                queryLog2.LogValuesStart(CustomLogging.Methods.GetValues, // method
                                         SiteNumber,                      //locaiton
                                         Variable,                        //variable
                                         StartDate,                       // startdate
                                         EndDate,                         //enddate
                                         appContext.Request.UserHostName);

                //get siteId, variableId
                string siteId     = SiteNumber.Substring(SiteNumber.LastIndexOf(":") + 1);
                string variableId = Variable.Substring(Variable.LastIndexOf(":") + 1);



                DateTime startDateTime = new DateTime(2000, 1, 1);
                DateTime endDateTime   = DateTime.Now;

                if (StartDate != String.Empty)
                {
                    startDateTime = DateTime.Parse(StartDate);
                }

                if (EndDate != String.Empty)
                {
                    endDateTime = DateTime.Parse(EndDate);
                }

                //TimeSeriesResponseType resp = obj.getValues(SiteNumber, Variable, StartDate, EndDate);
                TimeSeriesResponseType resp = new TimeSeriesResponseType();

                resp.timeSeries               = new TimeSeriesType[1];
                resp.timeSeries[0]            = new TimeSeriesType();
                resp.timeSeries[0].sourceInfo = WebServiceUtils.GetSiteFromDb2(siteId);
                resp.timeSeries[0].variable   = WebServiceUtils.GetVariableInfoFromDb(variableId);

                resp.timeSeries[0].values    = new TsValuesSingleVariableType[1];
                resp.timeSeries[0].values[0] = WebServiceUtils.GetValuesFromDb(siteId, variableId, startDateTime, endDateTime);

                //set the query info
                resp.queryInfo          = new QueryInfoType();
                resp.queryInfo.criteria = new QueryInfoTypeCriteria();

                resp.queryInfo.creationTime           = DateTime.UtcNow;
                resp.queryInfo.creationTimeSpecified  = true;
                resp.queryInfo.criteria.locationParam = SiteNumber;
                resp.queryInfo.criteria.variableParam = Variable;
                resp.queryInfo.criteria.timeParam     = CuahsiBuilder.createQueryInfoTimeCriteria(StartDate, EndDate);

                queryLog2.LogValuesEnd(CustomLogging.Methods.GetValues,
                                       SiteNumber,                                //locaiton
                                       Variable,                                  //variable
                                       StartDate,                                 // startdate
                                       EndDate,                                   //enddate
                                       timer.ElapsedMilliseconds,                 // processing time
                                                                                  // assume one for now
                                       resp.timeSeries[0].values[0].value.Length, // count
                                       appContext.Request.UserHostName);

                return(resp);
            }
Exemple #3
0
        public TimeSeriesResponseType getValues(string SiteNumber, string Variable, string StartDate, string EndDate)
        {
            // convert dates
            // get site info
            // get site ID
            // return value dataset

            TimeSeriesResponseType response;
            W3CDateTime?           BeginDateTime;
            W3CDateTime?           EndDateTime;
            int?variableId = null;
            int?siteID;

            VariableInfoType varInfoType = null;
            SiteInfoType     siteType    = null;

            if (!String.IsNullOrEmpty(StartDate))
            {
                try
                {
                    BeginDateTime = W3CDateTime.Parse(StartDate);
                }
                catch
                {
                    throw new WaterOneFlowException("Improper BeginDate '" +
                                                    StartDate + "' Must be YYYY-MM-DD");
                }
            }
            else
            {
                BeginDateTime = null;
            }

            if (!String.IsNullOrEmpty(EndDate))
            {
                try
                {
                    EndDateTime = W3CDateTime.Parse(EndDate);
                }
                catch
                {
                    throw new WaterOneFlowException("Improper EndDate '" +
                                                    EndDate + "' Must be YYYY-MM-DD");
                }
            }
            else
            {
                EndDateTime = null;
            }
            VariableParam vp;

            if (Variable != null)
            {
                vp = new VariableParam(Variable);
                VariableInfoType[] v = ODvariables.getVariable(vp, variableDs);
                if (v != null && v.Length > 0)
                {
                    variableId  = Convert.ToInt16(v[0].variableCode[0].variableID);
                    varInfoType = v[0];
                }
                else
                {
                    throw new WaterOneFlowException("Variable parameter not found: " + Variable);
                }
            }
            else
            {
                throw new WaterOneFlowException("Variable parameter is required ");
            }
            locationParam sq;

            sq = new locationParam(SiteNumber);

            if (sq.isGeometry)
            {
                throw new WaterOneFlowException("Location by Geometry not accepted: " + SiteNumber);
            }

            siteInfoDataSet sitDs = ODSiteInfo.GetSiteInfoDataSet(sq);

            if (sitDs != null && sitDs.sites.Count > 0)
            {
                siteID = sitDs.sites[0].SiteID;
                ValuesDataSet valuesDs = getValuesDataset(siteID, variableId, BeginDateTime, EndDateTime, vp);

                response = getValues(valuesDs, vp);

                // above is the values, add the site, and variables
                response.timeSeries.variable = varInfoType;

                if (varInfoType != null)
                {
                    if (varInfoType.units != null)
                    {
                        response.timeSeries.values.unitsAbbreviation = varInfoType.units.unitsAbbreviation;
                        response.timeSeries.values.unitsCode         = varInfoType.units.unitsCode;

                        if (varInfoType.units.unitsType != null)
                        {
                            response.timeSeries.values.unitsType          = varInfoType.units.unitsType;
                            response.timeSeries.values.unitsTypeSpecified = true;
                        }
                        response.timeSeries.values.unitsAreConverted = false;
                    }
                }

                response.timeSeries.sourceInfo = ODSiteInfo.row2SiteInfoElement(sitDs.sites[0], sitDs);
            }
            else
            {
                response = CuahsiBuilder.CreateTimeSeriesObject();
            }
            // add query info
            response.queryInfo.creationTime = DateTime.UtcNow;
            //response.queryInfo.creationTime = DateTimeOffset.UtcNow;
            response.queryInfo.creationTimeSpecified  = true;
            response.queryInfo.criteria.locationParam = SiteNumber;
            response.queryInfo.criteria.variableParam = Variable;
            response.queryInfo.criteria.timeParam     = CuahsiBuilder.createQueryInfoTimeCriteria(StartDate, EndDate);
            NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service");

            response.queryInfo.note = CuahsiBuilder.addNote(response.queryInfo.note,
                                                            sourceNote);


            return(response);
        }