예제 #1
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());
                }
            }
예제 #2
0
        // Return number of records inserted or found.
        public static int HandleVariableInfo(SqlConnection sqlConn, VariableInfoType varInfo)
        {
            VariablesTableAdapter varAdapter = new VariablesTableAdapter();

            varAdapter.Connection = sqlConn;

            OD_1_1_1DataSet.VariablesDataTable tblVariables = new OD_1_1_1DataSet.VariablesDataTable();

            Console.WriteLine(">>>Parsing and inserting VARIABLES");

            InsertOneVariable(tblVariables, varInfo, sqlConn);

            try
            {
                varAdapter.Update(tblVariables);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to insert VARIABLE {0}: {1}",
                                  varInfo.variableCode[0].Value, e.Message);
                return(0);
            }

            return(1);
            //PrintTable(varAdapter, tblVariables);
        }
        // This routine is to fill in the data what stinfo and scts have. The IDs will
        // be updated when handling DataValues.
        OD_1_1_1DataSet.SeriesCatalogRow CreateNewSeriesCatalog(
            string siteCode, string varCode,
            seriesCatalogTypeSeries scts)
        {
            OD_1_1_1DataSet.SeriesCatalogRow row = Table.NewSeriesCatalogRow();
            VariableInfoType varInfo             = scts.variable;

            row.SiteID   = -1;
            row.SiteCode = siteCode;
            row.SiteName = null;

            row.VariableID   = -1;
            row.VariableCode = varInfo.variableCode[0].Value;
            row.VariableName = varInfo.variableName;

            row.Speciation = varInfo.speciation;

            row.VariableUnitsID   = Convert.ToInt32(varInfo.unit.unitCode);
            row.VariableUnitsName = varInfo.unit.unitName;

            row.SampleMedium = varInfo.sampleMedium;
            row.ValueType    = varInfo.valueType;

            row.TimeSupport   = varInfo.timeScale.timeSupport;
            row.TimeUnitsID   = Convert.ToInt32(varInfo.timeScale.unit.unitCode);
            row.TimeUnitsName = varInfo.timeScale.unit.unitName;

            row.DataType        = varInfo.dataType;
            row.GeneralCategory = varInfo.generalCategory;

            if (scts.method != null)
            {
                row.MethodID          = scts.method.methodID;
                row.MethodDescription = scts.method.methodDescription;
            }

            row.SourceID          = scts.source.sourceID;
            row.Organization      = scts.source.organization;
            row.SourceDescription = scts.source.sourceDescription;

            row.SetCitationNull();

            row.QualityControlLevelID   = scts.qualityControlLevel.qualityControlLevelID;
            row.QualityControlLevelCode = scts.qualityControlLevel.qualityControlLevelCode;

            // This table is to track what we have in DataValues table.
            // We don't have anything in DataValues table at this moment.
            TimeIntervalType ti = (TimeIntervalType)scts.variableTimeInterval;

            row.BeginDateTime    = ti.beginDateTime;
            row.EndDateTime      = OD_Utils.GetDateTime(row.BeginDateTime, row.TimeUnitsID, -1);
            row.BeginDateTimeUTC = ti.beginDateTime.ToUniversalTime();
            row.EndDateTimeUTC   = row.EndDateTime.ToUniversalTime();
            row.ValueCount       = 0;

            return(row);
        }
