public static units getUnitsElement(string unitsID, unitsDataset ds) { DataRow[] dr = ds.Tables["units"].Select("unitID = " + unitsID); if (dr.Length > 0) { unitsDataset.UnitsRow row = (unitsDataset.UnitsRow)dr[0]; string uID = row.UnitsID.ToString(); string unitType = String.IsNullOrEmpty(row.UnitsType) ? null : row.UnitsType; string unitAbbrev = String.IsNullOrEmpty(row.UnitsAbbreviation) ? null : row.UnitsAbbreviation; string unitName = String.IsNullOrEmpty(row.UnitsName) ? null : row.UnitsName; units u = CuahsiBuilder.CreateUnitsElement(null, uID, unitAbbrev, unitName); return(u); } else { return(null); } }
public static UnitsType getUnitsElement(int unitsID, VariablesDataset ds) { DataRow[] dr = ds.Tables["units"].Select("unitsID = " + unitsID); if (dr.Length > 0) { VariablesDataset.UnitsRow row = (VariablesDataset.UnitsRow)dr[0]; string uID = row.UnitsID.ToString(); string unitType = row.UnitsType; string unitAbbrev = row.UnitsAbbreviation; string unitName = row.UnitsName; UnitsType u = CuahsiBuilder.CreateUnitsElement(unitType, uID, unitAbbrev, unitName); return(u); } else { return(null); } }
/// <summary> /// Method to generate a list of offset (from OD OffsetTypes table) in a ValuesDataSet /// This is done as a separate method since Values can could contain other VariableValue Types /// /// </summary> /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param> /// <returns></returns> public static List <OffsetType> datasetOffsetTypes(ValuesDataSet ds) { /* generate a list * create a distinct DataSet * - new data view * - set filter (no nulls) * - use toTable with unique to get unique list * foreach to generate qualifiers * */ string COLUMN = "OffsetTypeID"; string TABLENAME = "offsetTypes"; List <OffsetType> list = new List <OffsetType>(); try { DataView view = new DataView(ds.DataValues); view.RowFilter = COLUMN + " is not Null"; DataTable ids = view.ToTable(TABLENAME, true, new string[] { COLUMN }); foreach (DataRow r in ids.Rows) { try { Object aId = r[COLUMN]; // edit here ValuesDataSet.OffsetTypesRow offset = ds.OffsetTypes.FindByOffsetTypeID((int)aId); if (offset != null) { OffsetType t = new OffsetType(); t.offsetTypeID = offset.OffsetTypeID; t.offsetTypeIDSpecified = true; if (!String.IsNullOrEmpty(offset.OffsetDescription)) { t.offsetDescription = offset.OffsetDescription; } ValuesDataSet.UnitsRow offUnit = ds.Units.FindByUnitsID(offset.OffsetUnitsID); string offUnitsCode; string offUnitsName = null; string offUnitsAbbreviation = null; if (!String.IsNullOrEmpty(offUnit.UnitsAbbreviation)) { offUnitsAbbreviation = offUnit.UnitsAbbreviation; } if (!String.IsNullOrEmpty(offUnit.UnitsName)) { offUnitsName = offUnit.UnitsName; } if (offUnit != null) { t.units = CuahsiBuilder.CreateUnitsElement( null, offUnit.UnitsID.ToString(), offUnitsAbbreviation, offUnitsName); } list.Add(t); } } catch (Exception e) { log.Error("Error generating a qualifier " + r.ToString() + e.Message); } } return(list); } catch (Exception e) { log.Error("Error generating a qualifiers " + e.Message); // non fatal exceptions return(null); } }
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); }
private VariableInfoType RowToVariable(UsgsDbDailyValues.VariablesRow vRow) { VariableInfoType vit; String vCode = vRow.IsVariableCodeNull() ? null : vRow.VariableCode; String vName = vRow.IsVariableNameNull() ? null : vRow.VariableName; //String vDescr = String uName = vRow.IsUnitsNull() ? null : vRow.Units; String uAbbrev = vRow.IsUnitAbbreviationNull() ? null : vRow.UnitAbbreviation; String uType = vRow.IsUnitTypeNull() ? null : vRow.UnitType; String uCode = null; // ID is code if (!vRow.IsVariableUnitsIDNull()) { uCode = vRow.VariableUnitsID.ToString(); } UnitsTypeEnum uTypeEnum = (UnitsTypeEnum)CoreBuilder.GetTextAsEnum(uType, typeof(UnitsTypeEnum)); units vUnit = CuahsiBuilder.CreateUnitsElement( uTypeEnum, uCode, uAbbrev, uName); /* this needs to be fixed to accept value type and data type * and time options */ vit = CuahsiBuilder.CreateVariableInfoType( null, // don't want variable ID exposed in the NWIS service "NWIS", vRow.VariableCode, vRow.VariableName, null, vUnit // units ); CoreBuilder.SetEnumFromText(vit, vRow, "valueType", typeof(valueTypeEnum)); CoreBuilder.SetEnumFromText(vit, vRow, "dataType", typeof(dataTypeEnum)); // add usgs statistic code options if (!vRow.Isstat_cdNull()) { List <option> opts = new List <option>(1); option opt = new option(); opt.name = "statistic"; opt.optionCode = vRow.stat_cd; opts.Add(opt); vit.options = opts.ToArray(); } if (!vRow.IsisRegularNull() && vRow.isRegular) { vit.timeSupport = new VariableInfoTypeTimeSupport(); vit.timeSupport.isRegular = vRow.isRegular; vit.timeSupport.isRegularSpecified = true; // add time support // check to be sure we've got some vaild stuff if (!vRow.IsTimeSupportNull()) { int timeInterval; if (Int32.TryParse(vRow.TimeSupport, out timeInterval)) { vit.timeSupport.timeInterval = timeInterval; vit.timeSupport.timeIntervalSpecified = true; } } if (!vRow.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); }