public override object GetTimeSeries( locationParam lp, VariableParam vp, Nullable <W3CDateTime> startDate, Nullable <W3CDateTime> endDate) { if (lp.isGeometry) { throw new WaterOneFlowException("Geometry not supported "); } TimeSeriesResponseType result = null; string[] StationsList = new string[] { lp.SiteCode }; result = CuahsiBuilder.CreateTimeSeriesObject(); result.queryInfo.criteria.locationParam = lp.ToString(); result.queryInfo.criteria.variableParam = vp.ToString(); result.timeSeries.sourceInfo = DataInfoService.GetSite(lp); // not fully correct, but just choose the first one. VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp); result.timeSeries.variable = vits[0]; string aURL = InstantaneousData(startDate, endDate, new string[] { vp.Code }, StationsList, USGSCommon.option2AgencyCode(lp)); try { result.timeSeries.values = CreateWQTimeSeriesObject(vp, aURL); } catch (WaterOneFlowException e) { throw; } catch (WaterOneFlowSourceException e) { throw; } catch (Exception e) { log.Error(e.Message + e.StackTrace); throw new WaterOneFlowException("An External resource failed.", e); } List <NoteType> notes = new List <NoteType>(); NoteType urlNote = new NoteType(); urlNote.title = "USGS URL"; urlNote.Value = aURL; notes.Add(urlNote); result.queryInfo.note = notes.ToArray(); return(result); }
public override object GetTimeSeries( locationParam lp, VariableParam vp, Nullable <W3CDateTime> startDate, Nullable <W3CDateTime> endDate) { if (lp.isGeometry) { throw new WaterOneFlowException("Geometry not supported "); } TimeSeriesResponseType result = null; //string Network; //string SiteCode; ////WSUtils.ParseSiteId(siteId, out Network, out SiteCode); //try //{ // locationParam sq = new locationParam(siteNumber); // Network = sq.Network; // SiteCode = sq.SiteCode; // if (sq.isGeometry) // { // throw new WaterOneFlowException("Location by Geometry not accepted: " + siteNumber); // } //} //catch (WaterOneFlowException we) //{ // log.Info("Bad SiteID:" + siteNumber); // throw; //} //catch (Exception e) //{ // log.Error("Uncaught exception:" + e.Message); // throw new WaterOneFlowException("Sorry. Your submitted site ID for this getSiteInfo request caused an problem that we failed to catch programmatically: " + e.Message); //} //// string WaterQualityList = "¶meter_cd=" + variable; //string[] StationsList = new string[] { SiteCode }; string[] StationsList = new string[] { lp.SiteCode }; //VariableParam vp; //try //{ // vp = new VariableParam(variable); //} //catch (WaterOneFlowException we) //{ // log.Info("Bad Variable Request '" + variable + "'"); // throw; //} //catch (Exception e) //{ // log.Error("uncaught exception duing Variable Request '" + variable + "'"); // throw new WaterOneFlowException("Sorry. Your variable parameter caused an exception that we failed to catch:" + e.Message); //} result = CuahsiBuilder.CreateTimeSeriesObject(); //// all data are provisional //List<note> notes = new List<note>(); //note urlNote = new note(); //urlNote.title = "USGS Data Provisional"; //urlNote.href = "http://waterdata.usgs.gov/nwis/help/?provisional"; //urlNote.Value = "All data are provisional, and subject to revision"; //notes.Add(urlNote); //result.queryInfo.note = notes.ToArray(); result.queryInfo.criteria.locationParam = lp.ToString(); result.queryInfo.criteria.variableParam = vp.ToString(); // result.queryInfo.criteria.timeParam = CuahsiBuilder.createQueryInfoTimeCriteria(startDate, endDate); // look for siteInfoType in cache, and use if it is there /* SiteInfoType sit = (SiteInfoType)appCache[sitCache + SiteCode]; * if (sit == null) * { * // just use the values for now. * ((SiteInfoType)result.timeSeries.sourceInfo).siteCode[0].Value = SiteCode; * ((SiteInfoType)result.timeSeries.sourceInfo).siteCode[0].network = "NWIS"; * * } * else * { * // in the cache, use it * result.timeSeries.sourceInfo = sit; * } * */ result.timeSeries.sourceInfo = DataInfoService.GetSite(lp); // vaiable info // result.timeSeries.variable = vp.getVariableSchemaType(); //result.timeSeries.variable = NwisVariableCatalog.getVariable(vp.Code, variableDataSet); //result.timeSeries.variable = ODvariables.getVariable(vp.Code, variableDataSet)[0]; // not fully correct, but just choose the first one. VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp); result.timeSeries.variable = vits[0]; string aURL = GroundWater(startDate, endDate, StationsList, USGSCommon.option2AgencyCode(lp)); try { // refactor too much abstraction //CreateRealTimeSeriesObject(result, RealTime(StationsList)); result.timeSeries.values = CreateGWTimeSeriesObject(vp, aURL); } catch (WaterOneFlowException e) { //log.Error(e.Message + e.StackTrace); throw; } catch (WaterOneFlowSourceException e) { //log.Error(e.Message + e.StackTrace); throw; } catch (WebException e) { log.Error(e.Message + e.StackTrace); throw new WaterOneFlowException("Connecting to External resource failed.", e); } catch (Exception e) { log.Error(e.Message + e.StackTrace); throw new WaterOneFlowException("An External resource failed.", e); } result.timeSeries.sourceInfo = DataInfoService.GetSite(lp); List <NoteType> notes = new List <NoteType>(); NoteType urlNote = new NoteType(); urlNote.title = "USGS URL"; urlNote.Value = aURL; notes.Add(urlNote); result.queryInfo.note = notes.ToArray(); return(result); }
public object GetVariableInfoObject(string variable, String authToken) { Stopwatch timer = System.Diagnostics.Stopwatch.StartNew(); queryLog2.LogStart(Logging.Methods.GetVariables, variable, Context.Request.UserHostName); try { VariableParam[] vars = null; if (!String.IsNullOrEmpty(variable)) { vars = new VariableParam[1]; VariableParam vp = new VariableParam(variable); vars[0] = vp; } VariablesResponseType res = new VariablesResponseType(); res.variables = ODws.GetVariableInfoObject(vars); res.queryInfo = new QueryInfoType(); res.queryInfo.creationTime = DateTime.Now; res.queryInfo.creationTimeSpecified = true; res.queryInfo.criteria = new QueryInfoTypeCriteria(); res.queryInfo.criteria.variableParam = variable; // don't always have variables if (res.variables != null) { queryLog2.LogEnd(Logging.Methods.GetVariables, variable, timer.ElapsedMilliseconds.ToString(), res.variables.Length.ToString(), Context.Request.UserHostName); } else { queryLog2.LogEnd(Logging.Methods.GetVariables, variable, timer.ElapsedMilliseconds.ToString(), "0", Context.Request.UserHostName); } WaterOneFlow.Service.v1_0.xsd.VariablesResponse obj = new WaterOneFlow.Service.v1_0.xsd.VariablesResponse(res); // if (DEBUG) { // XmlSerializer xs = new XmlSerializer( // typeof (WaterOneFlow.Service.v1_0.xsd.VariablesResponse)); // StringBuilder sb = new StringBuilder(); // XmlWriterSettings settings = new XmlWriterSettings(); // settings.OmitXmlDeclaration = true; //// settings.ConformanceLevel = ConformanceLevel.Fragment; // XmlWriter writer = XmlWriter.Create(sb, settings); // xs.Serialize(writer, obj); //} //return res; return(new WaterOneFlow.Service.v1_0.xsd.VariablesResponse(res)); } catch (Exception we) { log.Warn(we.Message); queryLog2.LogEnd(Logging.Methods.GetVariables, variable, timer.ElapsedMilliseconds.ToString(), "-9999", Context.Request.UserHostName); throw SoapExceptionGenerator.WOFExceptionToSoapException(we); } }
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); }
/* * public TimeSeriesResponseType GetValues( * locationParam Location, * VariableParam Variable, * W3CDateTime? BeginDateTime, W3CDateTime? EndDateTime) */ public override WaterOneFlow.Service.Response.v1_1.TimeSeriesResponseType GetTimeSeries( locationParam lp, VariableParam vp, Nullable <W3CDateTime> startDate, Nullable <W3CDateTime> endDate) { // put the date check up front. // a start date can be older than 31 days, as long as the endDate is not older than 31 days. if (endDate.HasValue && endDate.Value.DateTime < DateTime.Today.AddDays(-31)) { throw new WaterOneFlowException("No Data. EndDate must be less than that 31 days from present."); } TimeSeriesResponseType result = null; string[] StationsList = new string[] { lp.SiteCode }; result = CuahsiBuilder.CreateTimeSeriesObject(); result.queryInfo.criteria.locationParam = lp.ToString(); result.queryInfo.criteria.variableParam = vp.ToString(); // not fully correct, but just choose the first one. VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp); result.timeSeries.variable = vits[0]; string aUrl = UnitValues(startDate, endDate, new string[] { vp.Code }, StationsList); try { // refactor too much abstraction //CreateRealTimeSeriesObject(result, RealTime(StationsList)); result.timeSeries.values = new TsValuesSingleVariableType[1]; result.timeSeries.values[0] = USGSCommon.CreateTimeSeriesValuesElement(vp, aUrl, true // add provisional flag ); } catch (Exception e) { log.Error(e.Message + e.StackTrace); throw new WaterOneFlowException("An External resource failed.", e); } // all data are provisional List <NoteType> notes = new List <NoteType>(); NoteType pNote = new NoteType(); pNote.title = "USGS Data Provisional"; pNote.href = "http://waterdata.usgs.gov/nwis/help/?provisional"; pNote.Value = "All data are provisional, and subject to revision"; notes.Add(pNote); NoteType urlNote = new NoteType(); urlNote.title = "USGS URL"; urlNote.Value = aUrl; notes.Add(urlNote); result.queryInfo.note = notes.ToArray(); return(new WaterOneFlow.Service.v1_1.xsd.TimeSeriesResponse(result)); }