예제 #4
0
            public static VariableInfoType CreateVariableDescriptionType()
            {
                VariableInfoType vdt = new VariableInfoType();

                variableCode[] var = new variableCode[1];
                var[0]           = new variableCode();
                vdt.variableCode = var;
                vdt.units        = new units();
                return(vdt);
            }
        public static VariableInfoType[] GetVariablesByID(int[] variableIDs, VariablesDataset ds)
        {
            List <VariableInfoType> vars = new List <VariableInfoType>();


            if (variableIDs.Length == 0)
            {
                foreach (VariablesDataset.VariablesRow row in ds.Variables.Rows)
                {
                    VariableInfoType result = rowToVariableInfoType(row,
                                                                    ds
                                                                    );
                    vars.Add(result);
                }
                return(vars.ToArray());
            }
            else
            {
                StringBuilder sBuilder = new StringBuilder("(");
                int           i        = 0;
                foreach (int s in variableIDs)
                {
                    if (i > 0)
                    {
                        sBuilder.Append(",");
                    }
                    sBuilder.Append("'");
                    sBuilder.Append(s.ToString());
                    sBuilder.Append("'");
                    i++;
                }
                sBuilder.Append(")");

                //DataRow dr = ds.Tables["variables"].Select("variableCode = " + vCode);
                DataRow[] dr = ds.Tables["variables"].Select("variableID IN " + sBuilder.ToString());

                if (dr.Length > 0)
                {
                    foreach (DataRow row in dr)
                    {
                        VariableInfoType result = rowToVariableInfoType((
                                                                            VariablesDataset.VariablesRow)row,
                                                                        ds
                                                                        );
                        vars.Add(result);
                    }
                    return(vars.ToArray());
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #6
0
            /* need method that says
             * createSeriesCatalogRecord(
             * int variableID,
             *  Nullable<W3CDateTime> beginDateTime,
             *  Nullable<W3CDateTime> endDateTime,
             *  Nullable<int> valueCount
             *  )
             * */

            public static seriesCatalogTypeSeries CreateSeriesRecord(
                VariableInfoType variable,
                string sampleMedium,
                Nullable <W3CDateTime> beginDateTime,
                Nullable <W3CDateTime> endDateTime,
                Nullable <int> valueCount
                )
            {
                return(CreateSeriesRecord(variable, sampleMedium, beginDateTime, endDateTime,
                                          valueCount, null, null, null, null, false, "P31D", null, null, null, null, null, null, null));
            }
예제 #7
0
            /// <summary>
            /// Gets the variables.
            /// used to test the variable datatable.
            /// </summary>
            /// <returns></returns>
            public static VariableInfoType[] GetVariables()
            {
                List <VariableInfoType> vars = new List <VariableInfoType>();
                VariablesDataset        ds   = GetVariableDataSet();

                foreach (VariablesDataset.VariablesRow row in ds.Variables)
                {
                    VariableInfoType vit = rowToVariableInfoType(row, ds);
                    vars.Add(vit);
                }
                return(vars.ToArray());
            }
예제 #8
0
            public IEnumerable <TimeSeriesType> GetTimesSeriesTypeForSiteVariable(string SiteNumber, string StartDate, string EndDate)
            {
                W3CDateTime?BeginDateTime;
                W3CDateTime?EndDateTime;
                int?        variableId = null;
                int?        siteID;

                VariableInfoType varInfoType = null;
                SiteInfoType     siteType    = null;

                BeginDateTime = GetBeginDateTime(StartDate);

                EndDateTime = GetEndDateTime(EndDate);

                locationParam sq = GetLocationParameter(SiteNumber);

                siteInfoDataSet sitDs = ODSiteInfo.GetSiteInfoDataSet(sq);

                if (sitDs != null && sitDs.sites.Count > 0)
                {
                    siteID = sitDs.sites[0].SiteID;
                    ValuesDataSet valuesDs      = getValuesDataset(siteID, null, BeginDateTime, EndDateTime);
                    DataTable     variableTable = DataSetHelper.SelectDistinct("variableIds", valuesDs.DataValues, "VariableID");

                    if (variableTable.Rows.Count == 0)
                    {
                        throw new WaterOneFlowException("No Data Available for Time Period.");
                    }

                    foreach (DataRow dataRow in variableTable.Rows)
                    {
                        TimeSeriesType timeSeries = new TimeSeriesType();

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

                        int id = (int)dataRow[0];
                        VariableInfoType vit = ODvariables.GetVariableByID(id, variableDs);
                        timeSeries.variable = vit;


                        // DataView view = new DataView(valuesDs.DataValues, "VariableId = " + id, " DateTime ASC", DataViewRowState.CurrentRows);

                        timeSeries.values = getValues(valuesDs, null, id);

                        yield return(timeSeries);
                    }
                }
            }
예제 #9
0
            public static VariableInfoType CreateVariableInfoType(int varibleId, string vocab, string vCode, string vName, string vDescription, UnitsType aUnit)
            {
                VariableInfoType vdt = CreateVariableDescriptionType();

                vdt.variableCode[0].Value               = vCode;
                vdt.variableCode[0].vocabulary          = vocab;
                vdt.variableCode[0].variableID          = varibleId;
                vdt.variableCode[0].variableIDSpecified = true;
                vdt.variableCode[0].defaultSpecified    = true;
                vdt.variableCode[0].@default            = true;
                vdt.variableDescription = vDescription;
                vdt.variableName        = vName;
                vdt.unit = aUnit;

                return(vdt);
            }
예제 #10
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);
            }
예제 #11
0
            public VariableInfoType getVariableSchemaType()
            {
                VariableInfoType vdt = v1_1.CuahsiBuilder.CreateVariableDescriptionType();

                vdt.variableCode[0].Value      = Code;
                vdt.variableCode[0].vocabulary = Vocabulary;
                if (options.Count > 0)
                {
                    option[] opts = new option[options.Count];
                    int      i    = 0;
                    foreach (string key in options.Keys)
                    {
                        opts[i]       = new option();
                        opts[i].name  = key;
                        opts[i].Value = options[key];

                        i++;
                    }
                    vdt.options = opts;
                }
                return(vdt);
            }
            private VariableInfoType[] FixVariablesResponse(XmlDocument xdoc)
            {
                XmlRootAttribute root = new XmlRootAttribute("variable");

                Type[]                  types                 = new Type[0];
                XmlSerializer           varSerializar         = new XmlSerializer(typeof(VariableInfoType), null, types, root, WaterOneFlowImpl.Constants.XML_SCHEMA_NAMSPACE);
                List <VariableInfoType> vars                  = new List <VariableInfoType>();
                VariablesResponseType   variablesResponseType = new VariablesResponseType();

                foreach (XmlNode v in xdoc.GetElementsByTagName("variable", WaterOneFlowImpl.Constants.XML_SCHEMA_NAMSPACE))
                {
                    try
                    {
                        TextReader reader = new StringReader(v.OuterXml);


                        VariableInfoType variableInfoType = (VariableInfoType)varSerializar.Deserialize(reader);
                        vars.Add(variableInfoType);
                    } catch {
                        log.Debug("error serializing variable");
                    }
                }
                return(vars.ToArray());
            }
예제 #13
0
        public VariablesResponseType GetVariables(VariableParam[] variables)
        {
            UsgsDbDailyValues.VariablesDataTable vDs = new UsgsDbDailyValues.VariablesDataTable();

            UsgsDbDailyValuesTableAdapters.VariablesTableAdapter TableAdapter = new VariablesTableAdapter();

            List <VariableInfoType> vList = new List <VariableInfoType>();

            // if nothing. get it all
            if (variables == null || variables.Length == 0)
            {
                try
                {
                    TableAdapter.Fill(vDs);
                } catch
                {
                    log.Error("Cannot connect to USGS Database");
                    throw new WaterOneFlowServerException("Server Error: Cannot Connect to Database");
                }

                if (vDs.Rows.Count > 0)
                {
                    foreach (UsgsDbDailyValues.VariablesRow vRow
                             in vDs)
                    {
                        VariableInfoType vit = RowToVariable(vRow);

                        if (vit != null)
                        {
                            vList.Add(vit);
                        }
                    }
                }
            }
            else
            {
                foreach (VariableParam v in variables)
                {
                    UsgsDbDailyValues.VariablesRow[] vRows;
                    try
                    {
                        TableAdapter.FillByVariableCode(vDs, v.Code);

                        string where = VariableOptions2WhereClause(v); /* Use Caution, where clause not SQL inject safe. */
                        vRows        = (UsgsDbDailyValues.VariablesRow[])
                                       vDs.Select(where);
                    }
                    catch
                    {
                        log.Error("Cannot connect to USGS Database");
                        throw new WaterOneFlowServerException("Server Error: Cannot Connect to Database");
                    }
                    if (vRows.Length > 0)
                    {
                        foreach (UsgsDbDailyValues.VariablesRow vRow
                                 in vRows)
                        {
                            VariableInfoType vit = RowToVariable(vRow);

                            if (vit != null)
                            {
                                vList.Add(vit);
                            }
                        }
                    }
                }
            }

            //if (vDs.Rows.Count > 0)
            //{
            //    foreach (UsgsDbDailyValues.VariablesRow vRow
            //        in vDs)
            //    {


            //            VariableInfoType v = RowToVariable(vRow);

            //        if (v != null) vList.Add(v);

            //    }
            //}
            VariablesResponseType vRes = new VariablesResponseType();

            if (vList != null && vList.Count > 0)
            {
                // build response

                vRes.variables = vList.ToArray();
            }
            else
            {
                log.Info("User Error: No Variables Returned");
                throw new WaterOneFlowException("No Variables Returned. Submit with no values to get full list.");
            }
            return(vRes);
        }
예제 #14
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);
            }
 public static seriesCatalogTypeSeries CreateSeriesRecord(VariableInfoType variable, string sampleMedium, W3CDateTime? beginDateTime, W3CDateTime? endDateTime, int? valueCount, bool? valueCountIsEstimated, string dataType, string valueType, string generalCategory, bool realTime, string realTimeInterval, string qualityControlLevelCode, int? qualityControlLevelid, string methodName, int? methodID, string organization, string sourceDescription, int? sourceID, string citation)
 {
     return CreateSeriesRecord(variable, sampleMedium, beginDateTime, endDateTime, valueCount, valueCountIsEstimated, dataType, valueType, generalCategory, realTime, realTimeInterval, qualityControlLevelCode, qualityControlLevelid, methodName, methodID, organization, sourceDescription, sourceID, citation, false, null);
 }
