示例#1
0
        public static string GetStringOfAllPhotoEmotionScores(Emotion[] emotionResults, int emotionResultNumber)
        {
            if (emotionResults == null || emotionResults.Length < 1)
            {
                return(ErrorMessageDictionary[ErrorMessageType.GenericError]);
            }

            var allEmotionsString = new StringBuilder();

            allEmotionsString.AppendLine($"Anger: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Anger)}");
            allEmotionsString.AppendLine($"Contempt: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Contempt)}");
            allEmotionsString.AppendLine($"Disgust: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Disgust)}");
            allEmotionsString.AppendLine($"Fear: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Fear)}");
            allEmotionsString.AppendLine($"Happiness: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Happiness)}");
            allEmotionsString.AppendLine($"Neutral: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Neutral)}");
            allEmotionsString.AppendLine($"Sadness: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Sadness)}");
            allEmotionsString.Append($"Surprise: {ConversionService.ConvertFloatToPercentage(emotionResults[emotionResultNumber].Scores.Surprise)}");

            return(allEmotionsString.ToString());
        }
示例#2
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)
            {
                Insights.Report(e);
                return(ErrorMessageDictionary[ErrorMessageType.GenericError]);
            }
        }
示例#3
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]);
            }
        }