Example #1
0
            private TsValuesSingleVariableType CreateGWTimeSeriesObject(VariableParam vp, string aURL)
            {
                // download the iformation
                String resultFile = USGSCommon.GetHTTPFile(aURL, 10);

                TsValuesSingleVariableType values = new TsValuesSingleVariableType();
                //result.TimeSeries.Values.valueUnits = units; // this needs to be done earlier


                DataTable aTable = NWISDelimitedTextParser.ParseFileIntoDT(resultFile);

                // dwv add code to get the code, and use that to find the correct columns
                int    time = 2; // present location of time column
                String code = vp.Code;
                String stat = null;
                int    aValue;
                int    qualifier;

                //if (result.timeSeries.variable.options != null)
                //{
                //    stat = result.timeSeries.variable.options[0].Value;
                //}
                try
                {
                    aValue    = USGSCommon.getVarColumn(aTable, "lev_va", null); // uses eEndWith... so this should work
                    qualifier = USGSCommon.getVarQualifiersColumn(aTable, "lev_status_cd", null);
                }
                catch (WaterOneFlowException we)
                {
                    // need to insert the URL in the exception
                    if (string.IsNullOrEmpty(stat))
                    {
                        throw new WaterOneFlowException("URL: '" + aURL, we);
                        //+"' variable '"+code+"' not found at site.");
                    }
                    else
                    {
                        throw new WaterOneFlowException("URL: '" + aURL, we);
                        //+ "' variable '"+code+"' statistic '"+stat +"' not found at site. Try not using the statistic", we);
                    }
                }

                List <ValueSingleVariable> tsTypeList = new List <ValueSingleVariable>();

                //TimeSeriesFromRDB(aTable, time, aValue, qualifier, tsTypeList);

                USGSCommon.TimeSeriesFromRDB(aTable, time, aValue, qualifier, tsTypeList, false);

                values.count = tsTypeList.Count;
                values.value = tsTypeList.ToArray();

                return(values);
            }
            private TsValuesSingleVariableType CreateWQTimeSeriesObject(VariableParam vp, string aURL)
            {
                // download the iformation
                String resultFile = USGSCommon.GetHTTPFile(aURL, 10);

                TsValuesSingleVariableType values = new TsValuesSingleVariableType();
                //result.TimeSeries.Values.valueUnits = units; // this needs to be done earlier


                DataTable aTable = NWISDelimitedTextParser.ParseFileIntoDT(resultFile);

                // dwv add code to get the code, and use that to find the correct columns
                // time and date are separate
                int    date = 2; // present location of time column
                int    time = 3;
                String code = vp.Code;
                int    codeCol;
                int    aValue;
                int    qualifier; // there are many qa columns. what do we want to do about them

                /* 20070909
                 * add
                 #  meth_cd                    - Method code
                 #  dqi_cd                     - Data-quality indicator code
                 #  rpt_lev_va                 - Reporting level
                 #  rpt_lev_cd                 - Reporting level type
                 #  lab_std_va                 - Lab standard deviation
                 #  anl_ent_cd                 - Analyzing entity code
                 */
                int method;

                try
                {
                    /* 20070909 - USGS column name changes
                     * parameter_cd to param_cd
                     *     APPSETTING: ConfigurationManager.AppSettings["parameterColumn"];
                     * qualifiers now in val_qual_tx
                     * also:
                     #  meth_cd                    - Method code
                     #  dqi_cd                     - Data-quality indicator code
                     #  rpt_lev_va                 - Reporting level
                     #  rpt_lev_cd                 - Reporting level type
                     #  lab_std_va                 - Lab standard deviation
                     #  anl_ent_cd                 - Analyzing entity code
                     */
                    //codeCol = getVarQualifiersColumn(aTable, "parameter_cd", null);
                    string parmameterColName = (string)Properties.Settings.Default["parameterColumn"];
                    codeCol   = USGSCommon.getVarQualifiersColumn(aTable, parmameterColName, null);
                    aValue    = USGSCommon.getVarColumn(aTable, "result_va", null);
                    qualifier = USGSCommon.getVarQualifiersColumn(aTable, "remark_cd", null); // there are many qa columns. what do we want to do about them
                    // qualifier = getVarColumn(aTable, "val_qual_tx", null); //Do Not use at present
                }
                catch (WaterOneFlowException we)
                {
                    throw new WaterOneFlowException("URL: '" + aURL, we);
                }
                List <ValueSingleVariable> tsTypeList = new List <ValueSingleVariable>();

                foreach (DataRow aRow in aTable.Rows)
                {
                    if (aRow[codeCol].Equals(code))
                    { // only do this if this is the correct value
                        ValueSingleVariable tsTypeValue = new ValueSingleVariable();
                        //tsTypeValue.time= Convert.ToDateTime(aRow[time]);
                        tsTypeValue.dateTime = Convert.ToDateTime(
                            aRow[date].ToString() +
                            " " + aRow[time].ToString()
                            );
                        // tsTypeValue.dateTimeSpecified = true;
                        //tsTypeValue.censored = string.Empty;
                        if (string.IsNullOrEmpty(aRow[aValue].ToString()))
                        {
                            continue;
                        }
                        else
                        {
                            tsTypeValue.Value = Convert.ToDecimal(aRow[aValue]);
                        }

                        USGSCommon.parseQualifiersForCensorCode(tsTypeValue, aRow[qualifier].ToString()); // this will add censored, if appropariate
                        // added for  hydrodesktop
                        tsTypeValue.qualityControlLevel          = QualityControlLevelEnum.Unknown;
                        tsTypeValue.qualityControlLevelSpecified = true;
                        tsTypeValue.methodID          = 0;
                        tsTypeValue.methodIDSpecified = true;
                        tsTypeValue.sourceID          = 1;
                        tsTypeValue.sourceIDSpecified = true;
                        tsTypeList.Add(tsTypeValue);
                    }
                }
                values.count = tsTypeList.Count.ToString();
                values.value = tsTypeList.ToArray();

                // add added qualifiers
                values.source                      = new SourceType[1];
                values.source[0]                   = new SourceType();
                values.source[0].sourceID          = 1;
                values.source[0].sourceIDSpecified = true;
                values.source[0].Organization      = "USGS";
                values.source[0].SourceDescription = "US Geological Survey National Water Information System";
                values.source[0].SourceLink        = "http://waterdata.usgs.gov/";

                values.qualityControlLevel    = new qualityControlLevel[1];
                values.qualityControlLevel[0] = new qualityControlLevel();
                values.qualityControlLevel[0].qualityControlLevelID   = "0";
                values.qualityControlLevel[0].qualityControlLevelCode = "Unknown";

                values.method                      = new MethodType[1];
                values.method[0]                   = new MethodType();
                values.method[0].methodID          = 0;
                values.method[0].methodIDSpecified = true;
                values.method[0].MethodDescription = "Unknown";

                return(values);
            }