예제 #16
0
            /// <summary>
            /// Builds a VariableInfoType which is part of the VariablesResponse;
            /// Columns:
            /// VariableID
            /// VariableCode (R)
            /// VariableVocabulary
            /// VariableName (r) - will display 'not specified'
            /// </summary>
            /// <param name="aRow"></param>
            /// <returns></returns>
            public static VariableInfoType CreateVariableRecord(DataRow aRow)
            {
                CoreTables.VariablesDataTable vDs = new CoreTables.VariablesDataTable();

                vDs.ImportRow(aRow);

                vDs.AcceptChanges();

                VariableInfoType vit = new VariableInfoType();

                if (vDs.Rows.Count > 0)
                {
                    CoreTables.VariablesRow row =
                        (CoreTables.VariablesRow)vDs.Rows[0];
                    {
                        // set attributes
                        if (!row.IsVariableIDNull())
                        {
                            vit.oid = row.VariableID.ToString();
                        }

                        // add a vCode
                        vit.variableCode = new VariableInfoTypeVariableCode[1];
                        VariableInfoTypeVariableCode vCode = new VariableInfoTypeVariableCode();
                        if (!row.IsVariableVocabularyNull())
                        {
                            vCode.vocabulary       = row.VariableVocabulary;
                            vCode.@default         = true;
                            vCode.defaultSpecified = true;
                        }
                        vCode.Value         = row.VariableCode;
                        vit.variableCode[0] = vCode;

                        // add name
                        if (!row.IsVariableNameNull())
                        {
                            vit.variableName = row.VariableName;
                        }
                        else
                        {
                            vit.variableName = "Not Specified.";
                        }

                        // value type
                        if (!row.IsValueTypeNull())
                        {
                            //                           SetEnumFromText(vit, row, "valueType", typeof(valueTypeEnum));

                            vit.valueType = row.ValueType;
                        }
                        //add DataType
                        if (!row.IsDataTypeNull())
                        {
                            //SetEnumFromText(vit, row, "dataType", typeof(dataTypeEnum));
                            vit.dataType = row.DataType;
                        }
                        //add General Categoy
                        //
                        if (!row.IsGeneralCategoryNull())
                        {
                            // SetEnumFromText(vit, row, "generalCategory", typeof(generalCategoryEnum));
                            vit.generalCategory = row.GeneralCategory;
                        }

                        // Units
                        // if just the ID exists... then it's not useful
                        if (!row.IsVariableUnitsNameNull() ||
                            !row.IsVariableUnitsAbbreviationNull())
                        {
                            UnitsType unit = new UnitsType();
                            if (!row.IsVariableUnitsNameNull())
                            {
                                unit.unitName = row.VariableUnitsName;
                            }
                            if (!row.IsVariableUnitsAbbreviationNull())
                            {
                                unit.unitAbbreviation = row.VariableUnitsAbbreviation;
                            }
                            if (!row.IsVariableUnitsIDNull())
                            {
                                unit.unitCode = row.VariableUnitsID.ToString();
                            }
                            vit.unit = unit;
                        }
                    }

                    // add time support
                    if (!row.IsIsRegularNull() && row.IsRegular)
                    {
                        vit.timeScale           = new VariableInfoTypeTimeScale();
                        vit.timeScale.isRegular = row.IsRegular;
                        //vit.timeScale.isRegularSpecified = true;

                        // add time support

                        // check to be sure we've got some vaild stuff
                        if (!row.IsTimeSupportNull())
                        {
                            vit.timeScale.timeSupport = row.TimeSupport;
                        }

                        if (!row.IsTimeUnitsNameNull() ||
                            !row.IsTimeUnitsAbbreviationNull()
                            )
                        {
                            vit.timeScale.unit = new UnitsType();
                            if (!row.IsTimeUnitsNameNull())
                            {
                                vit.timeScale.unit.unitName = row.TimeUnitsName;
                            }
                            if (!row.IsTimeUnitsAbbreviationNull())
                            {
                                vit.timeScale.unit.unitAbbreviation = row.TimeUnitsAbbreviation;
                            }

                            // vit.timeSupport.unit.UnitType = (UnitsTypeEnum)CoreBuilder.GetTextAsEnum("Time", typeof(UnitsTypeEnum));
                            vit.timeScale.unit.unitType = "Time";
                        }
                        else
                        {
                            // try to get info from time unitsID
                            ///@TODO fix this
                            //if (!row.IsTimeUnitsIDNull())
                            //{

                            //    vit.timeSupport.unit = new UnitsType();
                            //    vit.timeSupport.unit.UnitID = 104;
                            //    vit.timeSupport.unit.UnitIDSpecified = true;
                            //    vit.timeSupport.unit.UnitDescription = "day";
                            //    vit.timeSupport.unit.UnitAbbreviation = "d";
                            //    vit.timeSupport.unit.UnitType = (UnitsTypeEnum)CoreBuilder.GetTextAsEnum("Time", typeof(UnitsTypeEnum)); ;

                            //}
                        }
                    }
                }

                return(vit);
            }
예제 #17
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);
        }
예제 #18
0
        public static VariableInfoType[] GetVariablesFromDb()
        {
            List<VariableInfoType> variablesList = new List<VariableInfoType>();

            int[] variableIDs = { 1, 4, 5, 16 };

            foreach (int var_id in variableIDs)
            {
                VariableInfoType varInfo = new VariableInfoType();
                SetVariableProperties(var_id, varInfo);
                variablesList.Add(varInfo);
            }

            return variablesList.ToArray();
        }
