Example #1
0
        public static async Task <List <Emotion> > GetEmotionResultsFromMediaFile(MediaFile mediaFile, bool disposeMediaFile)
        {
            using (var handle = AnalyticsHelpers.TrackTime(AnalyticsConstants.AnalyzeEmotion))
            {
                var faceApiResponseList = await FaceApiClient.Face.DetectWithStreamAsync(MediaService.GetPhotoStream(mediaFile, disposeMediaFile),
                                                                                         returnFaceAttributes : new List <FaceAttributeType> {
                    { FaceAttributeType.Emotion }
                }).ConfigureAwait(false);

                return(faceApiResponseList.Select(x => x.FaceAttributes.Emotion).ToList());
            }
        }
Example #2
0
        public static async Task <Emotion[]> GetEmotionResultsFromMediaFile(MediaFile mediaFile, bool disposeMediaFile)
        {
            Device.BeginInvokeOnMainThread(() => Application.Current.MainPage.IsBusy = true);

            try
            {
                using (var handle = AnalyticsHelpers.TrackTime(AnalyticsConstants.AnalyzeEmotion))
                    return(await EmotionClient.RecognizeAsync(MediaService.GetPhotoStream(mediaFile, disposeMediaFile)));
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() => Application.Current.MainPage.IsBusy = false);
            }
        }
Example #3
0
        void StartGame()
        {
            var isPlayer1EntryTextEmpty = string.IsNullOrWhiteSpace(_player1Entry.Text);
            var isPlayer2EntryTextEmpty = string.IsNullOrWhiteSpace(_player2Entry.Text);

            if (isPlayer1EntryTextEmpty)
            {
                AnalyticsHelpers.Track(AnalyticsConstants.StartGameButtonTapped, AnalyticsConstants.StartGameButtonTappedStatus, AnalyticsConstants.Player1NameEmpty);
                DisplayEmptyPlayerNameAlert(1);
            }
            else if (isPlayer2EntryTextEmpty)
            {
                AnalyticsHelpers.Track(AnalyticsConstants.StartGameButtonTapped, AnalyticsConstants.StartGameButtonTappedStatus, AnalyticsConstants.Player2NameEmpty);
                DisplayEmptyPlayerNameAlert(2);
            }
            else
            {
                AnalyticsHelpers.Track(AnalyticsConstants.StartGameButtonTapped, AnalyticsConstants.StartGameButtonTappedStatus, AnalyticsConstants.GameStarted);
                Device.BeginInvokeOnMainThread(async() => await Navigation.PushAsync(new FaceOffPage()));
            }
        }
Example #4
0
        public static async Task <List <Emotion> > GetEmotionResultsFromMediaFile(MediaFile mediaFile, bool disposeMediaFile)
        {
            Device.BeginInvokeOnMainThread(() => Application.Current.MainPage.IsBusy = true);

            try
            {
                using (var handle = AnalyticsHelpers.TrackTime(AnalyticsConstants.AnalyzeEmotion))
                {
                    var faceApiResponseList = await FaceApiClient.Face.DetectWithStreamAsync(MediaService.GetPhotoStream(mediaFile, disposeMediaFile),
                                                                                             returnFaceAttributes : new List <FaceAttributeType> {
                        { FaceAttributeType.Emotion }
                    }).ConfigureAwait(false);

                    return(faceApiResponseList.Select(x => x.FaceAttributes.Emotion).ToList());
                }
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() => Application.Current.MainPage.IsBusy = false);
            }
        }
Example #5
0
 public void Dispose()
 {
     _stopwatch.Stop();
     Data.Add("Timed Event", $"{_stopwatch.Elapsed.ToString(@"ss\.fff")}s");
     AnalyticsHelpers.Track($"{_trackIdentifier} [Timed Event]", Data);
 }
