예제 #1
0
파일: Program.cs 프로젝트: BjartN/wsklima
        static no_met_metdata_Metdata GetSnowDepths(int startYear, int endYear)
        {
            //http://eklima.met.no/met/MetService?invoke=getMetData&timeserietypeID=2&format=&from=1950-01-01&to=2017-01-01&stations=50310&elements=SA&hours=0%2C1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9&months=0%2C1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11&username=

            var snowDepthParameter = "SA";
            var stations           = new[] { 50300, 50310 };

            //var timeseriesTypeObs = "T_ELEM_OBS";
            //var timeseriesTypeObsId = "2";

            var timeseriesTypeObs   = "T_DIURNAL";
            var timeseriesTypeObsId = "0";

            var hours  = Enumerable.Range(0, 23);
            var months = new[] { 10, 11, 12, 1, 2, 3, 4, 5 };
            var from   = startYear + "-01-01";
            var to     = endYear + "-31-12";

            var ds = new MetDataService();

            var result = ds.getMetData(
                timeseriesTypeObsId,
                "yyyy-MM-dd",
                from,
                to,
                string.Join(",", stations),
                snowDepthParameter.ToString(),
                string.Join(",", hours),
                string.Join(",", months), "");


            return(result);
        }
예제 #2
0
        private StationEntry[] GetLatesDailyObsInner(string element = defaultElement, int limit = 10000)
        {
            var timeseriesTypeDailyId = "0";
            var ds = new MetDataService();
            var st = GetStationsByElement(element, timeseriesTypeDailyId)
                     .Where(x => x.to == null)
                     .ToArray();

            var stIdx = st.ToDictionary(x => x.stationId, x => x);

            var stations = string.Join(",", st.Select(x => x.stationId).ToArray());

            var result = ds.getMetData(
                timeseriesTypeDailyId,
                "yyyy-MM-dd",
                DateTime.UtcNow.AddDays(-1).ToString("yyyy-MM-dd"),
                DateTime.UtcNow.ToString("yyyy-MM-dd"),
                stations,
                element,
                string.Join(",", hours),
                allMonths,
                userName);

            //flatten
            var entries = result.timeStamp.SelectMany(timestamp => timestamp.location.SelectMany(location => location.weatherElement.Select(weatherElement => new StationEntry
            {
                from           = timestamp.from,
                to             = timestamp.to.Year == 1 ? default(DateTime?) : timestamp.to,
                stationId      = location.id,
                elementId      = weatherElement.id,
                elementValue   = weatherElement.value,
                elementQuality = weatherElement.quality,
                stationName    = stIdx.ContainsKey(location.id) ? stIdx[location.id].name : default(string),
                lat            = stIdx.ContainsKey(location.id) ? stIdx[location.id].lat : default(double?),
                lon            = stIdx.ContainsKey(location.id) ? stIdx[location.id].lon : default(double?)
            })))
                          .Where(x => x.elementValue != noValue)
                          .GroupBy(x => x.stationId)
                          .Select(g => g.OrderByDescending(x => x.from).First())
                          .ToArray();

            return(entries
                   .OrderByDescending(x => x.elementValue.ToNullableDouble())
                   .Take(limit)
                   .ToArray());
        }
예제 #3
0
        private static Entry[] GetTimeSeriesInner(DateTime from, DateTime to, string element, string stations)
        {
            var timeseriesTypeDailyId = "0";

            //get result
            var ds     = new MetDataService();
            var result = ds.getMetData(
                timeseriesTypeDailyId,
                "yyyy-MM-dd",
                from.ToString("yyyy-MM-dd"),
                to.ToString("yyyy-MM-dd"),
                stations,
                element,
                string.Join(",", hours), //applies only to timeserietypeID=2, 8, 9, 13, 14, 15 og 16
                allMonths,
                userName);

            //flatten
            var entries = result.timeStamp.SelectMany(timestamp => timestamp.location.SelectMany(location => location.weatherElement.Select(weatherElement => new Entry
            {
                from           = timestamp.from,
                to             = timestamp.to.Year == 1 ? default(DateTime?) : timestamp.to,
                stationId      = location.id,
                elementId      = weatherElement.id,
                elementValue   = weatherElement.value,
                elementQuality = weatherElement.quality
            })))
                          .Where(x => x.elementValue != noValue)
                          .ToArray();

            return(entries
                   .GroupBy(x => x.from)
                   .Select(x => x.First())
                   .OrderBy(x => x.from)
                   .ToArray());
        }