예제 #19
0
        internal static void SetVariableProperties(int var_id, VariableInfoType varInfo)
        {
            //time support and time unit (same for all variables here)
            varInfo.timeScale = new VariableInfoTypeTimeScale();
            varInfo.timeScale.isRegular = true;
            varInfo.timeScale.timeSpacingSpecified = false;
            varInfo.timeScale.timeSupport = 1.0f;
            varInfo.timeScale.timeSupportSpecified = true;
            varInfo.timeScale.unit = new UnitsType();
            varInfo.timeScale.unit.unitAbbreviation = "hr";
            varInfo.timeScale.unit.unitCode = "103";
            varInfo.timeScale.unit.unitID = 103;
            varInfo.timeScale.unit.unitName = "hour";
            varInfo.timeScale.unit.unitType = "Time";

            //variable code (same computation for all variables here)
            varInfo.valueType = "Field Observation";

            varInfo.variableCode = new VariableInfoTypeVariableCode[1];
            varInfo.variableCode[0] = new VariableInfoTypeVariableCode();
            varInfo.variableCode[0].@default = true;
            varInfo.variableCode[0].defaultSpecified = true;
            varInfo.variableCode[0].Value = VariableIDToShortCode(var_id);
            varInfo.variableCode[0].vocabulary = ConfigurationManager.AppSettings["vocabulary"];
            varInfo.variableCode[0].variableID = var_id;

            switch(var_id)
            {
                case 1:
                    //precipitation
                    varInfo.dataType = "Incremental";
                    varInfo.generalCategory = "Climate";
                    varInfo.metadataTimeSpecified = false;
                    varInfo.noDataValue = -9999.0;
                    varInfo.noDataValueSpecified = true;
                    varInfo.sampleMedium = "Precipitation";
                    varInfo.speciation = "Not Applicable";

                    //variable unit
                    varInfo.unit = new UnitsType();
                    varInfo.unit.unitAbbreviation = "mm";
                    varInfo.unit.unitCode = "54";
                    varInfo.unit.unitDescription = "millimeter";
                    varInfo.unit.unitID = 1;
                    varInfo.unit.unitIDSpecified = true;
                    varInfo.unit.unitName = "millimeter";
                    varInfo.unit.unitType = "Length";
                    varInfo.variableName = "Precipitation";
                    break;
                case 4:
                    //water level
                    varInfo.dataType = "Average";
                    varInfo.generalCategory = "Hydrology";
                    varInfo.metadataTimeSpecified = false;
                    varInfo.noDataValue = -9999.0;
                    varInfo.noDataValueSpecified = true;
                    varInfo.sampleMedium = "Water";
                    varInfo.speciation = "Not Applicable";

                    //variable unit - centimeter
                    varInfo.unit = new UnitsType();
                    varInfo.unit.unitAbbreviation = "cm";
                    varInfo.unit.unitCode = "47";
                    varInfo.unit.unitDescription = "centimeter";
                    varInfo.unit.unitID = 47;
                    varInfo.unit.unitIDSpecified = true;
                    varInfo.unit.unitName = "centimeter";
                    varInfo.unit.unitType = "Length";

                    //variable value type and name
                    varInfo.valueType = "Field Observation";
                    varInfo.variableName = "Gage height";
                    break;
                case 5:
                    //discharge
                    varInfo.dataType = "Average";
                    varInfo.generalCategory = "Hydrology";
                    varInfo.metadataTimeSpecified = false;
                    varInfo.noDataValue = -9999.0;
                    varInfo.noDataValueSpecified = true;
                    varInfo.sampleMedium = "Water";
                    varInfo.speciation = "Not Applicable";

                    //variable unit - cubic meter per second
                    varInfo.unit = new UnitsType();
                    varInfo.unit.unitAbbreviation = "m^3/s";
                    varInfo.unit.unitCode = "36";
                    varInfo.unit.unitDescription = "cubic meters per second";
                    varInfo.unit.unitID = 36;
                    varInfo.unit.unitIDSpecified = true;
                    varInfo.unit.unitName = "cubic meters per second";
                    varInfo.unit.unitType = "Flow";

                    //variable value type and name
                    varInfo.valueType = "Field Observation";
                    varInfo.variableName = "Discharge";
                    break;
                case 8:
                    //snow
                    varInfo.dataType = "Average";
                    varInfo.generalCategory = "Climate";
                    varInfo.metadataTimeSpecified = false;
                    varInfo.noDataValue = -9999.0;
                    varInfo.noDataValueSpecified = true;
                    varInfo.sampleMedium = "Snow";
                    varInfo.speciation = "Not Applicable";

                    //variable unit
                    varInfo.unit = new UnitsType();
                    varInfo.unit.unitAbbreviation = "cm";
                    varInfo.unit.unitCode = "47";
                    varInfo.unit.unitDescription = "centimeter";
                    varInfo.unit.unitID = 47;
                    varInfo.unit.unitIDSpecified = true;
                    varInfo.unit.unitName = "centimeter";
                    varInfo.unit.unitType = "Length";

                    //variable value type and name
                    varInfo.valueType = "Field Observation";
                    varInfo.variableName = "Snow depth";
                    break;
                case 16:
                    //temperature
                    varInfo.dataType = "Average";
                    varInfo.generalCategory = "Climate";
                    varInfo.metadataTimeSpecified = false;
                    varInfo.noDataValue = -9999.0;
                    varInfo.noDataValueSpecified = true;
                    varInfo.sampleMedium = "Air";
                    varInfo.speciation = "Not Applicable";

                    //variable unit
                    varInfo.unit = new UnitsType();
                    varInfo.unit.unitAbbreviation = "degC";
                    varInfo.unit.unitCode = "96";
                    varInfo.unit.unitDescription = "degree celsius";
                    varInfo.unit.unitID = 96;
                    varInfo.unit.unitIDSpecified = true;
                    varInfo.unit.unitName = "degree celsius";
                    varInfo.unit.unitType = "Temperature";

                    //variable code
                    varInfo.valueType = "Field Observation";
                    varInfo.variableName = "Temperature";
                    break;
                case 17:
                    //temperature min
                    varInfo.dataType = "Minimum";
                    varInfo.generalCategory = "Climate";
                    varInfo.metadataTimeSpecified = false;
                    varInfo.noDataValue = -9999.0;
                    varInfo.noDataValueSpecified = true;
                    varInfo.sampleMedium = "Air";
                    varInfo.speciation = "Not Applicable";

                    //variable unit
                    varInfo.unit = new UnitsType();
                    varInfo.unit.unitAbbreviation = "degC";
                    varInfo.unit.unitCode = "96";
                    varInfo.unit.unitDescription = "degree celsius";
                    varInfo.unit.unitID = 96;
                    varInfo.unit.unitIDSpecified = true;
                    varInfo.unit.unitName = "degree celsius";
                    varInfo.unit.unitType = "Temperature";

                    //variable code
                    varInfo.valueType = "Field Observation";
                    varInfo.variableName = "Temperature";
                    break;
                case 18:
                    //temperature
                    varInfo.dataType = "Maximum";
                    varInfo.generalCategory = "Climate";
                    varInfo.metadataTimeSpecified = false;
                    varInfo.noDataValue = -9999.0;
                    varInfo.noDataValueSpecified = true;
                    varInfo.sampleMedium = "Air";
                    varInfo.speciation = "Not Applicable";

                    //variable unit
                    varInfo.unit = new UnitsType();
                    varInfo.unit.unitAbbreviation = "degC";
                    varInfo.unit.unitCode = "96";
                    varInfo.unit.unitDescription = "degree celsius";
                    varInfo.unit.unitID = 96;
                    varInfo.unit.unitIDSpecified = true;
                    varInfo.unit.unitName = "degree celsius";
                    varInfo.unit.unitType = "Temperature";

                    //variable code
                    varInfo.valueType = "Field Observation";
                    varInfo.variableName = "Temperature";
                    break;
            }
        }
 public static VariableInfoType CreateVariableDescriptionType()
 {
     VariableInfoType vdt = new VariableInfoType();
     variableCode[] var = new variableCode[1];
     var[0] = new variableCode();
     vdt.variableCode = var;
     vdt.units = new units();
     return vdt;
 }
예제 #21
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);
                }
            }
         public static seriesCatalogTypeSeries CreateSeriesRecord(
  VariableInfoType variable,
  string sampleMedium,
  Nullable<W3CDateTime> beginDateTime,
  Nullable<W3CDateTime> endDateTime,
  Nullable<int> valueCount,
  Nullable<Boolean> valueCountIsEstimated,
  string dataType
 )
         {
             return CreateSeriesRecord(variable, sampleMedium, beginDateTime, endDateTime,
                                       valueCount, valueCountIsEstimated, null, null, null, false, "P31D", null, null, null, null, null, null, null, null);
         }
