예제 #1
0
 /// <summary>
 /// Prevents a default instance of the <see cref="NewsEmotionLogic"/> class from being created.
 /// </summary>
 private NewsEmotionLogic()
 {
     //"default" emotions:
     _emotions = new EmotionResponse
     {
         scores = new Scores
         {
             happiness = 0.5
         }
     };
 }
예제 #2
0
        /// <summary>
        /// Calculates the stories.
        /// </summary>
        /// <returns></returns>
        public async Task <string> updateHappiness()
        {
            try
            {
                var error = await EmotionProcessingLogic.Instance.TakePicture();

                var byteRA = ReadFully(EmotionProcessingLogic.Instance.MediaFile.GetStream());
                _emotions = await EmotionService.getEmotion(byteRA);

                return(null);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
예제 #3
0
    public Emotion(EmotionResponse emotionResponse)
    {
        if (emotionResponse?.emotion == null)
        {
            valence = Level.MEDIUM;
            arousal = Level.MEDIUM;
            return;
        }
        var match = emotionRegex.Match(emotionResponse.emotion);

        if (!match.Success)
        {
            valence = Level.MEDIUM;
            arousal = Level.MEDIUM;
            return;
        }
        valence    = GetLevelFromString(match.Groups[1].Value);
        arousal    = GetLevelFromString(match.Groups[2].Value);
        additional = emotionResponse.additional;
    }
예제 #4
0
    public IEnumerator AskForEmotion()
    {
        if (!apiEnabled)
        {
            yield break;
        }
        requestInProgress = true;
        var rrArray     = heartRateManager.RrArray.Select(rr => rr / 1000).ToArray();
        var hrArray     = heartRateManager.HrArray;
        var requestBody = new RequestBody {
            hr = hrArray, rr = rrArray
        };

        var uri = URI + (URI.EndsWith("/") ? "classify" : "/classify");

        using (UnityWebRequest req = UnityWebRequest.Put(uri, JsonUtility.ToJson(requestBody)))
        {
            req.SetRequestHeader("Content-Type", "application/json");
            yield return(req.SendWebRequest());

            while (!req.isDone)
            {
                yield return(null);
            }

            if (!req.isHttpError && !req.isNetworkError && req.error == null)
            {
                var result  = req.downloadHandler.data;
                var json    = System.Text.Encoding.Default.GetString(result);
                var emotion = JsonUtility.FromJson <EmotionResponse>(json);
                m_LastEmotionResponse    = emotion;
                isNewEmotionSinceLastGet = true;
            }

            requestInProgress = false;
        }
    }
예제 #5
0
        public EmotionResponse Convert(Emotion source)
        {
            var result = default(EmotionResponse);

            if (source != null)
            {
                result = new EmotionResponse
                {
                    Anger       = source.Anger,
                    Contempt    = source.Contempt,
                    DateTimeUtc = source.DateTimeUtc,
                    Disgust     = source.Disgust,
                    Fear        = source.Fear,
                    Happiness   = source.Happiness,
                    Id          = source.Id,
                    Neutral     = source.Neutral,
                    PersonId    = source.PersonId,
                    Sadness     = source.Sadness,
                    Smile       = source.Smile,
                    Surprise    = source.Surprise
                };
            }
            return(result);
        }