Esempio n. 1
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;

                BeginDateTime = GetBeginDateTime(StartDate);

                EndDateTime = GetEndDateTime(EndDate);

                VariableParam vp = GetVariableParameter(Variable, ref variableId, ref varInfoType);
                locationParam sq = GetLocationParameter(SiteNumber);

                siteInfoDataSet sitDs = ODSiteInfo.GetSiteInfoDataSet(sq);

                response = CuahsiBuilder.CreateTimeSeriesObjectSingleValue(1);

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

                    response.timeSeries[0].values = getValues(valuesDs, vp, variableId);

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

                    response.timeSeries[0].sourceInfo = ODSiteInfo.row2SiteInfoElement(sitDs.sites[0], sitDs);
                }

                // AddQueryInfo(StartDate, EndDate, Variable, SiteNumber, response);

                response.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetValues",
                                                                       new string[] { SiteNumber }, null, new string[] { Variable }, StartDate, EndDate);

                return(response);
            }
Esempio n. 2
0
        public static TimeSeriesResponseType getValues(ValuesDataSet ValuesDs, VariableParam variable)
        {
            TimeSeriesResponseType response = CuahsiBuilder.CreateTimeSeriesObjectSingleValue();

            // get siteInfo

            // get variable Info

            // get Values
            // reformats values dataset into a TimeSeriesResponseType
            List <ValueSingleVariable> valueList = ODValues.dataset2ValuesList(ValuesDs, variable);

            response.timeSeries.values.value = valueList.ToArray();
            response.timeSeries.values.count = valueList.Count.ToString();

            // add qualifiers
            List <qualifier> qualifers = ODValues.datasetQualifiers(ValuesDs);

            if (qualifers != null && qualifers.Count > 0)
            {
                response.timeSeries.values.qualifier = qualifers.ToArray();
            }
            // add methods
            List <MethodType> methods = ODValues.datasetMethods(ValuesDs);

            if (methods != null && methods.Count > 0)
            {
                response.timeSeries.values.method = methods.ToArray();
            }
            List <SourceType> sources = ODValues.datasetSources(ValuesDs);

            if (sources != null && sources.Count > 0)
            {
                response.timeSeries.values.source = sources.ToArray();
            }
            List <OffsetType> offsets = ODValues.datasetOffsetTypes(ValuesDs);

            if (offsets != null && offsets.Count > 0)
            {
                response.timeSeries.values.offset = offsets.ToArray();
            }
            return(response);
        }
Esempio n. 3
0
        public VariablesResponseType GetVariableInfo(string Variable)
        {
            VariableInfoType[] variableList;
            if (String.IsNullOrEmpty(Variable))
            {
                variableList = ODvariables.getVariables(new VariableParam[0], Variables);

            }
            else
            {
                VariableParam vp;
                vp = new VariableParam(Variable);
                variableList = ODvariables.getVariable(vp, Variables);
            }

            if (variableList == null)
            {
                throw new WaterOneFlowException("Variable Not Found");
            }
            VariablesResponseType Response = new VariablesResponseType();
            Response.variables = variableList;

            if (Response.queryInfo == null)
            {
                Response.queryInfo = new QueryInfoType();
                Response.queryInfo.criteria = new QueryInfoTypeCriteria();
            }
            Response.queryInfo.creationTime = DateTime.UtcNow;
            Response.queryInfo.creationTimeSpecified = true;
            if (String.IsNullOrEmpty(Variable))
            {
                Response.queryInfo.criteria.variableParam = "NULL (Request for all variables";
            }
            else
            {
                Response.queryInfo.criteria.variableParam = Variable;
            }

            NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service");
            Response.queryInfo.note = CuahsiBuilder.addNote(Response.queryInfo.note,
                                                            sourceNote);
            return Response;
        }
Esempio n. 4
0
            private VariableParam GetVariableParameter(string Variable, ref int?variableId, ref VariableInfoType varInfoType)
            {
                VariableParam vp = null;

                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);
                    }
                }
                return(vp);
            }
