示例#1
0
    public void Apply()
    {
        GatherTimeRange();
        TemporalRangeFilter      tf           = new TemporalRangeFilter(lowerBound, upperBound);
        GeoLocation              lastKnownLoc = controller.GetLastKnownLocation();
        SpatialMaxDistanceFilter sf           = new SpatialMaxDistanceFilter(maxDist * 1000, lastKnownLoc.latitude, lastKnownLoc.longitude);

        logger.Debug("Created filters:\nTime: {0}\nDist: {1}", tf, sf);
        filterEngine.AddFilterStrategy(tf);
        filterEngine.AddFilterStrategy(sf);

        List <MultimediaObject> filteredList = filterEngine.ApplyFilters(controller.GetOriginalList());

        logger.Debug("Filtered list, notifying ui...");
        controller.SetActiveList(filteredList);
        uiManager.panelManager.ShowPanel("choice");
    }
        private IEnumerator ExecuteMultiQuery(SimilarQuery query, CategoryRatio ratio, string guid = null)
        {
            // === SIMILAR ===
            // Initial SimilarQuery
            yield return(similarRequest = CineastUtils.BuildSimilarRequest(CineastUtils.Configuration.FindSimilarSegmentsUrl(), query));

            // Parse response
            earlyBreak = !Parse(similarRequest.text, out similarResult);
            yield return(similarResult);

            if (earlyBreak)
            {
                yield break;
            }

            // Check if empty
            if (similarResult.IsEmpty())
            {
                earlyBreak = true;
                yield break; // Stop and
            }

            ContentObject[] tempResult = CineastUtils.ExtractContentObjects(similarResult);

            if (ratio != null && similarResult.results.Length > 1)
            {
                ResultMerger merger = new ResultMerger();
                tempResult = merger.Merge(similarResult.results, ratio)
                             .ToArray();
            }

            // === SEGMENTS ===
            // segments
            yield return(segmentRequest =
                             CineastUtils.BuildSegmentRequest(CineastUtils.Configuration.FindSegmentsByIdUrl(),
                                                              CineastUtils.ExtractIdArray(tempResult)));

            // parse response
            earlyBreak = !Parse(segmentRequest.text, out segmentResult);
            yield return(segmentResult);

            if (earlyBreak)
            {
                yield break;
            }

            // === METAS ===
            yield return(metaRequest =
                             CineastUtils.BuildMetadataRequest(CineastUtils.Configuration.FindMetadataUrl(),
                                                               CineastUtils.ExtractIdArray(segmentResult.content)));

            earlyBreak = !Parse(metaRequest.text, out metaResult);
            yield return(metaResult);

            if (earlyBreak)
            {
                yield break;
            }
            // meta->mmo
            objectList = CineastUtils.Convert(metaResult.content);

            // === OBJECTS ===
            yield return(objectRequest =
                             CineastUtils.BuildObjectsRequest(CineastUtils.Configuration.FindObjectsUrl(),
                                                              CineastUtils.ExtractIdArray(objectList.ToArray())));

            yield return(objectsResult = JsonUtility.FromJson <ObjectsResult>(objectRequest.text));

            // merge results
            List <MultimediaObject> objects = CineastUtils.Convert(objectsResult.content);

            foreach (MultimediaObject mmo in objects)
            {
                if (objectList.Contains(mmo))
                {
                    objectList.Find(o => o.Equals(mmo)).Merge(mmo);
                }
            }

            results = new List <MultimediaObject>(objectList);

            // === WRAPUP ===
            foreach (MultimediaObject mmo in objectList)
            {
                mmo.resultIndex = CineastUtils.GetIndexOf(mmo, similarResult) + 1;
            }

            // === SORT LIST ===
            objectList.Sort(Comparison);

            List <MultimediaObject> transferList;

            if (filterEngine != null)
            {
//                logger.Debug("FilterEngine installed with " + filterEngine.GetFilterCount() + " filters.");
                transferList = filterEngine.ApplyFilters(objectList);
            }
            else
            {
//                logger.Debug("No FilterEngine installed - no filtering");
                transferList = objectList;
            }


            // cleanup
            finished = true;
            if (guid == null)
            {
                // LEGACY
                if (queryFinishedCallback != null)
                {
                    //                logger.Info("Query completed, passing resulting MultimediaObject list to callback");
                    queryFinishedCallback.Invoke(transferList);
                }
            }
            else
            {
                CineastResponseHandler <List <MultimediaObject> > handler = _guidHandlerMap[guid];
                if (handler != null)
                {
                    handler.onSuccess(transferList);
                }
            }

            yield return(true);
        }