예제 #1
0
        private static FiltersDefinition ShuffleComplexRandomFiltersCombination(Mission mission, Dictionary <string, DataCollectionDefinition> collections, string filterSetKey)
        {
            FiltersDefinition _filtersDefinition = ShuffleSimpleRandomFiltersCombination(mission, collections, filterSetKey, null, 2);

            IEnumerable <System.Reflection.PropertyInfo> props = mission.GetType().GetProperties().Where(
                prop => Attribute.IsDefined(prop, typeof(ComplexChoiceAttribute)));

            foreach (var prop in props)
            {
                var choice = prop.GetValue(mission);
                if (choice == null)
                {
                    continue;
                }
                if (choice is TimeRange && prop.Name == "Lifetime")
                {
                    var      tr    = choice as TimeRange;
                    DateTime start = tr.Start;
                    DateTime stop  = tr.Stop >= DateTime.UtcNow ? DateTime.UtcNow : tr.Stop;
                    if (rnd.Next() % 2 == 0)
                    {
                        TimeSpan timeSpan = stop - tr.Start;
                        TimeSpan newSpan  = new TimeSpan(rnd.Next(0, (int)timeSpan.TotalHours), 0, 0);
                        start = tr.Start + newSpan;
                        _filtersDefinition.AddFilter("sensingStart", tr.ParameterStartFullName, start.ToString("s"), string.Format("From {0}", start.ToString("D")),
                                                     (IOpenSearchResultItem item) =>
                        {
                            var date = Terradue.Metadata.EarthObservation.OpenSearch.Extensions.EarthObservationOpenSearchResultExtensions.FindStartDate(item);
                            return(date > start);
                        },
                                                     null
                                                     );
                    }
                    if (rnd.Next() % 2 == 0)
                    {
                        TimeSpan timeSpan = stop - start;
                        TimeSpan newSpan  = new TimeSpan(rnd.Next(0, (int)timeSpan.TotalHours), 0, 0);
                        stop = start + newSpan;
                        _filtersDefinition.AddFilter("sensingEnd", tr.ParameterEndFullName, stop.ToString("s"), string.Format("To {0}", stop.ToString("D")),
                                                     (IOpenSearchResultItem item) =>
                        {
                            var date = Terradue.Metadata.EarthObservation.OpenSearch.Extensions.EarthObservationOpenSearchResultExtensions.FindEndDate(item);
                            return(date < stop);
                        },
                                                     null
                                                     );
                    }
                }
                if (choice is GeometryFilterCollection)
                {
                    var gfc     = choice as GeometryFilterCollection;
                    var feature = gfc.Features.ToArray()[rnd.Next(0, gfc.Features.Count())];
                    _filtersDefinition.AddFilter(gfc.Key, "{http://a9.com/-/opensearch/extensions/geo/1.0/}geometry", wktWriter.Write(feature.Geometry), string.Format("intersecting {0}", feature.Attributes["NAME"]),
                                                 GetGeometryValidator(feature),
                                                 null
                                                 );
                }
            }
            return(_filtersDefinition);
        }