Esempio n. 5
0
        public static TimeSeriesResponseType getValues(ValuesDataSet ValuesDs, VariableParam variable)
        {
            TimeSeriesResponseType response = CuahsiBuilder.CreateTimeSeriesObjectSingleValue();

            // get siteInfo

            // get variable Info

            // get Values
            // reformats values dataset into a TimeSeriesResponseType
            List<ValueSingleVariable> valueList = ODValues.dataset2ValuesList(ValuesDs, variable);

            response.timeSeries.values.value = valueList.ToArray();
            response.timeSeries.values.count = valueList.Count.ToString();

            // add qualifiers
            List<qualifier> qualifers = ODValues.datasetQualifiers(ValuesDs);
            if (qualifers != null && qualifers.Count > 0)
            {
                response.timeSeries.values.qualifier = qualifers.ToArray();
            }
            // add methods
            List<MethodType> methods = ODValues.datasetMethods(ValuesDs);
            if (methods != null && methods.Count > 0)
            {
                response.timeSeries.values.method = methods.ToArray();
            }
            List<SourceType> sources = ODValues.datasetSources(ValuesDs);
            if (sources != null && sources.Count > 0)
            {
                response.timeSeries.values.source = sources.ToArray();
            }
            List<OffsetType> offsets = ODValues.datasetOffsetTypes(ValuesDs);
            if (offsets != null && offsets.Count > 0)
            {
                response.timeSeries.values.offset = offsets.ToArray();
            }
            return response;
        }
Esempio n. 6
0
            public static TsValuesSingleVariableType[] getValues(ValuesDataSet ValuesDs, VariableParam variableParam, int?variableId)
            {
                // TimeSeriesResponseType response = CuahsiBuilder.CreateTimeSeriesObjectSingleValue(1);

                TsValuesSingleVariableType[] valuesList = new TsValuesSingleVariableType[1];

                TsValuesSingleVariableType values = new TsValuesSingleVariableType();

                valuesList[0] = values;

                // get siteInfo
                // get variable Info
                // get Values

                string valuesWhereClause = OdValuesCommon.CreateValuesWhereClause(variableParam, variableId);

                // reformats values dataset into a TimeSeriesResponseType
                IEnumerable <ValueSingleVariable> valueE = ODValues.dataset2ValuesList(ValuesDs, variableParam, variableId, variableDs);


                // do this by keeping a list of ID's then generating in after the values list is done
                values.value = new List <ValueSingleVariable>(valueE).ToArray();
                //values.count = values.value.Length;

                if (values.value.Length > 0)
                {
                    // add qualifiers
                    List <QualifierType> qualifers = ODValues.datasetQualifiers(ValuesDs, valuesWhereClause);
                    if (qualifers != null && qualifers.Count > 0)
                    {
                        values.qualifier = qualifers.ToArray();
                    }
                    // add methods
                    List <MethodType> methods = ODValues.datasetMethods(ValuesDs, valuesWhereClause);
                    if (methods != null && methods.Count > 0)
                    {
                        values.method = methods.ToArray();
                    }
                    List <SourceType> sources = ODValues.datasetSources(ValuesDs, valuesWhereClause);
                    if (sources != null && sources.Count > 0)
                    {
                        values.source = sources.ToArray();
                    }
                    List <OffsetType> offsets = ODValues.datasetOffsetTypes(ValuesDs, valuesWhereClause);
                    if (offsets != null && offsets.Count > 0)
                    {
                        values.offset = offsets.ToArray();
                    }

                    List <QualityControlLevelType> qcLevels = ODValues.DatasetQCLevels(ValuesDs, valuesWhereClause);
                    if (qcLevels != null && qcLevels.Count > 0)
                    {
                        values.qualityControlLevel = qcLevels.ToArray();
                    }
                    List <SampleType> samples = ODValues.datasetSamples(ValuesDs, valuesWhereClause);
                    if (samples != null && samples.Count > 0)
                    {
                        values.sample = samples.ToArray();
                    }

                    IEnumerable <CensorCodeType> codeTypes = ODValues.datasetCensorCodes(ValuesDs, valuesWhereClause);
                    values.censorCode = new List <CensorCodeType>(codeTypes).ToArray();
                }

                return(valuesList);
            }
