Ejemplo n.º 1
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);
            }
Ejemplo n.º 2
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);
                    }
                }
            }