Example #6
0
        public static string GetPhotoEmotionScore(List <Emotion> emotionResults, int emotionResultNumber, EmotionType currentEmotionType)
        {
            double rawEmotionScore;

            var isInternetConnectionAvilable = Connectivity.NetworkAccess.Equals(NetworkAccess.Internet);

            if (!isInternetConnectionAvilable)
            {
                return(ErrorMessageDictionary[ErrorMessageType.ConnectionToCognitiveServicesFailed]);
            }

            if (emotionResults == null || emotionResults.Count < 1)
            {
                return(ErrorMessageDictionary[ErrorMessageType.NoFaceDetected]);
            }

            if (emotionResults.Count > 1)
            {
                OnMultipleFacesDetectedAlertTriggered();
                return(ErrorMessageDictionary[ErrorMessageType.MultipleFacesDetected]);
            }

            try
            {
                switch (currentEmotionType)
                {
                case EmotionType.Anger:
                    rawEmotionScore = emotionResults[emotionResultNumber].Anger;
                    break;

                case EmotionType.Contempt:
                    rawEmotionScore = emotionResults[emotionResultNumber].Contempt;
                    break;

                case EmotionType.Disgust:
                    rawEmotionScore = emotionResults[emotionResultNumber].Disgust;
                    break;

                case EmotionType.Fear:
                    rawEmotionScore = emotionResults[emotionResultNumber].Fear;
                    break;

                case EmotionType.Happiness:
                    rawEmotionScore = emotionResults[emotionResultNumber].Happiness;
                    break;

                case EmotionType.Neutral:
                    rawEmotionScore = emotionResults[emotionResultNumber].Neutral;
                    break;

                case EmotionType.Sadness:
                    rawEmotionScore = emotionResults[emotionResultNumber].Sadness;
                    break;

                case EmotionType.Surprise:
                    rawEmotionScore = emotionResults[emotionResultNumber].Surprise;
                    break;

                default:
                    return(ErrorMessageDictionary[ErrorMessageType.GenericError]);
                }

                var emotionScoreAsPercentage = ConversionService.ConvertDoubleToPercentage(rawEmotionScore);

                return(emotionScoreAsPercentage);
            }
            catch (Exception e)
            {
                AnalyticsHelpers.Report(e);
                return(ErrorMessageDictionary[ErrorMessageType.GenericError]);
            }
        }
Example #7
0
        public static async Task <string> GetPhotoEmotionScore(Emotion[] emotionResults, int emotionResultNumber, EmotionType currentEmotionType)
        {
            float rawEmotionScore;

            var isInternetConnectionAvilable = await ConnectionService.IsInternetConnectionAvailable().ConfigureAwait(false);

            if (!isInternetConnectionAvilable)
            {
                return(ErrorMessageDictionary[ErrorMessageType.ConnectionToCognitiveServicesFailed]);
            }

            if (emotionResults == null || emotionResults.Length < 1)
            {
                return(ErrorMessageDictionary[ErrorMessageType.NoFaceDetected]);
            }

            if (emotionResults.Length > 1)
            {
                OnMultipleFacesDetectedAlertTriggered();
                return(ErrorMessageDictionary[ErrorMessageType.MultipleFacesDetected]);
            }

            try
            {
                switch (currentEmotionType)
                {
                case EmotionType.Anger:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Anger;
                    break;

                case EmotionType.Contempt:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Contempt;
                    break;

                case EmotionType.Disgust:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Disgust;
                    break;

                case EmotionType.Fear:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Fear;
                    break;

                case EmotionType.Happiness:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Happiness;
                    break;

                case EmotionType.Neutral:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Neutral;
                    break;

                case EmotionType.Sadness:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Sadness;
                    break;

                case EmotionType.Surprise:
                    rawEmotionScore = emotionResults[emotionResultNumber].Scores.Surprise;
                    break;

                default:
                    return(ErrorMessageDictionary[ErrorMessageType.GenericError]);
                }

                var emotionScoreAsPercentage = ConversionService.ConvertFloatToPercentage(rawEmotionScore);

                return(emotionScoreAsPercentage);
            }
            catch (Exception e)
            {
                AnalyticsHelpers.Report(e);
                return(ErrorMessageDictionary[ErrorMessageType.GenericError]);
            }
        }
Example #8
0
        protected override void OnStart()
        {
            base.OnStart();

            AnalyticsHelpers.Start();
        }