public string[] ListUniqueElements() { var uniqueElements = new HashSet <string>(); // using auto-generated class from AWDB SOAP service reference var wsc = new Awdb.AwdbWebServiceClient(); // download a list of all SCAN station triplets string[] stationTriplets = LoadStationTriplets(wsc); foreach (string stationTriplet in stationTriplets) { var elements = wsc.getStationElements(stationTriplet, null, null); // ignore stations with no elements if (elements is null) { continue; } // add elements at this station to unique list foreach (var element in elements) { string elementName = element.elementCd; if (!uniqueElements.Contains(elementName)) { uniqueElements.Add(elementName); } } } return(uniqueElements.ToArray()); }
public string[] ListUniqueVariables() { var uniqueElements = new HashSet <string>(); // using auto-generated class from AWDB SOAP service reference var wsc = new Awdb.AwdbWebServiceClient(); // download a list of all SCAN station triplets string[] stationTriplets = LoadStationTriplets(wsc); foreach (string stationTriplet in stationTriplets) { var elements = wsc.getStationElements(stationTriplet, null, null); // ignore stations with no elements if (elements is null) { continue; } // unique variable code is a combination of code, duration and heightDepth foreach (var element in elements) { string elementCd = element.elementCd; string duration = element.duration.ToString(); var hd = element.heightDepth; decimal heightDepthValue = 0.0M; string heightDepthUnits = null; if (hd != null) { heightDepthValue = hd.value; heightDepthUnits = hd.unitCd; } string uniqueCode = GetCuahsiVariableCode(elementCd, duration, heightDepthValue, heightDepthUnits); if (!uniqueElements.Contains(uniqueCode)) { uniqueElements.Add(uniqueCode); } } } // saving outputs to a .csv file using (var file = File.CreateText("variables.csv")) { foreach (var arr in uniqueElements) { //file.WriteLine(string.Join(",", arr)); file.WriteLine(arr); } } return(uniqueElements.ToArray()); }
public List <Site> GetStations() { // !!! necessary to prevent the "Bad Gateway" error (moved to class constructor) //System.Net.ServicePointManager.Expect100Continue = false; List <Site> siteList = new List <Site>(); // using auto-generated class from AWDB SOAP service reference var wsc = new Awdb.AwdbWebServiceClient(); // download a list of all SNOTEL station triplets string[] stationTriplets = LoadStationTriplets(wsc, "SNTL"); var stationCount = stationTriplets.Length; _logger.LogWrite("Retrieved SNOTEL Station codes from AWDB service: found " + stationTriplets.Length.ToString() + " stations."); _logger.LogWrite("Downloading metadata for " + stationTriplets.Length.ToString() + " stations..."); foreach (string stationTriplet in stationTriplets) { // call method "getStationMetadata" var metadata = wsc.getStationMetadata(stationTriplet); var site = new Site { SiteCode = metadata.stationTriplet.Replace(":", "_"), SiteName = metadata.name, Latitude = metadata.latitude, Longitude = metadata.longitude, Elevation = ft2m(metadata.elevation), State = fips2stateName(metadata.fipsStateNumber), County = metadata.countyName, HUC = metadata.huc, HUD = metadata.hud, ActonId = metadata.actonId, ShefId = metadata.shefId, BeginDate = Convert.ToDateTime(metadata.beginDate), EndDate = Convert.ToDateTime(metadata.endDate), TimeZone = metadata.stationDataTimeZone, StationTriplet = metadata.stationTriplet }; siteList.Add(site); } return(siteList); }
private string[] LoadStationTriplets(Awdb.AwdbWebServiceClient wsc) { var stationIds = new string[] { }; var stateCds = new string[] { }; var networkCds = new string[] { "SCAN" }; var hucs = new string[] { }; var countyNames = new string[] { }; var minLatitude = -90; var maxLatitude = 90; var minLongitude = -180; var maxLongitude = 180; var minElevation = -100000; var maxElevation = 100000; var elementCds = new string[] { }; var ordinals = new int[] { }; var heightDepths = new Awdb.heightDepth[] { }; var logicalAnd = true; var result = wsc.getStations(stationIds, stateCds, networkCds, hucs, countyNames, minLatitude, maxLatitude, minLongitude, maxLongitude, minElevation, maxElevation, elementCds, ordinals, heightDepths, logicalAnd); return(result); }
public List <Series> GetAllSeries() { List <Series> seriesList = new List <Series>(); var wsc = new Awdb.AwdbWebServiceClient(); string[] stationTriplets = LoadStationTriplets(wsc); var stationCount = stationTriplets.Length; _logger.LogWrite("Retrieving series catalog for " + stationTriplets.Length.ToString() + " stations."); foreach (string stationTriplet in stationTriplets) { var elements = wsc.getStationElements(stationTriplet, null, null); // ignore stations with no elements if (elements is null) { continue; } // element to series foreach (var element in elements) { Series series = new Series(); string elementCd = element.elementCd; string duration = element.duration.ToString(); var hd = element.heightDepth; decimal heightDepthValue = 0.0M; string heightDepthUnits = null; if (hd != null) { heightDepthValue = hd.value; } // get the variable code string variableCode = GetCuahsiVariableCode(elementCd, duration, heightDepthValue, heightDepthUnits); // get the method code ---> from variable code ... // extract the method code from the name string[] codeSplit = variableCode.Split('_'); string methodCode = "NOTSPECIFIED"; if (codeSplit.Length > 2) { methodCode = codeSplit[2]; } else { methodCode = "NOTSPECIFIED"; } series.MethodCode = methodCode; series.SiteCode = stationTriplet.Replace(":", "_"); series.VariableCode = variableCode; series.BeginDateTime = Convert.ToDateTime(element.beginDate); series.EndDateTime = Convert.ToDateTime(element.endDate); series.BeginDateTimeUTC = series.BeginDateTime; series.EndDateTimeUTC = series.EndDateTime; // estimate the value count DateTime realEndTime = series.EndDateTime; if (series.EndDateTime > DateTime.Now.AddDays(1)) { realEndTime = DateTime.Now.AddDays(1); } double estValueCount = (realEndTime - series.BeginDateTime).TotalHours; switch (element.duration) { case Awdb.duration.ANNUAL: case Awdb.duration.CALENDAR_YEAR: case Awdb.duration.WATER_YEAR: estValueCount = ((realEndTime - series.BeginDateTime).TotalDays) / 365.0; break; case Awdb.duration.SEASONAL: estValueCount = ((realEndTime - series.BeginDateTime).TotalDays) / 90.0; break; case Awdb.duration.MONTHLY: estValueCount = ((realEndTime - series.BeginDateTime).TotalDays) / 30.5; break; case Awdb.duration.SEMIMONTHLY: estValueCount = ((realEndTime - series.BeginDateTime).TotalDays) / 15.0; break; case Awdb.duration.DAILY: estValueCount = (realEndTime - series.BeginDateTime).TotalDays; break; case Awdb.duration.HOURLY: estValueCount = (realEndTime - series.BeginDateTime).TotalHours; break; } series.ValueCount = (int)(Math.Ceiling(estValueCount)); seriesList.Add(series); } } return(seriesList); }