예제 #23
0
            public static seriesCatalogTypeSeries CreateSeriesRecord(VariableInfoType variable, string sampleMedium, W3CDateTime?beginDateTime, W3CDateTime?endDateTime, int?valueCount, bool?valueCountIsEstimated, string dataType, string valueType, string generalCategory, bool realTime, string realTimeInterval, string QualityControlLevelTerm, int?qualityControlLevelid, string methodName, int?methodID, string organization, string sourceDescription, int?sourceID)
            {
                /* don't forget to check the VariableInfoType for the
                 * dataType,ValueType and General Category
                 *
                 */
                /*
                 * logic
                 * create seriesCatalogTypeSeries
                 * if variable != null use it. if null, make an empty variable
                 * if variable != null
                 *    and sampleMedium,dataType,valueType or generalCategory is null
                 *    try to get value from variable
                 * add datTime interface logic
                 *
                 */
                seriesCatalogTypeSeries series = new seriesCatalogTypeSeries();

                series.variable = variable != null ? variable : CreateVariableDescriptionType();
                if (valueCount.HasValue)
                {
                    series.valueCount       = new seriesCatalogTypeSeriesValueCount();
                    series.valueCount.Value = valueCount.Value;
                }



                // if begin time and end time are the same use single

                if (beginDateTime.HasValue)
                {
                    TimeIntervalType tm = new TimeIntervalType();

                    tm.beginDateTime = beginDateTime.Value.DateTime;

                    if (endDateTime.HasValue)
                    {
                        tm.endDateTime = endDateTime.Value.DateTime;
                    }
                    else
                    {
                        tm.endDateTime = tm.beginDateTime;
                    }
                    series.variableTimeInterval = tm;
                }


                if (realTime)
                {
                    TimePeriodRealTimeType rt = new TimePeriodRealTimeType();
                    rt.realTimeDataPeriod       = realTimeInterval; // 31 day Period
                    rt.beginDateTime            = DateTime.Today.AddDays(-31);
                    rt.endDateTime              = DateTime.Today;
                    series.variableTimeInterval = rt;
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (qualityControlLevelid.HasValue || !String.IsNullOrEmpty(QualityControlLevelTerm))
                {
                    series.QualityControlLevel = new QualityControlLevelType();
                    // need to have a dataset with an enum so we can
                    // SetEnumFromText(qsds,row,series.QualityControlLevel, typeof(QualityControlLevelEnum));
                    if (qualityControlLevelid.HasValue)
                    {
                        series.QualityControlLevel.qualityControlLevelID          = qualityControlLevelid.Value;
                        series.QualityControlLevel.qualityControlLevelIDSpecified = true;
                    }
                    if (!String.IsNullOrEmpty(QualityControlLevelTerm))
                    {
                        series.QualityControlLevel.Value = QualityControlLevelTerm;

                        // originally defined as an enum, but enums cannot be empty, and we have an id
                        // QualityControlLevelTerm = QualityControlLevelTerm.Replace(" ", "");
                        // if (Enum.IsDefined(typeof(QualityControlLevelEnum), QualityControlLevelTerm))
                        // {
                        //     object aEnum = Enum.Parse(typeof(QualityControlLevelEnum), QualityControlLevelTerm);
                        //     series.QualityControlLevel.Value = (QualityControlLevelEnum)aEnum;
                        // }
                    }
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (!String.IsNullOrEmpty(methodName) || methodID.HasValue)
                {
                    MethodType method = new MethodType();
                    if (!String.IsNullOrEmpty(methodName))
                    {
                        method.MethodDescription = methodName;
                    }
                    if (methodID.HasValue)
                    {
                        method.methodID = methodID.Value;
                    }
                    series.Method = method;
                }
                if (!String.IsNullOrEmpty(sourceDescription) ||
                    !String.IsNullOrEmpty(organization) ||
                    sourceID.HasValue)
                {
                    SourceType source = new SourceType();
                    if (!String.IsNullOrEmpty(sourceDescription) ||
                        !String.IsNullOrEmpty(organization))
                    {
                        source.SourceDescription = sourceDescription;
                        source.Organization      = organization;
                    }
                    if (sourceID.HasValue)
                    {
                        source.sourceID = sourceID.Value;
                    }
                    series.Source = source;
                }

                return(series);
            }
            public static seriesCatalogTypeSeries CreateSeriesRecord(VariableInfoType variable, string sampleMedium, W3CDateTime? beginDateTime, W3CDateTime? endDateTime, int? valueCount, bool? valueCountIsEstimated, string dataType, string valueType, string generalCategory, bool realTime, string realTimeInterval, string QualityControlLevelTerm, int? qualityControlLevelid, string methodName, int? methodID, string organization, string sourceDescription, int? sourceID, string citation)
            {
                /* don't forget to check the VariableInfoType for the
                 * dataType,ValueType and General Category
                 *
                 */
                /*
                 * logic
                 * create seriesCatalogTypeSeries
                 * if variable != null use it. if null, make an empty variable
                 * if variable != null
                 *    and sampleMedium,dataType,valueType or generalCategory is null
                 *    try to get value from variable
                 * add datTime interface logic
                 *
                 */
                seriesCatalogTypeSeries series = new seriesCatalogTypeSeries();
                series.variable = variable != null ? variable : CreateVariableDescriptionType();
                if (valueCount.HasValue)
                {
                series.valueCount = new seriesCatalogTypeSeriesValueCount();
                series.valueCount.Value = valueCount.Value;
                }

                // if begin time and end time are the same use single

                if (beginDateTime.HasValue)
                {
                TimeIntervalType tm = new TimeIntervalType();

                   // tm.beginDateTime = new DateTimeOffset(beginDateTime.Value.DateTime);
                tm.beginDateTime = beginDateTime.Value.DateTime;

                if (endDateTime.HasValue)
                {
                  //  tm.endDateTime = new DateTimeOffset(endDateTime.Value.DateTime);
                    tm.endDateTime = endDateTime.Value.DateTime;
                }
                else
                {
                    tm.endDateTime = tm.beginDateTime;
                }
                series.variableTimeInterval = tm;
                }

                if (realTime)
                {
                TimePeriodRealTimeType rt = new TimePeriodRealTimeType();
                rt.realTimeDataPeriod = realTimeInterval; // 31 day Period
                //rt.beginDateTime = new DateTimeOffset(DateTime.Today.AddDays(-31));
                //rt.endDateTime = new DateTimeOffset(DateTime.Today);
                rt.beginDateTime = DateTime.Today.AddDays(-31);
                rt.endDateTime = DateTime.Today;
                series.variableTimeInterval = rt;
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (qualityControlLevelid.HasValue || !String.IsNullOrEmpty(QualityControlLevelTerm))
                {
                series.QualityControlLevel = new QualityControlLevelType();
                // need to have a dataset with an enum so we can
                // SetEnumFromText(qsds,row,series.QualityControlLevel, typeof(QualityControlLevelEnum));
                if (qualityControlLevelid.HasValue)
                {
                    series.QualityControlLevel.qualityControlLevelID = qualityControlLevelid.Value;
                    series.QualityControlLevel.qualityControlLevelIDSpecified = true;
                }
                if (!String.IsNullOrEmpty(QualityControlLevelTerm))
                {
                    series.QualityControlLevel.Value = QualityControlLevelTerm;

                  // originally defined as an enum, but enums cannot be empty, and we have an id
                    // QualityControlLevelTerm = QualityControlLevelTerm.Replace(" ", "");
                   // if (Enum.IsDefined(typeof(QualityControlLevelEnum), QualityControlLevelTerm))
                   // {
                   //     object aEnum = Enum.Parse(typeof(QualityControlLevelEnum), QualityControlLevelTerm);
                   //     series.QualityControlLevel.Value = (QualityControlLevelEnum)aEnum;
                   // }

                }
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (!String.IsNullOrEmpty(methodName) || methodID.HasValue)
                {
                MethodType method = new MethodType();
                if ( !String.IsNullOrEmpty(methodName)  )
                { method.MethodDescription = methodName;
                }
                if (methodID.HasValue) {
                    method.methodID = methodID.Value;
                    method.methodIDSpecified = true;

                }
                series.Method = method;
                }
                if (!String.IsNullOrEmpty(sourceDescription) ||
                !String.IsNullOrEmpty(organization) ||
                sourceID.HasValue)
                {
                SourceType source = new SourceType();
                if (!String.IsNullOrEmpty(sourceDescription) ||
                !String.IsNullOrEmpty(organization) )
                {
                    source.SourceDescription = sourceDescription;
                source.Organization = organization;

                }
                if (sourceID.HasValue)
                {
                    source.sourceID = sourceID.Value;
                    source.sourceIDSpecified = true;
                }
                series.Source = source;
                }

                return series;
            }
            public static seriesCatalogTypeSeries row2SeriesCatalogElement(seriesCatalogDataSet.SeriesCatalogRow row, seriesCatalogDataSet ds, VariablesDataset vds, ControlledVocabularyDataset vocabularyDataset)
            {
                int variableID = row.VariableID;
                VariableInfoType       variable      = ODvariables.GetVariableByID(variableID, vds);
                Nullable <W3CDateTime> beginDateTime = null;

                if (!row.IsBeginDateTimeNull())
                {
                    TimeSpan timeSpan = row.BeginDateTime.Subtract(row.BeginDateTimeUTC);
                    beginDateTime = new W3CDateTime(row.BeginDateTime, timeSpan);
                }

                Nullable <W3CDateTime> endDateTime = null;

                if (!row.IsEndDateTimeNull())
                {
                    TimeSpan timeSpan = row.EndDateTime.Subtract(row.EndDateTimeUTC);
                    endDateTime = new W3CDateTime(row.EndDateTime, timeSpan);
                }

                Nullable <int> valueCount = null;

                if (!row.IsValueCountNull())
                {
                    valueCount = row.ValueCount;
                }

                string qualityControlLevelTerm = null;
                int?   QualityControlLevelid   = null;

                if (!row.IsQualityControlLevelIDNull())
                {
                    QualityControlLevelid = row.QualityControlLevelID;
                    ControlledVocabularyDataset.QualityControlLevelsRow qcRow =
                        vocabularyDataset.QualityControlLevels.FindByQualityControlLevelID(QualityControlLevelid.Value);
                    if (qcRow != null)
                    {
                        qualityControlLevelTerm = qcRow.Definition;
                    }
                }

                int?MethodID = null;

                if (!row.IsMethodIDNull())
                {
                    MethodID = row.MethodID;
                }

                int?SourceID = null;

                if (!row.IsSourceIDNull())
                {
                    SourceID = row.SourceID;
                }

                Nullable <Boolean> valueCountIsEstimated = false;

                /* public static seriesCatalogTypeSeries createSeriesCatalogRecord(
                 *      VariableInfoType variable,
                 *      string sampleMedium,
                 *      Nullable<W3CDateTime> beginDateTime,
                 *      Nullable<W3CDateTime> endDateTime,
                 *      Nullable<int> valueCount,
                 *       Nullable<Boolean> valueCountIsEstimated,
                 *      string dataType,
                 *      string valueType,
                 *      string generalCategory
                 *     )
                 */
                seriesCatalogTypeSeries record = CuahsiBuilder.CreateSeriesRecord(
                    variable,
                    variable.sampleMedium.ToString(),
                    beginDateTime,
                    endDateTime,
                    valueCount,
                    valueCountIsEstimated,
                    null,
                    null,
                    null,
                    false, // real time
                    null,  // string if real time
                    row.QualityControlLevelCode,
                    QualityControlLevelid,
                    row.MethodDescription,
                    MethodID, row.Organization,
                    row.SourceDescription,
                    SourceID,
                    row.Citation,
                    true, // include UTC Time
                    qualityControlLevelTerm
                    );

                return(record);
            }
        public static seriesCatalogTypeSeries row2SeriesCatalogElement(
            seriesCatalogDataSet.SeriesCatalogRow row,
            seriesCatalogDataSet ds, VariablesDataset vds)
        {
            int variableID = row.VariableID;
            VariableInfoType       variable      = ODvariables.GetVariableByID(variableID, vds);
            Nullable <W3CDateTime> beginDateTime = null;

            if (!row.IsBeginDateTimeNull())
            {
                beginDateTime = new W3CDateTime(row.BeginDateTime);
            }

            Nullable <W3CDateTime> endDateTime = null;

            if (!row.IsEndDateTimeNull())
            {
                endDateTime = new W3CDateTime(row.EndDateTime);
            }

            Nullable <int> valueCount = null;

            if (!row.IsValueCountNull())
            {
                valueCount = row.ValueCount;
            }

            int?QualityControlLevelid = null;

            if (!row.IsQualityControlLevelIDNull())
            {
                QualityControlLevelid = row.QualityControlLevelID;
            }

            int?MethodID = null;

            if (!row.IsMethodIDNull())
            {
                MethodID = row.MethodID;
            }

            int?SourceID = null;

            if (!row.IsSourceIDNull())
            {
                SourceID = row.SourceID;
            }


            Nullable <Boolean> valueCountIsEstimated = false;

            seriesCatalogTypeSeries record = CuahsiBuilder.CreateSeriesRecord(
                variable,
                variable.sampleMedium.ToString(),
                beginDateTime,
                endDateTime,
                valueCount,
                valueCountIsEstimated,
                null,
                null,
                null,
                false, // real time
                null,  // string if real time
                null,
                QualityControlLevelid,
                row.MethodDescription, MethodID,
                row.Organization, row.SourceDescription,
                SourceID,
                row.Citation);

            return(record);
        }
        /// <summary>
        /// Builds a VariableInfoType from a dataset row
        /// the dataSet is stored in the NWISService variableDataSet.
        /// Find the rwo you want with the command:
        ///
        /// and convert.
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static VariableInfoType rowToVariableInfoType(VariablesDataset.VariablesRow row, VariablesDataset ds)
        {
            units aUnit = null;

            aUnit = getUnitsElement(row.VariableUnitsID, ds);


            String vCode = !String.IsNullOrEmpty(row.VariableCode) ? row.VariableCode : null;

            int vid = row.VariableID;
            // appSetting['vocabulary']

            String vocab   = System.Configuration.ConfigurationManager.AppSettings["vocabulary"];
            String varName = !String.IsNullOrEmpty(row.VariableName) ? row.VariableName : null;

            VariableInfoType vt = CuahsiBuilder.CreateVariableInfoType(
                vid.ToString(),
                vocab,
                vCode,
                varName,
                null, //variable description
                aUnit
                );

            // add time support
            vt.timeSupport = new VariableInfoTypeTimeSupport();
            if (row.IsRegular)
            {
                vt.timeSupport.isRegular             = true;
                vt.timeSupport.isRegularSpecified    = true;
                vt.timeSupport.timeInterval          = Convert.ToInt32(row.TimeSupport);
                vt.timeSupport.timeIntervalSpecified = true;
                // this is different that the other "units", so populate by code
                units tUnit = getUnitsElement(row.TimeUnitsID, ds);
                if (tUnit != null)
                {
                    vt.timeSupport.unit                  = new UnitsType();
                    vt.timeSupport.unit.UnitID           = int.Parse(tUnit.unitsCode);
                    vt.timeSupport.unit.UnitIDSpecified  = true;
                    vt.timeSupport.unit.UnitDescription  = tUnit.Value;
                    vt.timeSupport.unit.UnitAbbreviation = tUnit.unitsAbbreviation;
                    if (tUnit.unitsTypeSpecified)
                    {
                        // if it's specified in the units, then it's a valid enum
                        vt.timeSupport.unit.UnitType          = tUnit.unitsType;
                        vt.timeSupport.unit.UnitTypeSpecified = true;
                    }
                }
            }
            else
            {
                vt.timeSupport.isRegular          = false;
                vt.timeSupport.isRegularSpecified = true;
            }
            CuahsiBuilder.SetEnumFromText(vt, row, "valueType", typeof(valueTypeEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "sampleMedium", typeof(SampleMediumEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "dataType", typeof(dataTypeEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "generalCategory", typeof(generalCategoryEnum));
            // if (!String.IsNullOrEmpty(row.NoDataValue)) {
            vt.NoDataValue = row.NoDataValue.ToString();
            // }
            return(vt);
        }
예제 #28
0
            public static seriesCatalogTypeSeries CreateSeriesRecord(VariableInfoType variable, string sampleMedium, W3CDateTime?beginDateTime, W3CDateTime?endDateTime, int?valueCount, bool?valueCountIsEstimated, string dataType, string valueType, string generalCategory, bool realTime, string realTimeInterval, string qualityControlLevelCode, int?qualityControlLevelid, string methodName, int?methodID, string organization, string sourceDescription, int?sourceID, string citation, bool addUtCDateTime, string qualityControlLevelTerm)
            {
                /* don't forget to check the VariableInfoType for the
                 * dataType,ValueType and General Category
                 *
                 */
                /*
                 * logic
                 * create seriesCatalogTypeSeries
                 * if variable != null use it. if null, make an empty variable
                 * if variable != null
                 *    and sampleMedium,dataType,valueType or generalCategory is null
                 *    try to get value from variable
                 * add datTime interface logic
                 *
                 */
                seriesCatalogTypeSeries series = new seriesCatalogTypeSeries();

                series.variable = variable != null ? variable : CreateVariableDescriptionType();
                if (valueCount.HasValue)
                {
                    series.valueCount       = new seriesCatalogTypeSeriesValueCount();
                    series.valueCount.Value = valueCount.Value;
                }



                // if begin time and end time are the same use single

                if (beginDateTime.HasValue)
                {
                    TimeIntervalType tm = new TimeIntervalType();

                    //tm.beginDateTime = new DateTimeOffset(beginDateTime.Value.DateTime);
                    tm.beginDateTime = beginDateTime.Value.DateTime;
                    if (addUtCDateTime)
                    {
                        tm.beginDateTimeUTC          = beginDateTime.Value.UtcTime;
                        tm.beginDateTimeUTCSpecified = true;
                    }

                    if (endDateTime.HasValue)
                    {
                        //tm.endDateTime = new DateTimeOffset(endDateTime.Value.DateTime);
                        tm.endDateTime = endDateTime.Value.DateTime;
                        if (addUtCDateTime)
                        {
                            tm.endDateTimeUTC          = endDateTime.Value.UtcTime;
                            tm.endDateTimeUTCSpecified = true;
                        }
                    }
                    else
                    {
                        tm.endDateTime = tm.beginDateTime;
                        if (addUtCDateTime)
                        {
                            tm.endDateTimeUTC          = tm.beginDateTimeUTC;
                            tm.endDateTimeUTCSpecified = true;
                        }
                    }

                    series.variableTimeInterval = tm;
                }


                if (realTime)
                {
                    TimePeriodRealTimeType rt = new TimePeriodRealTimeType();
                    rt.realTimeDataPeriod = realTimeInterval; // 31 day Period
                    //rt.beginDateTime = new DateTimeOffset(DateTime.Today.AddDays(-31));
                    //rt.endDateTime = new DateTimeOffset(DateTime.Today);
                    rt.beginDateTime            = DateTime.Today.AddDays(-31);
                    rt.endDateTime              = DateTime.Today;
                    series.variableTimeInterval = rt;
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (qualityControlLevelid.HasValue ||
                    !String.IsNullOrEmpty(qualityControlLevelCode))
                {
                    series.qualityControlLevel = new QualityControlLevelType();
                    // need to have a dataset with an enum so we can
                    // SetEnumFromText(qsds,row,series.QualityControlLevel, typeof(QualityControlLevelEnum));
                    if (qualityControlLevelid.HasValue)
                    {
                        series.qualityControlLevel.qualityControlLevelID          = qualityControlLevelid.Value;
                        series.qualityControlLevel.qualityControlLevelIDSpecified = true;
                    }
                    if (!String.IsNullOrEmpty(qualityControlLevelCode))
                    {
                        if (!String.IsNullOrEmpty(qualityControlLevelCode))
                        {
                            series.qualityControlLevel.qualityControlLevelCode = qualityControlLevelCode;
                        }
                    }
                    if (!String.IsNullOrEmpty(qualityControlLevelTerm))
                    {
                        series.qualityControlLevel.definition = qualityControlLevelTerm;
                    }
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (!String.IsNullOrEmpty(methodName) || methodID.HasValue)
                {
                    MethodType method = new MethodType();
                    if (!String.IsNullOrEmpty(methodName))
                    {
                        method.methodDescription = methodName;
                    }
                    if (methodID.HasValue)
                    {
                        method.methodID          = methodID.Value;
                        method.methodIDSpecified = true;
                    }
                    series.method = method;
                }
                if (!String.IsNullOrEmpty(sourceDescription) ||
                    !String.IsNullOrEmpty(organization) ||
                    !String.IsNullOrEmpty(citation) ||
                    sourceID.HasValue)
                {
                    SourceType source = new SourceType();
                    if (!String.IsNullOrEmpty(sourceDescription) ||
                        !String.IsNullOrEmpty(organization))
                    {
                        source.sourceDescription = sourceDescription;
                        source.organization      = organization;
                        source.citation          = citation;
                    }
                    if (sourceID.HasValue)
                    {
                        source.sourceID          = sourceID.Value;
                        source.sourceIDSpecified = true;
                    }
                    series.source = source;
                }

                return(series);
            }
예제 #29
0
        static void InsertOneVariable(OD_1_1_1DataSet.VariablesDataTable tblVariables,
                                      VariableInfoType varInfo, SqlConnection sqlConn)
        {
            string cond;

            OD_1_1_1DataSet.VariablesRow row = tblVariables.NewVariablesRow();

            string[] vars = Regex.Split(varInfo.variableCode[0].Value, "/");
            row.DataType = varInfo.dataType;
            //row.DataType = OD_Utils.ConvertToString(varInfo.dataType);
            row.VariableCode = vars[0] + "_" + row.DataType;

            // Check if the variable is already in the table or not
            //??? need to add ValueType filter
            cond = "VariableCode = '" + row.VariableCode + "'";
            if (OD_Utils.Exists(row.Table.TableName, cond, sqlConn))
            {
                return;
            }

            // VariableName is a tricky one too
            //??? I think VariableCode is enough to differentiate different variables
            cond = "Term = '" + varInfo.variableName + "'";
            if (OD_Utils.Exists("VariableNameCV", cond, sqlConn))
            {
                // Found it and use it
                row.VariableName = varInfo.variableName;
            }
            else
            {
                string myString = varInfo.variableName;
                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\bas\b");
                string[] splitString = reg.Split(myString);

                // Refer to the document, e.g.,
                //    including "as", eg., "Nitrogen, nitrate (NO3) as N, filtered"
                //    fix ing "Calcium, filtered as Ca"
                if (splitString.Length == 2)
                {
                    row.VariableName = splitString[0];
                }
                else
                {
                    // Remove the string after ","
                    vars             = Regex.Split(varInfo.variableName, ",");
                    row.VariableName = vars[0];
                }
            }

            row.Speciation = varInfo.speciation; // "Not Applicable"; //?
            // Note: in DavtaValue Response Type units.unitsCode is actually unitsAbbreviation
            if (varInfo.unit.unitCode != null)
            {
                //cond = "UnitsName = '" + varInfo.unit.unitName + "'";
                //row.VariableUnitsID = OD_Utils.GetPrimaryKey("Units", "UnitsID", cond, sqlConn);
                //if (row.VariableUnitsID >= 143) row.VariableUnitsID = row.VariableUnitsID + 1;
                row.VariableUnitsID = Convert.ToInt32(varInfo.unit.unitCode);
            }
            else
            {
                row.VariableUnitsID = varInfo.unit.unitID;
            }


            row.SampleMedium = varInfo.sampleMedium;

            row.ValueType = varInfo.valueType;

            row.IsRegular = varInfo.timeScale.isRegular;

            row.TimeSupport = varInfo.timeScale.timeSupport;

            if (varInfo.timeScale.unit.unitCode != null)
            {
                row.TimeUnitsID = Convert.ToInt32(varInfo.timeScale.unit.unitCode);
            }
            else
            {
                row.TimeUnitsID = varInfo.timeScale.unit.unitID;
            }

            row.GeneralCategory = varInfo.generalCategory;

            if (varInfo.noDataValue != null)
            {
                row.NoDataValue = varInfo.noDataValue;
            }
            else
            {
                row.NoDataValue = -9999;
            }

            tblVariables.AddVariablesRow(row);
        }
예제 #30
0
 public static seriesCatalogTypeSeries CreateSeriesRecord(VariableInfoType variable, string sampleMedium, W3CDateTime?beginDateTime, W3CDateTime?endDateTime, int?valueCount, bool?valueCountIsEstimated, string dataType, string valueType, string generalCategory, bool realTime, string realTimeInterval, string qualityControlLevelCode, int?qualityControlLevelid, string methodName, int?methodID, string organization, string sourceDescription, int?sourceID, string citation)
 {
     return(CreateSeriesRecord(variable, sampleMedium, beginDateTime, endDateTime, valueCount, valueCountIsEstimated, dataType, valueType, generalCategory, realTime, realTimeInterval, qualityControlLevelCode, qualityControlLevelid, methodName, methodID, organization, sourceDescription, sourceID, citation, false, null));
 }
예제 #31
0
        internal static VariableInfoType GetVariableInfoFromDb(string VariableParameter)
        {
            VariableInfoType varInfo = new VariableInfoType();
            int var_id = VariableCodeToID(VariableParameter);
            SetVariableProperties(var_id, varInfo);

            return varInfo;
        }
예제 #32
0
            /// <summary>
            /// Builds a VariableInfoType from a dataset row
            /// the dataSet is stored in the NWISService variableDataSet.
            /// Find the rwo you want with the command:
            ///
            /// and convert.
            /// </summary>
            /// <param name="row"></param>
            /// <returns></returns>
            public static VariableInfoType rowToVariableInfoType(VariablesDataset.VariablesRow row, VariablesDataset ds)
            {
                UnitsType aUnit = null;


                aUnit = getUnitsElement(row.VariableUnitsID, ds);


                String vCode = row.VariableCode;

                int vid = row.VariableID;

                String vocab   = System.Configuration.ConfigurationManager.AppSettings["vocabulary"];
                String varName = row.VariableName;

                VariableInfoType vt = CuahsiBuilder.CreateVariableInfoType(
                    vid,
                    vocab,
                    vCode,
                    varName,
                    null, //variable description
                    aUnit
                    );

                // add time support
                vt.timeScale = new VariableInfoTypeTimeScale();


                vt.timeScale.isRegular = row.IsRegular;

                vt.timeScale.timeSupport          = Convert.ToInt32(row.TimeSupport);
                vt.timeScale.timeSupportSpecified = true;

                // future, when ODM reports spacing
                //if (row.["timeSpacing"] != null)
                //{
                //    vt.timeScale.timeSpacing = Convert.ToInt32(row["timeSpacing"]);
                //    vt.timeScale.timeSpacingSpecified = true;
                //}


                UnitsType tUnit = getUnitsElement(row.TimeUnitsID, ds);

                if (tUnit != null)
                {
                    vt.timeScale.unit = tUnit;
                }

                vt.valueType    = String.IsNullOrEmpty(row.ValueType) ? null : row.ValueType;
                vt.sampleMedium = String.IsNullOrEmpty(row.SampleMedium) ? null : row.SampleMedium;
                vt.dataType     = String.IsNullOrEmpty(row.DataType) ? null : row.DataType;
                if (vt.dataType.Equals("Categorical", StringComparison.InvariantCultureIgnoreCase))
                {
                    IEnumerable <VariableInfoTypeCategory> categories = getCategoryElement(vid, ds);
                    vt.categories = new List <VariableInfoTypeCategory>(categories).ToArray();
                }
                vt.generalCategory = String.IsNullOrEmpty(row.GeneralCategory) ? null : row.GeneralCategory;

                // zero is default value for datatype... so don't add it if it is the default value
                if (!row.NoDataValue.Equals(0))
                {
                    vt.noDataValue          = row.NoDataValue;
                    vt.noDataValueSpecified = true;
                }

                vt.speciation = String.IsNullOrEmpty(row.Speciation) ? null : row.Speciation;


                return(vt);
            }
예제 #33
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;
            }
예제 #34
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);
                    }
                }
            }