Esempio n. 7
0
            public static VariableInfoType[] getVariable(VariableParam vParam, VariablesDataset ds)
            {
                List <VariableInfoType> vars = new List <VariableInfoType>();

                if (vParam != null)
                {
                    /* need to use a data view, so the we can set a filter that does not effect the whole dataset
                     * DataView has a ToTable method that is uses to create a new DS, and fill
                     * a new VariablesDataset. Typed Datasets are useful ;)
                     */

                    DataView view = new DataView();
                    view.Table = ds.Tables["Variables"];

                    if (vParam.IsId)
                    {
                        view.RowFilter = "VariableID = " + vParam.Code + " ";
                    }
                    else
                    {
                        view.RowFilter = "VariableCode = '" + vParam.Code + "' ";
                        // list of possible options. Allowing any will break the query (aka QualityControlLevelID, etc)
                        String[] options = { "samplemedium", "datatype", "valuetype" };

                        foreach (string opt in options)
                        {
                            if (vParam.options.ContainsKey(opt))
                            {
                                if (!String.IsNullOrEmpty(vParam.options[opt]))
                                {
                                    String rowFilter = view.RowFilter + " AND "
                                                       + opt + "='" + vParam.options[opt] + "'";
                                    view.RowFilter = rowFilter;
                                }
                            }
                        }
                    }

                    DataTable v = view.ToTable();

                    if (v.Rows.Count > 0)
                    {
                        VariablesDataset vtemp = new VariablesDataset();

                        vtemp.Variables.Merge(v);

                        foreach (VariablesDataset.VariablesRow row in vtemp.Variables.Rows)
                        {
                            VariableInfoType result = rowToVariableInfoType(row,
                                                                            ds
                                                                            );
                            vars.Add(result);
                        }

                        return(vars.ToArray());
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
Esempio n. 8
0
        /// <summary>
        /// DataValue creation. Converts a ValuesDataSet to the XML schema ValueSingleVariable
        /// If variable is null, it will return all
        /// If variable has extra options (variable:code/Value=Key/Value=Key)
        /// 
        /// </summary>
        /// <param name="ds">Dataset that you want converted</param>
        /// <param name="variable">Variable that you want to use to place limits on the returned data</param>
        /// <returns></returns>
        public static List<ValueSingleVariable> dataset2ValuesList(ValuesDataSet ds, VariableParam variable)
        {
            List<ValueSingleVariable> tsTypeList = new List<ValueSingleVariable>();

            /* logic
             * if there is a variable that has options, then get a set of datarows
               * using a select clause
             * use an enumerator, since it is generic
             * */
            IEnumerator dataValuesEnumerator ;

            ValuesDataSet.DataValuesRow[] dvRows; // if we find options, we need to use this.

                 String select = OdValuesCommon.CreateValuesWhereClause(variable, null);

                 if (select.Length > 0)
                 {
                     dvRows = (ValuesDataSet.DataValuesRow[])ds.DataValues.Select(select.ToString());

                     dataValuesEnumerator = dvRows.GetEnumerator();

                 }
                 else
                 {
                     dataValuesEnumerator = ds.DataValues.GetEnumerator();
                 }

            //  foreach (ValuesDataSet.DataValuesRow aRow in ds.DataValues){
            while (dataValuesEnumerator.MoveNext())
            {
                ValuesDataSet.DataValuesRow aRow = (ValuesDataSet.DataValuesRow)dataValuesEnumerator.Current;
                try
                {
                    ValueSingleVariable tsTypeValue = new ValueSingleVariable();

                    #region DateTime Standard
                    tsTypeValue.dateTime = Convert.ToDateTime(aRow.DateTime);
                    //tsTypeValue.dateTimeSpecified = true;
                    DateTime temprealdate;

                    //<add key="returnUndefinedUTCorLocal" value="Undefined"/>
                    if (ConfigurationManager.AppSettings["returnUndefinedUTCorLocal"].Equals("Undefined"))
                    {
                        temprealdate = Convert.ToDateTime(aRow.DateTime); // not time zone shift

                    }
                    else if (ConfigurationManager.AppSettings["returnUndefinedUTCorLocal"].Equals("Local"))
                    {

                        TimeSpan zone = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
                        Double offset = Convert.ToDouble(aRow.UTCOffset);

                        if (zone.TotalHours.Equals(offset))
                        {
                            // zone is the same as server. Shift
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime), DateTimeKind.Local);
                        }
                        else
                        {
                            //// zone is not the same. Output in UTC.
                            //temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime), DateTimeKind.Utc);
                            //// correct time with shift.
                            //temprealdate = temprealdate.AddHours(offset);

                            // just use the DateTime UTC
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTimeUTC), DateTimeKind.Utc);

                        }
                    }
                    else if (ConfigurationManager.AppSettings["returnUndefinedUTCorLocal"].Equals("UTC"))
                    {
                        temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTimeUTC), DateTimeKind.Utc);

                    }
                    else
                    {
                        temprealdate = Convert.ToDateTime(aRow.DateTime); // not time zone shift

                    }

                    temprealdate = Convert.ToDateTime(aRow.DateTime); // not time zone shift
            #endregion
            #region DateTimeOffset Failed
                    /// using XML overrides
                    // Attemp to use DateTimeOffset in xml Schema
                    //TimeSpan zone = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
                    //Double offset = Convert.ToDouble(aRow.UTCOffset);

                    //DateTimeOffset temprealdate;
                    //temprealdate = new DateTimeOffset(Convert.ToDateTime(aRow.DateTime),
                    //    new TimeSpan(Convert.ToInt32(offset),0,0));
                    //DateTimeOffset temprealdate;
                    //temprealdate = new DateTimeOffset(Convert.ToDateTime(aRow.DateTime),
                    //    new TimeSpan(Convert.ToInt32(offset), 0, 0));

                    //tsTypeValue.dateTime = temprealdate;
                    //tsTypeValue.dateTimeSpecified = true;
                    #endregion

                    //tsTypeValue.censored = string.Empty;
                    if (string.IsNullOrEmpty(aRow.Value.ToString()))
                        continue;
                    else
                        tsTypeValue.Value = Convert.ToDecimal(aRow.Value);

                    try
                    {

                        tsTypeValue.censorCode = (CensorCodeEnum)Enum.Parse(typeof(CensorCodeEnum), aRow.CensorCode, true);
                        tsTypeValue.censorCodeSpecified = true;

                        if (!aRow.IsOffsetTypeIDNull())
                        {
                            tsTypeValue.offsetTypeID = aRow.OffsetTypeID;
                            tsTypeValue.offsetTypeIDSpecified = true;

                            // enabled to fix issue with hydroobjects
                            ValuesDataSet.OffsetTypesRow off = ds.OffsetTypes.FindByOffsetTypeID(aRow.OffsetTypeID);

                            ValuesDataSet.UnitsRow offUnit = ds.Units.FindByUnitsID(off.OffsetUnitsID);
                            tsTypeValue.offsetUnitsCode = offUnit.UnitsID.ToString();
                            tsTypeValue.offsetUnitsAbbreviation = offUnit.UnitsAbbreviation;
                        }

                        // offset value may be separate from the units... anticpating changes for USGS
                        if (!aRow.IsOffsetValueNull())
                        {
                            tsTypeValue.offsetValue = aRow.OffsetValue;
                            tsTypeValue.offsetValueSpecified = true;
                        }

                        ValuesDataSet.MethodsRow meth = ds.Methods.FindByMethodID(aRow.MethodID);
                        tsTypeValue.methodID = aRow.MethodID;
                        tsTypeValue.methodIDSpecified = true;

                        if (!aRow.IsQualifierIDNull())
                        {
                            ValuesDataSet.QualifiersRow qual = ds.Qualifiers.FindByQualifierID(aRow.QualifierID);
                            if (qual != null)
                            {
                                tsTypeValue.qualifiers = qual.QualifierCode;

                            }
                        }

                        ValuesDataSet.QualityControlLevelsRow qcl =
                            ds.QualityControlLevels.FindByQualityControlLevelID(aRow.QualityControlLevelID);
                        string qlName = qcl.Definition.Replace(" ", "");

                        if (Enum.IsDefined(typeof(QualityControlLevelEnum), qlName))
                        {
                            tsTypeValue.qualityControlLevel = (QualityControlLevelEnum)
                                                              Enum.Parse(
                                                                  typeof(QualityControlLevelEnum), qlName, true);
                            if (tsTypeValue.qualityControlLevel != QualityControlLevelEnum.Unknown){
                             tsTypeValue.qualityControlLevelSpecified = true;
                            }
                        }
                        //}
                        tsTypeValue.sourceID = aRow.SourceID;
                        tsTypeValue.sourceIDSpecified = true;

                        if (!aRow.IsSampleIDNull())
                        {
                            tsTypeValue.sampleID = aRow.SampleID;
                            tsTypeValue.sampleIDSpecified = true;
                        }

                    }
                    catch (Exception e)
                    {
                        log.Debug("Error generating a value " + e.Message);
                        // non fatal exceptions
                    }

                    tsTypeList.Add(tsTypeValue);
                }
                catch (Exception e)
                {
                    //  ignore any value errors
                }

            }
            return tsTypeList;
        }
