Ejemplo n.º 1
0
        /// <summary>
        /// Handles an incoming search result.
        /// </summary>
        /// <param name="likeliness">Search result to handle</param>
        public async Task HandleSearchResult(LikelinessResult likeliness)
        {
            Debug.WriteLine(string.Format("Handling search result with confidence={0}", likeliness.Confidence));
            if (await scheduler.CheckExists(new JobKey(likeliness.FaceToken, "timeout")))
            {
                return;
            }
            switch (likeliness.Confidence)
            {
            case LikelinessConfidence.LowProbability:
                break;

            case LikelinessConfidence.NormalProbability:
            case LikelinessConfidence.HighProbability:
                await ScheduleJobByLikeliness <SendNotificationJob>(likeliness, "notificationJob");

                break;

            case LikelinessConfidence.VeryHighProbability:
                var        key = new JobKey(likeliness.FaceToken, "notificationJob");
                IJobDetail instantNotificationJob = JobBuilder.Create <SendNotificationJob>()
                                                    .WithIdentity(key)
                                                    .UsingJobData("confidence", (int)likeliness.Confidence)
                                                    .Build();
                await scheduler.AddJob(instantNotificationJob, true, true);

                await scheduler.TriggerJob(key);
                await ScheduleJobByLikeliness <TimeoutJob>(likeliness, "timeout");

                break;
            }
        }
Ejemplo n.º 2
0
 public IEnumerable <LikelinessResult> LikelinessConfidences()
 {
     if (Results == null)
     {
         yield break;
     }
     foreach (Result result in Results)
     {
         LikelinessResult likelinessResult = default(LikelinessResult);
         likelinessResult.FaceToken = result.Face_token;
         if (result.Confidence < Thresholds.E3)
         {
             likelinessResult.Confidence = LikelinessConfidence.LowProbability;
         }
         else if (result.Confidence < Thresholds.E4)
         {
             likelinessResult.Confidence = LikelinessConfidence.NormalProbability;
         }
         else if (result.Confidence < Thresholds.E5)
         {
             likelinessResult.Confidence = LikelinessConfidence.HighProbability;
         }
         else
         {
             likelinessResult.Confidence = LikelinessConfidence.VeryHighProbability;
         }
         yield return(likelinessResult);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Handles a single searchResult with no scheduling - sends it out if it meets the minimum confidence requirement.
 /// </summary>
 /// <param name="minimumConfidence">Minimum confidence to send the notification</param>
 /// <returns></returns>
 public static async Task HandleOneResult(LikelinessResult result, LikelinessConfidence minimumConfidence, CameraProperties cameraProperties = null)
 {
     if (result.Confidence >= minimumConfidence)
     {
         Debug.WriteLine(string.Format("Probability {0} meets minimum confidence requirement, notification will be sent.", result.Confidence));
         await SendNotification(result.FaceToken, result.Confidence, cameraProperties);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Schedules a notification job.
        /// Detail depend on the likeliness level
        /// </summary>
        /// <typeparam name="JobType">Type of job to create</typeparam>
        /// <param name="likelinessResult">Likeliness result</param>
        /// <param name="group">Group of the job to create</param>
        /// <returns></returns>
        private async Task ScheduleJobByLikeliness <JobType>(LikelinessResult likelinessResult, string group) where JobType : IJob
        {
            var        jobKey = new JobKey(likelinessResult.FaceToken, group);
            IJobDetail job    = JobBuilder.Create <JobType>()
                                .WithIdentity(jobKey)
                                .UsingJobData("confidence", (int)likelinessResult.Confidence)
                                .Build();
            ITrigger triggerByConfidence = TriggerBuilder.Create()
                                           .ForJob(job)
                                           .StartAt(DateTime.Now.AddSeconds(likelinessLevelData[likelinessResult.Confidence].TimeLimit))
                                           .Build();
            var oldJob = await scheduler.GetJobDetail(jobKey);

            if (oldJob != null)
            {
                var trigger      = (await scheduler.GetTriggersOfJob(jobKey)).FirstOrDefault();
                var triggerToUse = trigger == null || trigger.StartTimeUtc > triggerByConfidence.StartTimeUtc ?
                                   triggerByConfidence : trigger;
                if (oldJob.JobDataMap.GetInt("confidence") < (int)likelinessResult.Confidence)
                {
                    await scheduler.AddJob(job, true, true);

                    await scheduler.ScheduleJob(triggerToUse);
                }
                else
                {
                    await scheduler.RescheduleJob(trigger.Key, triggerToUse);
                }
                return;
            }
            else
            {
                await scheduler.AddJob(job, true, true);

                await scheduler.ScheduleJob(triggerByConfidence);
            }
        }