Exemplo n.º 1
0
        private Dictionary <EmotionsType, double> CalculateEmotionsWeights()
        {
            Dictionary <EmotionsType, double> weights = new Dictionary <EmotionsType, double>();

            //Calculate weights
            foreach (EmotionsType emoType in Enum.GetValues(typeof(EmotionsType)))
            {
                weights[emoType] = 0;
                for (int i = 0; i < _EmotionsInformation.Count; i++)
                {
                    var emotions = _EmotionsInformation[i].Emotions;
                    for (int j = 0; j < emotions.Count; j++)
                    {
                        weights[emoType]
                            += EmoUtils.GetEmoScore(emotions[j], emoType) * 1000;
                    }
                }
            }
            //Calculate sum
            double sum  = 0;
            var    keys = weights.Keys;

            foreach (var key in keys)
            {
                sum += weights[key];
            }
            //Normalize weight
            foreach (var key in keys.ToList())
            {
                double val = weights[key];
                weights[key] = val / sum;
            }
            return(weights);
        }
Exemplo n.º 2
0
        public string GetUrlPhotoWithEmotion(EmotionsType type)
        {
            string url             = string.Empty;
            double maxEmotionScore = 0;

            for (int i = 0; i < _EmotionsInformation.Count; i++)
            {
                EmoInfo emotInf             = _EmotionsInformation[i];
                double  currentEmotionScore = 0;
                int     facesCount          = emotInf.Emotions.Count;
                //если человек на фотографии не один - продолжаем дальше
                if (facesCount > 1)
                {
                    continue;
                }
                for (int j = 0; j < emotInf.Emotions.Count; j++)
                {
                    currentEmotionScore += EmoUtils.GetEmoScore(emotInf.Emotions[j], type);
                }
                if (currentEmotionScore > maxEmotionScore)
                {
                    maxEmotionScore = currentEmotionScore;
                    url             = emotInf.ImageUrl;
                }
            }
            return(url);
        }
Exemplo n.º 3
0
        public async Task LoadProfileData(
            string userName,
            string apiKey,
            bool isApiKeyTrial = true)
        {
            _InstagramInformation = await InstaUtils.GetInfoPostList(userName);

            _EmotionsInformation = await EmoUtils.GetEmoData(
                userName,
                InstagramInformation,
                apiKey,
                isApiKeyTrial);

            _Name            = userName;
            _AvatarUrl       = InstagramInformation[0].ProfileImageUrl;
            _EmotionsWeights = CalculateEmotionsWeights();
        }