Esempio n. 9
0
            public static IEnumerable <ValueSingleVariable> dataset2ValuesList(ValuesDataSet ds, VariableParam variable, int?VariableId, VariablesDataset variablesDs)
            {
                Boolean          variableIsCategorical = false;
                VariableInfoType variableInfoType      = ODvariables.GetVariableByID(VariableId, variablesDs);

                if (variableInfoType != null && variableInfoType.dataType.Equals("Categorical"))
                {
                    variableIsCategorical = true;
                }

                /* logic
                 * if there is a variable that has options, then get a set of datarows
                 * using a select clause
                 * use an enumerator, since it is generic
                 * */

                IEnumerator dataValuesEnumerator;     // = ds.DataValues.GetEnumerator();

                ValuesDataSet.DataValuesRow[] dvRows; // if we find options, we need to use this.

                String select = OdValuesCommon.CreateValuesWhereClause(variable, VariableId);

                if (select.Length > 0)
                {
                    dvRows = (ValuesDataSet.DataValuesRow[])ds.DataValues.Select(select.ToString());

                    dataValuesEnumerator = dvRows.GetEnumerator();
                }
                else
                {
                    dataValuesEnumerator = ds.DataValues.GetEnumerator();
                }

                while (dataValuesEnumerator.MoveNext())
                {
                    ValuesDataSet.DataValuesRow aRow        = (ValuesDataSet.DataValuesRow)dataValuesEnumerator.Current;
                    ValueSingleVariable         tsTypeValue = new ValueSingleVariable();
                    Boolean goodValue = false;
                    try
                    {
                        tsTypeValue.dateTime = Convert.ToDateTime(aRow.DateTime);

                        DateTime temprealdate;

                        TimeSpan zone   = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
                        Double   offset = Convert.ToDouble(aRow.UTCOffset);
                        if (zone.TotalHours.Equals(offset))
                        {
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime),
                                                                DateTimeKind.Local);
                        }
                        else
                        {
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime), DateTimeKind.Utc);

                            temprealdate = temprealdate.AddHours(offset);
                        }
                        temprealdate         = Convert.ToDateTime(aRow.DateTime);
                        tsTypeValue.dateTime = temprealdate;


                        tsTypeValue.dateTimeUTC          = aRow.DateTimeUTC;
                        tsTypeValue.dateTimeUTCSpecified = true;
                        tsTypeValue.timeOffset           = OffsetDoubleToHoursMinutesString(aRow.UTCOffset);

                        //tsTypeValue.dateTime = new DateTimeOffset(temprealdate);
                        //tsTypeValue.dateTimeSpecified = true;


                        if (string.IsNullOrEmpty(aRow.Value.ToString()))
                        {
                            continue;
                        }
                        else
                        {
                            tsTypeValue.Value = Convert.ToDecimal(aRow.Value);
                        }

                        try
                        {
                            tsTypeValue.censorCode =
                                aRow.CensorCode;
                            if (!aRow.IsOffsetTypeIDNull())
                            {
                                //tsTypeValue.offsetTypeID = aRow.OffsetTypeID.ToString();
                                tsTypeValue.offsetTypeCode = aRow.OffsetTypeID.ToString();

                                // HIS-97 moved to OffsetUnitsType
                                //      ValuesDataSet.OffsetTypesRow off =
                                //        ds.OffsetTypes.FindByOffsetTypeID(aRow.OffsetTypeID);
                                //    ValuesDataSet.UnitsRow offUnit = ds.Units.FindByUnitsID(off.OffsetUnitsID);
                                //    tsTypeValue.offsetUnitsCode = offUnit.UnitsID.ToString();
                                //    tsTypeValue.offsetUnitsAbbreviation = offUnit.UnitsAbbreviation;
                            }

                            // offset value may be separate from the units... anticpating changes for USGS
                            if (!aRow.IsOffsetValueNull())
                            {
                                tsTypeValue.offsetValue          = aRow.OffsetValue;
                                tsTypeValue.offsetValueSpecified = true;
                            }

                            ValuesDataSet.MethodsRow meth = ds.Methods.FindByMethodID(aRow.MethodID);
                            // tsTypeValue.methodID = aRow.MethodID.ToString();
                            tsTypeValue.methodCode = aRow.MethodID.ToString();

                            // qualifiers
                            if (!aRow.IsQualifierIDNull())
                            {
                                ValuesDataSet.QualifiersRow qual = ds.Qualifiers.FindByQualifierID(aRow.QualifierID);
                                if (qual != null)
                                {
                                    tsTypeValue.qualifiers = qual.QualifierCode;
                                }
                            }

                            //  quality control level

                            ValuesDataSet.QualityControlLevelsRow qcl =
                                ds.QualityControlLevels.FindByQualityControlLevelID(aRow.QualityControlLevelID);
                            string qlName = qcl.Definition.Replace(" ", "");
                            tsTypeValue.qualityControlLevelCode = qcl.QualityControlLevelCode;
                            //if (!String.IsNullOrEmpty(qlName))
                            //{
                            //    tsTypeValue.qualityControlLevel = qlName;
                            //}


                            // tsTypeValue.sourceID = aRow.SourceID.ToString();
                            tsTypeValue.sourceCode = aRow.SourceID.ToString();

                            if (!aRow.IsSampleIDNull())
                            {
                                //tsTypeValue.sampleID = aRow.SampleID.ToString();
                                ValuesDataSet.SamplesRow lsc = ds.Samples.FindBySampleID(aRow.SampleID);
                                tsTypeValue.labSampleCode = lsc.LabSampleCode;
                            }

                            // categorical
                            if (variableIsCategorical && VariableId.HasValue)
                            {
                                tsTypeValue.codedVocabularyTerm = ODvariables.GetCategoryTerm(VariableId.Value, tsTypeValue.Value, variablesDs);
                                if (!String.IsNullOrEmpty(tsTypeValue.codedVocabularyTerm))
                                {
                                    tsTypeValue.codedVocabulary = true;
                                }
                                tsTypeValue.codedVocabularySpecified = true;
                            }
                        }
                        catch (Exception e)
                        {
                            log.Debug("Error generating a value " + e.Message);
                            // non fatal exceptions
                        }
                        goodValue = true;
                    }
                    catch (Exception e)
                    {
                        goodValue = false;
                        // If there is an error, we do not add it.
                    }

                    if (goodValue)
                    {
                        yield return(tsTypeValue);
                    }
                }
            }