예제 #2
0
        public static IEnumerable <FiltersDefinition> GenerateBulkSystematicDataFiltersDefinition(TargetSiteWrapper target)
        {
            List <FiltersDefinition> bulkDataDefs = new List <FiltersDefinition>();

            FiltersDefinition _filtersDefinition = new FiltersDefinition("Systematic");

            _filtersDefinition.AddFilter("missionName", "{http://a9.com/-/opensearch/extensions/eo/1.0/}platform",
                                         "Sentinel-1", "Sentinel-1",
                                         Mission.GetIdentifierValidator(new Regex(@"^S1.*")), null);

            _filtersDefinition.AddFilter("productType", "{http://a9.com/-/opensearch/extensions/eo/1.0/}productType",
                                         "GRD", "Ground Range Detected (GRD)",
                                         Mission.GetIdentifierValidator(new Regex(@"^S1.*_GRD._.*")), null);

            var geom = wktreader.Read("POLYGON((-5.664 14.532,-5.196 13.991,-4.854 13.969,-4.877 13.637,-4.114 13.938,-3.96 13.378,-3.443 13.158,-3.27 13.698,-2.874 13.654,-2.839 14.054,-2.474 14.299,-2 14.191,-1.98 14.476,-0.745 15.066,-1.686 15.431,-2.532 15.322,-2.816 15.774,-3.262 15.857,-3.8 15.491,-4.135 15.81,-5.23 15.674,-5.1 15.196,-5.546 14.931,-5.664 14.532))");

            _filtersDefinition.AddFilter("geom", "{http://a9.com/-/opensearch/extensions/geo/1.0/}geometry",
                                         "POLYGON((-5.664 14.532,-5.196 13.991,-4.854 13.969,-4.877 13.637,-4.114 13.938,-3.96 13.378,-3.443 13.158,-3.27 13.698,-2.874 13.654,-2.839 14.054,-2.474 14.299,-2 14.191,-1.98 14.476,-0.745 15.066,-1.686 15.431,-2.532 15.322,-2.816 15.774,-3.262 15.857,-3.8 15.491,-4.135 15.81,-5.23 15.674,-5.1 15.196,-5.546 14.931,-5.664 14.532))",
                                         "over Mopti floodable area in Mali",
                                         Mission.GetGeometryValidator(geom), null);

            var now = DateTime.UtcNow.Subtract(TimeSpan.FromDays(7)).ToUniversalTime();

            // _filtersDefinition.AddFilter("{http://purl.org/dc/elements/1.1/}modified",
            _filtersDefinition.AddFilter("modified", "{http://purl.org/dc/terms/}modified",
                                         now.ToString("s") + "Z",
                                         "ingested since " + now.ToString(),
                                         Mission.GetIngestionDateValidator(now), null);

            // _filtersDefinition.AddFilter("archiveStatus", "{http://a9.com/-/opensearch/extensions/eo/1.0/}statusSubType", "online", "Online", null, null);

            bulkDataDefs.Add(_filtersDefinition);

            return(bulkDataDefs);
        }
예제 #3
0
        public static FiltersDefinition GenerateOfflineDataFiltersDefinition(int max, IEnumerable <Mission> missions, Dictionary <string, CatalogueSetConfiguration> catConfig)
        {
            FiltersDefinition _filtersDefinition = Mission.ShuffleSimpleRandomFiltersCombination(missions, catConfig, 1).First();

            _filtersDefinition.Name = "Offline-Random";

            _filtersDefinition.AddFilter("archiveStatus", "{http://a9.com/-/opensearch/extensions/eo/1.0/}statusSubType",
                                         "Offline", "Offline data", Mission.GetArchivingStatusValidator(Terradue.ServiceModel.Ogc.Eop21.StatusSubTypeValueEnumerationType.OFFLINE), null);
            _filtersDefinition.AddFilter("sensingEnd", "{http://a9.com/-/opensearch/extensions/time/1.0/}end", DateTime.UtcNow.Subtract(TimeSpan.FromDays(700)).ToString("s"), "more than 2 years ago", null, null);

            return(_filtersDefinition);
        }
예제 #4
0
        internal static IEnumerable <FiltersDefinition> GenerateOfflineDataStatusFiltersDefinition(OfflineDataStatus offlineDataStatus, TargetSiteWrapper target)
        {
            List <FiltersDefinition> _offlineFiltersDefinition = new List <FiltersDefinition>();

            foreach (var offlineDataStatusItem in offlineDataStatus.OfflineData.Where(di => di.TargetSiteName == target.Name))
            {
                FiltersDefinition fd = new FiltersDefinition(offlineDataStatusItem.Identifier);
                fd.AddFilter("uid", "{http://a9.com/-/opensearch/extensions/geo/1.0/}uid", offlineDataStatusItem.Identifier, offlineDataStatusItem.Identifier, null, null);
                fd.RemoveFilter("{http://a9.com/-/opensearch/extensions/eo/1.0/}timeliness");
                // to force usage of ODATA for DHUS wrapper
                fd.AddFilter("archiveStatus", "dummy", "dummy", "", null, null);
                _offlineFiltersDefinition.Add(fd);
            }

            return(_offlineFiltersDefinition);
        }
