コード例 #1
0
        private DataRowCollection EPAResponseMethods(EPAResults.StoretResultFlatDataTable table)
        {
            // it is possible for the EPA to return units that are not the same
            // need to add translation, if this happens
            DataTable dt = DataSetHelper.SelectDistinct("methods", table, "methodName");

            return(dt.Rows);
        }
コード例 #2
0
        public static EPAResults.StoretResultFlatDataTable GetStationResults(string Agency, string SiteCode, string VariableName, W3CDateTime?BeginDate, W3CDateTime?EndDate)
        {
            WqxResultsToDataset svc = new WqxResultsToDataset();

            svc.Organization       = Agency;
            svc.MonitoringLocation = SiteCode;
            svc.CharacteristicName = VariableName;
            svc.SetDateRange(BeginDate, EndDate);

            if (svc.getCount() < 20000)
            {
                EPAResults.StoretResultFlatDataTable results = svc.getResults();
                return(results);
            }

            return(null);
        }
コード例 #3
0
        public EPAResults.StoretResultFlatDataTable getResults()
        {
            XmlDocument xdoc = new XmlDocument();

            ;


            xdoc.Load(new StringReader(svc.getResults(Organization,
                                                      MonitoringLocation,
                                                      MonitoringLocationTypeField,
                                                      MinimumActivityStartDateField,
                                                      MaximumActivityStartDateField,
                                                      MinimumLatitudeField,
                                                      MaximumLatitudeField,
                                                      MinimumLongitudeField,
                                                      MaximumLongitudeField,
                                                      CharacteristicTypeField,
                                                      CharacteristicName,
                                                      ResultTypeField)));

            //  XmlNodeList results = (XmlNodeList)  xdoc.GetElementsByTagName("WQX");
            XmlNodeList results = (XmlNodeList)xdoc.GetElementsByTagName("STORETResults");

            if (results != null && results.Count > 0)
            {
                XmlNode wqx = results[0];


                EPAResults.StoretResultFlatDataTable table = wqx2datatable(wqx, true);
                return(table);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public override object  GetTimeSeries(
            locationParam lp,
            variableParamVersion vp,
            W3CDateTime?startDate,
            W3CDateTime?endDate)
        {
            if ((endDate.HasValue && startDate.HasValue) && endDate.Value.DateTime < startDate.Value.DateTime)
            {
                throw new WaterOneFlowException("No Data. End Date must be greater than Start Date");
            }

            TimeSeriesResponseType result = null;


            result = CuahsiBuilder.CreateTimeSeriesObject();

            string[] StationsList = new string[] { lp.SiteCode };

            SiteInfoType sit = null;

            try
            {
                sit = DataInfoService.GetSite(lp);
                result.timeSeries.sourceInfo = sit;
            }
            catch (WaterOneFlowException ex)
            {
                log.Info("EPA Bad Site Request" + vp.ToString());
                throw ex;
            }
            catch (WaterOneFlowServerException ex)
            {
                log.Error("EPA  server issued  with Site Request" + vp.ToString());
                throw ex;
            }
            catch (WaterOneFlowSourceException ex)
            {
                log.Error("EPA  source issued  with Site Request" + vp.ToString());
                throw ex;
            }
            catch (Exception ex)
            {
                log.Error("EPA  source issued  with Site Request" + vp.ToString());
                throw new WaterOneFlowServerException("Uncaught Exception in EPA Time series site reuqest", ex);
            }



            result.queryInfo.criteria.locationParam = lp.ToString();
            result.queryInfo.criteria.variableParam = vp.ToString();

            // not fully correct, but just choose the first one.
            VariableInfoType[] vits = null;
            try {
                vits = DataInfoService.GetVariableInfoObject(vp);
                result.timeSeries.variable = vits[0];
            } catch (WaterOneFlowException ex)
            {
                log.Info("EPA Bad variable Request" + vp.ToString());
                throw ex;
            }
            catch (WaterOneFlowServerException ex)
            {
                log.Error("EPA  server issued  with variable Request" + vp.ToString());
                throw ex;
            } catch (WaterOneFlowSourceException ex)
            {
                log.Error("EPA  source issued  with variable Request" + vp.ToString());
                throw ex;
            } catch (Exception ex)
            {
                log.Error("EPA  source issued  with variable Request" + vp.ToString());
                throw new WaterOneFlowServerException("Uncaught Exception in EPA Time series site reuqest", ex);
            }

            String variableName = result.timeSeries.variable.variableName;

            string agency   = GetAgencyEpaSiteCode(lp);
            string siteCode = GetSiteIDEpaSiteCode(lp);

            EPAResults.StoretResultFlatDataTable table =
                WqxResultsToDataset.GetStationResults(
                    agency, siteCode,
                    variableName, startDate, endDate);
            if (table.Rows.Count == 0)
            {  // no retults, just go back
                result.timeSeries.values       = new TsValuesSingleVariableType();
                result.timeSeries.values.count = "0";
                return(result);
            }
            DataRowCollection unitNameRows = EPAResponseUnits(table);

            // for now
            if (unitNameRows.Count > 1)
            {
                //throw new WaterOneFlowSourceException(
                //    " EPA Returned more than one unit for request."
                //    + " This is not supported at the present time" );
                // no longer want an error. return data
                log.Info("EPA STATION WITH MORE THAN ONE UNIT: '" + lp.ToString());
            }

            /* Logic neded for multiple units
             * select one with max count or latest one?
             * if max get count for each unit
             * For the selected unit,
             * * create a subtable,
             * * populate values
             *
             * Future:
             * for each unit
             * *collect a subtable, populate values
             * */

            /* need to creat a units element
             * The units returned, are not necessarily the ones in the series catalog
             */
            //string unitName = unitNameRows[0].ItemArray[0].ToString().Trim();
            //result.timeSeries.variable.units =  CuahsiBuilder.CreateUnitsElement(null, null, unitName, unitName);

            foreach (DataRow row in unitNameRows)
            {
                string unitName = row.ItemArray[0].ToString().Trim();
                result.timeSeries.variable.units = CuahsiBuilder.CreateUnitsElement(null, null, unitName, unitName);

                StringBuilder select = new StringBuilder();
                select.AppendFormat("[VariableUnitsAbbreviation]='{0}'", WaterOneFlowImpl.WSUtils.SqlEncode(unitName));
                if (startDate.HasValue)
                {
                    select.AppendFormat(" AND  [localDateTime] > '{0}' ", startDate.Value.DateTime.ToString("s"));
                }
                if (endDate.HasValue)
                {
                    select.AppendFormat(" AND  [localDateTime] < '{0}' ", endDate.Value.DateTime.AddDays(1).ToString("s"));
                }
                EPAResults.StoretResultFlatRow[] rowsWithUnit = (EPAResults.StoretResultFlatRow[])table.Select(select.ToString());
                result.timeSeries.values = DataValuesBuilder.CreateValuesElement(rowsWithUnit);

                result.timeSeries.values.unitsAbbreviation = unitName; // abbreviated name is presently returned
            }

            /* for now, just adding the methods, without the reference to the
             * value they came from. That will take a bit of work.
             * need to generate unique methodID's for distinct methods
             * then populate the methodID in the table,
             * then send to the value generator
             * */
            /***** This can cause more method, if nore than one parameter is returned
             * eg pH presently returns phosphorous
             * */

            DataRowCollection methodNameRows = EPAResponseMethods(table);

            if (methodNameRows != null && methodNameRows.Count > 0)
            {
                List <MethodType> methods;
                if (result.timeSeries.values.method == null)
                {
                    methods = new List <MethodType>();
                }
                else
                {
                    methods = new List <MethodType>(result.timeSeries.values.method);
                }
                foreach (DataRow row in methodNameRows)
                {
                    MethodType method = new MethodType();
                    method.MethodDescription = row.ItemArray[0].ToString();
                    methods.Add(method);
                }
                result.timeSeries.values.method = methods.ToArray();
            }


            return(result);
        }
コード例 #5
0
        private EPAResults.StoretResultFlatDataTable wqx2datatable(XmlNode wqx, bool MatchCharacteristicName)
        {
            EPAResults.StoretResultFlatDataTable table = new EPAResults.StoretResultFlatDataTable();
            XmlNodeList orgs = wqx.SelectNodes("Organization");

            foreach (XmlNode org in orgs)
            {
                string agencyCode = null;
                string orgName    = null;
                try
                {
                    agencyCode = org.SelectSingleNode("OrganizationDescription/OrganizationIdentifier").InnerText;
                    orgName    = org.SelectSingleNode("OrganizationDescription/OrganizationFormalName").InnerText;
                }
                catch
                {
                    log.Error(messageLead + "No agency or org name" + org.SelectSingleNode("OrganizationDescription/").ToString());
                    break;
                }
                XmlNodeList activities = org.SelectNodes("Activity");
                foreach (XmlNode activity in activities)
                {
                    string siteCode     = null;
                    string sampleMedium = null;
                    string localDate    = null;
                    string localTime    = null;
                    try
                    {
                        siteCode = activity.SelectSingleNode("MonitoringLocation/MonitoringLocationIdentifier").InnerText;
                    }
                    catch
                    {
                        log.Error(messageLead + "No site Code in Monitoring");
                        break;
                    }
                    try
                    {
                        localDate = activity.SelectSingleNode("ActivityDescription/ActivityStartDate").InnerText;
                        try
                        {
                            localTime = activity.SelectSingleNode("ActivityDescription/ActivityStartTime").InnerText;

                            if (Regex.IsMatch(localTime, "^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$"))
                            {
                                localDate = String.Format("{0} {1}", localDate, localTime);
                            }
                        }
                        catch
                        {
                            log.Info(messageLead + "No actvity time");
                        }
                    }
                    catch
                    {
                        log.Error(messageLead + "No actvity date");
                        break;
                    }

                    try
                    {
                        sampleMedium = activity.SelectSingleNode("ActivityDescription/ActivityMediaName").InnerText;
                    }
                    catch
                    {
                        log.Error(messageLead + "No  sample medium in ActivityDescription");
                    }


                    XmlNodeList results = activity.SelectNodes("Result");
                    foreach (XmlNode result in results)
                    {
                        string variableName = null;


                        string comments                   = null;
                        string methodCode                 = null;
                        string methodVocabulary           = null;
                        string methodDescription          = null;
                        string methodName                 = null; // combine code and vocab for EPA
                        string labName                    = null;
                        string detectionQuantitationLimit = null;

                        /* add precision, bias, confidence interval later
                         */
                        try
                        {
                            // if no characteristic name, we can't use it
                            variableName = result.SelectSingleNode("ResultDescription/CharacteristicName").InnerText;


                            if (MatchCharacteristicName)
                            {
                                // assume specific name
                                if (!variableName.Equals(CharacteristicName, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    // not equal to the request, skip it
                                    break;
                                }
                            }
                            XmlNode x;
                            x = result.SelectSingleNode("ResultDescription/ResultCommentText");

                            if (x != null)
                            {
                                comments = x.InnerText.Trim();
                            }

                            x = result.SelectSingleNode("ResultAnalyticalMethod/MethodIdentifier");
                            if (x != null)
                            {
                                methodCode = x.InnerText.Trim();
                            }
                            x = result.SelectSingleNode("ResultAnalyticalMethod/MethodIdentifierContext");
                            if (x != null)
                            {
                                methodVocabulary = x.InnerText.Trim();
                            }
                            // EPA mathod name as determined by dwv, MethodVocab:MethodCode
                            methodName = methodVocabulary + ":" + methodCode;

                            x = result.SelectSingleNode("ResultLabInformation/ResultLaboratoryCommentCode");
                            if (x != null)
                            {
                                methodDescription = x.InnerText.Trim();
                            }

                            x = result.SelectSingleNode("ResultLabInformation/ResultLaboratoryCommentCode");
                            if (x != null)
                            {
                                labName = x.InnerText.Trim();
                            }
                            x = result.SelectSingleNode("ResultLabInformation/ResultDetectionQuantitationLimit");
                            if (x != null)
                            {
                                detectionQuantitationLimit = x.InnerText.Trim();
                            }

                            try
                            {
                                XmlNodeList resultMeasures = result.SelectNodes("ResultDescription/ResultMeasure");
                                if (resultMeasures != null && resultMeasures.Count > 0)
                                {
                                    foreach (XmlNode measure in resultMeasures)
                                    {
                                        string value         = null;
                                        string unitCode      = null;
                                        string qualifierCode = null;
                                        try
                                        {
                                            //value = measure.FirstChild.InnerText;
                                            //unitCode = measure.FirstChild.NextSibling.InnerText.Trim();
                                            value         = measure.SelectSingleNode("ResultMeasureValue").InnerText.Trim();
                                            unitCode      = measure.SelectSingleNode("MeasureUnitCode").InnerText.Trim();
                                            qualifierCode = measure.SelectSingleNode("MeasureQualifierCode").InnerText.Trim();
                                            if (String.IsNullOrEmpty(value))
                                            {
                                                value = "-9999";
                                            }
                                        }
                                        catch
                                        {
                                            log.Info(messageLead + "could not convert ResultMeasure " + measure.ToString());
                                        }
                                        decimal numericValue;


                                        if (!Decimal.TryParse(value, out numericValue))
                                        {
                                            value = "-9999";
                                        }

                                        table.AddStoretResultFlatRow(agencyCode,
                                                                     siteCode, variableName,
                                                                     sampleMedium,
                                                                     localDate,
                                                                     value,
                                                                     unitCode,
                                                                     comments,
                                                                     qualifierCode,
                                                                     null,              //ResultValueTypeName
                                                                     null,              //DataType
                                                                     null,              //Precision
                                                                     null,              //CI
                                                                     methodCode,        //MethodCode
                                                                     methodVocabulary,  // MethodVocabulary
                                                                     methodDescription, // MethodDescription
                                                                     labName,
                                                                     detectionQuantitationLimit,
                                                                     methodName
                                                                     );
                                    }
                                }
                            }
                            catch
                            {
                                log.Error(messageLead + " Could not convert ResultMeasure");
                            }
                        }
                        catch
                        {
                            log.Error(messageLead + "could not convert result " + result.ToString());
                        }
                    }
                }
            }
            return(table);
        }