Esempio n. 10
0
        public static string CreateValuesWhereClause(VariableParam variable, int? VariableId)
        {
            string qualityControlId = null;
            string methodId = null;
            string sourceId = null;
            if (variable != null && variable.options != null && variable.options.Count > 0)
            {
                foreach (KeyValuePair<string, string> opt in variable.options)
                {
                    switch (opt.Key.ToUpperInvariant())
                    {
                        case "QUALITYCONTROLLEVEL":
                            // TODO Implement QUALITYCONTROLLEVEL Text Matching
                            break;
                        case "QUALITYCONTROLLEVELID":
                        case "QUALITYCONTROLID":
                        case "QUALITYCONTROLCODE":
                        case "QUALITYCONTROLLEVELCODE":
                            if (!string.IsNullOrEmpty(opt.Value))
                                qualityControlId = opt.Value;
                            break;
                        case "METHOD":
                            // TODO Implement METHOD Text Matching
                            break;
                        case "METHODID":
                        case "METHODCODE":
                            if (!string.IsNullOrEmpty(opt.Value))
                                methodId = opt.Value;
                            break;
                        case "SOURCE":
                            // TODO Implement SOURCE Text Matching
                            break;
                        case "SOURCEID":
                        case "SOURCECODE":
                            if (!string.IsNullOrEmpty(opt.Value))
                                sourceId = opt.Value;
                            break;
                        case "ORGANIZATION":
                            // TODO Implement ORGANIZATION Text Matching
                            break;

                    }
                }
            }

            const string selectFormat = " {0}={1} ";
            StringBuilder select = new StringBuilder();
            if (VariableId.HasValue)
            {
                select.AppendFormat(selectFormat, "variableId", VariableId);
            }
            if (!string.IsNullOrEmpty(qualityControlId))
            {
                if (select.Length > 0) select.Append(" AND ");
                select.AppendFormat(selectFormat, "qualityControlLevelId", qualityControlId);
            }

            if (!string.IsNullOrEmpty(methodId))
            {
                if (select.Length > 0) select.Append(" AND ");
                select.AppendFormat(selectFormat, "methodId", methodId);
            }
            if (!string.IsNullOrEmpty(sourceId))
            {
                if (select.Length > 0) select.Append(" AND ");
                select.AppendFormat(selectFormat, "sourceId", sourceId);
            }
            return select.ToString();
        }