예제 #5
0
        internal static FiltersDefinition GenerateFiltersDefinitionFromItem(string label, IOpenSearchResultItem item)
        {
            FiltersDefinition fd = new FiltersDefinition(string.Format("{0}-{1}", label, item.Identifier));

            if (item == null)
            {
                return(fd);
            }

            fd.AddFilter("uid", "{http://a9.com/-/opensearch/extensions/geo/1.0/}uid", item.Identifier, item.Identifier, null, null);

            var platform = item.FindPlatformShortName();

            if (!string.IsNullOrEmpty(platform))
            {
                fd.AddFilter("missionName", "{http://a9.com/-/opensearch/extensions/eo/1.0/}platform", platform, platform, null, null);
            }

            var instrument = item.FindInstrumentShortName();

            if (!string.IsNullOrEmpty(instrument))
            {
                fd.AddFilter("instrument", "{http://a9.com/-/opensearch/extensions/eo/1.0/}instrument", instrument, instrument, null, null);
            }

            var productType = item.FindProductType();

            if (!string.IsNullOrEmpty(productType))
            {
                fd.AddFilter("productType", "{http://a9.com/-/opensearch/extensions/eo/1.0/}productType", productType, productType, null, null);
            }

            var processingLevel = item.FindProcessingLevel();

            if (!string.IsNullOrEmpty(processingLevel))
            {
                fd.AddFilter("processingLevel", "{http://a9.com/-/opensearch/extensions/eo/1.0/}processingLevel", processingLevel, processingLevel, null, null);
            }

            try
            {
                var startDate = item.FindStartDate();
                if (startDate != DateTime.MinValue)
                {
                    fd.AddFilter("sensingStart", "{http://a9.com/-/opensearch/extensions/time/1.0/}start", startDate.ToString("O"), string.Format("starting at {0}", startDate.ToString()), null, null);
                }

                var endDate = item.FindEndDate();
                if (endDate != DateTime.MinValue)
                {
                    fd.AddFilter("sensingEnd", "{http://a9.com/-/opensearch/extensions/time/1.0/}end", endDate.ToString("O"), string.Format("ending at {0}", endDate.ToString()), null, null);
                }
            }
            catch { }

            return(fd);
        }
예제 #6
0
        /// <summary>
        /// Creates a list of cross filter definitions for a target site against a reference target site.
        /// </summary>
        /// <param name="setName">The name of the catalogue set.</param>
        /// <param name="setConfiguration">The configuration set</param>
        /// <param name="target">The target</param>
        /// <returns>A list of cross filter definitions.</returns>
        internal static IEnumerable <CrossCatalogueCoverageFiltersDefinition> GenerateCrossCatalogueCoverageFiltersDefinition(string setName, CatalogueSetConfiguration setConfiguration, TargetSiteWrapper target)
        {
            List <CrossCatalogueCoverageFiltersDefinition> bulkDataDefs = new List <CrossCatalogueCoverageFiltersDefinition>();

            // Let's get the baseline
            var catalogueSetConfiguration = ResolveBaseline(setName, setConfiguration);

            // Let's get the reference target
            TargetSiteWrapper ref_target = new TargetSiteWrapper(setConfiguration.ReferenceTargetSite, Configuration.Current.GetTargetSiteConfiguration(setConfiguration.ReferenceTargetSite));

            // Let's build the filter defintions
            foreach (FiltersDefinition pt in GenerateFilterDefinitionsFromCollectionsDefinition(catalogueSetConfiguration))
            {
                FiltersDefinition _targetFiltersDefinition = new FiltersDefinition("[target]");

                _targetFiltersDefinition.AddFilters(pt.Filters);
                _targetFiltersDefinition.AddFilter("count", "{http://a9.com/-/spec/opensearch/1.1/}count", "0", "", null, null);
                try
                {
                    _targetFiltersDefinition.AddFilters(catalogueSetConfiguration.Parameters);
                }
                catch { }
                FiltersDefinition _refFiltersDefinition = new FiltersDefinition(_targetFiltersDefinition);
                _refFiltersDefinition.Name = "[reference]";
                // special filter for filtering out product that are not considered as in the reference baseline
                try
                {
                    _targetFiltersDefinition.AddFilters(setConfiguration.Parameters);
                }
                catch { }

                bulkDataDefs.Add(new CrossCatalogueCoverageFiltersDefinition(
                                     new TargetAndFiltersDefinition(target, _targetFiltersDefinition),
                                     new TargetAndFiltersDefinition(ref_target, _refFiltersDefinition)
                                     ));
            }
            return(bulkDataDefs);
        }
