public GetValuesOD() { // // TODO: Add constructor logic here // variableDs = ODvariables.GetVariableDataSet(); unitsDs = ODUnits.getUnitsDataset(); oDconnectionString = ConfigurationManager.ConnectionStrings["ODDB"]; }
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); } } }
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 VariablesResponseType GetVariableInfo(string Variable) { VariableInfoType[] variableList; if (String.IsNullOrEmpty(Variable)) { variableList = ODvariables.getVariables(new VariableParam[0], Variables); } else { VariableParam vp; vp = new VariableParam(Variable); variableList = ODvariables.getVariable(vp, Variables); } if (variableList == null) { throw new WaterOneFlowException("Variable Not Found"); } VariablesResponseType Response = new VariablesResponseType(); Response.variables = variableList; Response.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetVariableInfo", null, null, new string[] { Variable }, null, null); if (String.IsNullOrEmpty(Variable)) { CuahsiBuilder.addNote(Response.queryInfo.note, CuahsiBuilder.createNote("(Request for all variables")); } else { Response.queryInfo.criteria.variableParam = Variable; } NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service"); Response.queryInfo.note = CuahsiBuilder.addNote(Response.queryInfo.note, sourceNote); return(Response); }
public GetSiteInfoOD() { variablesDs = ODvariables.GetVariableDataSet(); vocabulariesDs = ODvocabularies.GetVocabularyDataset(); }
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 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); } } }
public GetVariablesOD() { Variables = ODvariables.GetVariableDataSet(); }