Esempio n. 11
0
        public ValuesDataSet getValuesDataset(int? siteId, int? variableId, W3CDateTime? BeginDateTime, W3CDateTime? EndDateTime, VariableParam variable)
        {
            ValuesDataSet valuesDs;
            if (variableId == null && BeginDateTime == null && EndDateTime == null)
            {
                valuesDs = ODValues.GetValuesDataSet(siteId.Value);
            }
            else if (variableId != null && BeginDateTime == null && EndDateTime == null)
            {
                valuesDs = ODValues.GetValuesDataSet(siteId, variableId);
            }
            else if (variableId != null && BeginDateTime != null && EndDateTime == null)
            {
                EndDateTime = W3CDateTime.Now;
                valuesDs = ODValues.GetValuesDataSet(siteId,
                                                     variableId,
                                                     BeginDateTime.Value,
                                                      EndDateTime.Value // set above
                    );
            }
            else if (variableId != null && BeginDateTime == null && EndDateTime != null)
            {
                BeginDateTime = W3CDateTime.Parse(ConfigurationManager.AppSettings["MinimalSQLDate"]);

                valuesDs = ODValues.GetValuesDataSet(siteId,
                                                     variableId,
                                                     BeginDateTime.Value,  // set above
                                                     EndDateTime.Value
                    );
            }
            else
            {
                valuesDs = ODValues.GetValuesDataSet(siteId,
                                                     variableId,
                                                     BeginDateTime.Value,
                                                     EndDateTime.Value
                    );
            }

            return valuesDs;
        }