예제 #7
0
        private static FiltersDefinition ShuffleSimpleRandomFiltersCombination(Mission mission, Dictionary <string, DataCollectionDefinition> collections, string FilterSetkey, Func <ItemNumberRange, string> rangeReformatter = null, int limit = 3)
        {
            FiltersDefinition _filtersDefinition = new FiltersDefinition(FilterSetkey);
            var collection = collections.ToArray()[rnd.Next(0, collections.Count())].Value;

            _filtersDefinition.AddFilters(collection.Parameters, mission);
            // _filtersDefinition.AddFilter("missionName", "{http://a9.com/-/opensearch/extensions/eo/1.0/}platform",  mission.MissionName.Value, mission.MissionName.Label, mission.MissionName.Validator, null);

            IEnumerable <System.Reflection.PropertyInfo> props = mission.GetType().GetProperties().Where(
                prop => Attribute.IsDefined(prop, typeof(SimpleChoiceAttribute)));

            foreach (var prop in props)
            {
                if (_filtersDefinition.GetFilters().Count() >= limit)
                {
                    continue;
                }
                if (rnd.Next() % 2 == 0)
                {
                    continue;
                }
                var choice = prop.GetValue(mission);
                if (choice == null)
                {
                    continue;
                }
                if (_filtersDefinition.Filters.Any(fd => fd.FullName == ((IMissionFilter)choice).FullName))
                {
                    continue;
                }
                if (choice is StringListChoice)
                {
                    var sl    = choice as StringListChoice;
                    var value = sl.LabelStrings.ToArray()[rnd.Next(0, sl.LabelStrings.Count())];
                    _filtersDefinition.AddFilter(sl.Key, sl.FullName, value.Value, value.Label, value.Validator, null);
                }
                if (choice is ItemNumberRange)
                {
                    var     nb        = choice as ItemNumberRange;
                    int     randomMin = rnd.Next((int)(nb.Min / nb.Step), (int)(nb.Max / nb.Step));
                    decimal min       = new decimal(randomMin * nb.Step);
                    int     randomMax = rnd.Next((int)((int)min / nb.Step), (int)(nb.Max / nb.Step));
                    decimal max       = new decimal(randomMax * nb.Step);
                    var     value     = new double[2] {
                        (double)min, (double)max
                    };
                    var formatter = nb.Formatter;
                    if (rangeReformatter != null)
                    {
                        formatter = rangeReformatter.Invoke(nb);
                    }
                    Func <IOpenSearchResultItem, bool> ivalidator = null;
                    if (nb.ItemValueValidator != null)
                    {
                        ivalidator = nb.ItemValueValidator.Invoke(value);
                    }
                    Func <IOpenSearchResultCollection, bool> cvalidator = null;
                    if (nb.ResultsValidator != null)
                    {
                        cvalidator = nb.ResultsValidator.Invoke(value);
                    }
                    _filtersDefinition.AddFilter(nb.Key, nb.FullName, string.Format(formatter, value.Cast <object>().ToArray()), string.Format("{0} {1}", nb.Label, string.Format(formatter, value.Cast <object>().ToArray())), ivalidator, cvalidator);
                }
            }

            return(_filtersDefinition);
        }