Esempio n. 12
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;
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public ValuesDataSet getValuesDataset(int?siteId, int?variableId, W3CDateTime?BeginDateTime, W3CDateTime?EndDateTime, VariableParam variable)
        {
            ValuesDataSet valuesDs;

            if (variableId == null && BeginDateTime == null && EndDateTime == null)
            {
                valuesDs = ODValues.GetValuesDataSet(siteId.Value);
            }
            else if (variableId != null && BeginDateTime == null && EndDateTime == null)
            {
                valuesDs = ODValues.GetValuesDataSet(siteId, variableId);
            }
            else if (variableId != null && BeginDateTime != null && EndDateTime == null)
            {
                EndDateTime = W3CDateTime.Now;
                valuesDs    = ODValues.GetValuesDataSet(siteId,
                                                        variableId,
                                                        BeginDateTime.Value,
                                                        EndDateTime.Value // set above
                                                        );
            }
            else if (variableId != null && BeginDateTime == null && EndDateTime != null)
            {
                BeginDateTime = W3CDateTime.Parse(ConfigurationManager.AppSettings["MinimalSQLDate"]);

                valuesDs = ODValues.GetValuesDataSet(siteId,
                                                     variableId,
                                                     BeginDateTime.Value,  // set above
                                                     EndDateTime.Value
                                                     );
            }
            else
            {
                valuesDs = ODValues.GetValuesDataSet(siteId,
                                                     variableId,
                                                     BeginDateTime.Value,
                                                     EndDateTime.Value
                                                     );
            }

            return(valuesDs);
        }
Esempio n. 15
0
        public static VariableInfoType[] getVariables(VariableParam[] vParams, VariablesDataset ds)
        {
            List<VariableInfoType> vit = new List<VariableInfoType>();

            // if there are no variableParameters, return all varaibles
            if (vParams == null || vParams.Length == 0)
            {
                foreach (VariablesDataset.VariablesRow row in ds.Variables.Rows)
                {
                    VariableInfoType result = rowToVariableInfoType(row,
                                                                    ds
                        );
                    vit.Add(result);
                }
                return vit.ToArray();
            }
            else
            {
                foreach (VariableParam vParam in vParams)
                {
                    VariableInfoType[] vars = getVariable(vParam, ds);
                    if (vars != null) vit.AddRange(vars);
                }
                return vit.ToArray();
            }
        }
Esempio n. 16
0
        public static VariableInfoType[] getVariable(VariableParam vParam, VariablesDataset ds)
        {
            List<VariableInfoType> vars = new List<VariableInfoType>();
            if (vParam != null)
            {
                /* need to use a data view, so the we can set a filter that does not effect the whole dataset
                  DataView has a ToTable method that is uses to create a new DS, and fill
                 * a new VariablesDataset. Typed Datasets are useful ;)
                 */

                DataView view = new DataView();
                view.Table = ds.Tables["Variables"];

                if (vParam.IsId)
                {
                    view.RowFilter = "VariableID = " + vParam.Code + " ";
                }
                else
                {
                    view.RowFilter = "VariableCode = '" + vParam.Code + "' ";
                    // list of possible options. Allowing any will break the query (aka QualityControlLevelID, etc)
                    String[] options = {"samplemedium", "datatype", "valuetype"};

                    foreach (string opt in options)
                    {
                        if (vParam.options.ContainsKey(opt))
                        {
                            if (!String.IsNullOrEmpty(vParam.options[opt]))
                            {
                                String rowFilter = view.RowFilter + " AND "
                                                   + opt + "='" + vParam.options[opt] + "'";
                                view.RowFilter = rowFilter;
                            }
                        }
                    }
                }

                DataTable v = view.ToTable();
                if (v.Rows.Count > 0)
                {
                    VariablesDataset vtemp = new VariablesDataset();

                    vtemp.Variables.Merge(v);

                    foreach (VariablesDataset.VariablesRow row in vtemp.Variables.Rows)
                    {
                        VariableInfoType result = rowToVariableInfoType(row,
                                                                        ds
                            );
                        vars.Add(result);
                    }

                    return vars.ToArray();
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }