Example #1
0
        public RestRating(double happy)
        {
            InitializeComponent();

            MoodModel mood = new MoodModel();

            this.happinessRating = Math.Round(happy * 10, 2);
            label8.Text          = happinessRating.ToString();
        }
        public async Task <MoodModel> GetEmotions(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(new MoodModel());
            }

            try
            {
                HttpClient client = new HttpClient();

                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

                string requestParameters = "returnFaceId=false&returnFaceLandmarks=false" +
                                           "&returnFaceAttributes=emotion";

                // Assemble the URI for the REST API Call.
                string uri = uriBase + "?" + requestParameters;

                HttpResponseMessage response;

                byte[] byteData = GetImageAsByteArray(filePath);

                using (ByteArrayContent content = new ByteArrayContent(byteData))
                {
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                    // Execute the REST API call.
                    response = await client.PostAsync(uri, content);

                    // Get the JSON response.
                    string contentString = await response.Content.ReadAsStringAsync();

                    // Deserialize JSON string
                    dynamic jsonObj = JsonConvert.DeserializeObject(contentString.Substring(1, contentString.Length - 2));

                    MoodModel moodModel = new MoodModel();

                    //wanna vomit from the code below
                    moodModel.Anger     = jsonObj.faceAttributes.emotion.anger.Value;
                    moodModel.Contempt  = jsonObj.faceAttributes.emotion.contempt.Value;
                    moodModel.Disgust   = jsonObj.faceAttributes.emotion.disgust.Value;
                    moodModel.Fear      = jsonObj.faceAttributes.emotion.fear.Value;
                    moodModel.Happiness = jsonObj.faceAttributes.emotion.happiness.Value;
                    moodModel.Neutral   = jsonObj.faceAttributes.emotion.neutral.Value;
                    moodModel.Sadness   = jsonObj.faceAttributes.emotion.sadness.Value;
                    moodModel.Surprise  = jsonObj.faceAttributes.emotion.surprise.Value;

                    return(moodModel);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\n" + e.Message + "\nPress Enter to exit...\n");
                return(new MoodModel());
            }
        }
Example #3
0
 private void SetLabels(MoodModel model)
 {
     angerLabel.Text     = "Anger: " + (model.Anger * 100).ToString() + "%";
     contemptLabel.Text  = "Contempt: " + (model.Contempt * 100).ToString() + "%";
     disgustLabel.Text   = "Disgust: " + (model.Disgust * 100).ToString() + "%";
     fearLabel.Text      = "Fear: " + (model.Fear * 100).ToString() + "%";
     happinessLabel.Text = "Happiness: " + (model.Happiness * 100).ToString() + "%";
     neutralLabel.Text   = "Neutral: " + (model.Neutral * 100).ToString() + "%";
     sadnessLabel.Text   = "Sadness: " + (model.Sadness * 100).ToString() + "%";
     surpirseLabel.Text  = "Surprise: " + (model.Surprise * 100).ToString() + "%";
 }
Example #4
0
        public async Task <MoodModel> GetEmotions(byte[] byteArray)
        {
            try
            {
                HttpClient client = new HttpClient();

                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

                //parameters of what data should be returned about the face
                string requestParameters = "returnFaceId=false&returnFaceLandmarks=false" +
                                           "&returnFaceAttributes=emotion";

                // Assemble the URI for the REST API Call.
                string uri = uriBase + "?" + requestParameters;

                HttpResponseMessage response;

                using (ByteArrayContent content = new ByteArrayContent(byteArray))
                {
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                    // Execute the REST API call.
                    response = client.PostAsync(uri, content).GetAwaiter().GetResult();

                    // Get the JSON response.
                    string contentString = await response.Content.ReadAsStringAsync();

                    // Deserialize JSON string
                    MoodModel moodModel = JsonConvert.DeserializeObject <MoodModel>(contentString.Substring(1, contentString.Length - 2));

                    return(moodModel);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\n" + e.Message + "\nPress Enter to exit...\n");
                return(new MoodModel());
            }
        }
        public IHttpActionResult SetMood(string id)
        {
            var       mood = _db.Mood.ToList().Where(x => x.UserId == id.Split('_')[0]);
            MoodModel mm   = new MoodModel();
            int       type = Convert.ToInt32(id.Split('_')[1]);

            var moodModels = mood as MoodModel[] ?? mood.ToArray();

            if (moodModels.Any())
            {
                if (mm.Date == DateTime.Now.ToString())
                {
                    mm                  = moodModels.First();
                    mm.Date             = DateTime.Now.ToString();
                    mm.Type             = type;
                    _db.Entry(mm).State = System.Data.Entity.EntityState.Modified;
                    _db.SaveChanges();
                }
                else
                {
                    mm.Id     = Guid.NewGuid().ToString();
                    mm.UserId = id;
                    mm.Date   = DateTime.Now.ToString();
                    mm.Type   = type;
                    _db.Mood.Add(mm);
                    _db.SaveChanges();
                }
            }
            else
            {
                mm.Id     = Guid.NewGuid().ToString();
                mm.UserId = id;
                mm.Date   = DateTime.Now.ToString();
                mm.Type   = type;
                _db.Mood.Add(mm);
                _db.SaveChanges();
            }
            return(Ok("set"));
        }
Example #6
0
        // gets mood from the picture
        private async void GetMood()
        {
            _moodModel = await _moodDetector.GetEmotions(_faceImage);

            CalculatedMood = _calculateMood.CalculateMood(_moodModel);
        }
Example #7
0
    public void Start()
    {
        this.isCurrentAppraisalDirty = false;

        //Get personality values. Create Personality Object
        this.AgentPersonality = new Personality (0.4f, 0.8f, 0.6f, 0.3f, 0.4f);

        //Create MoodModel with personality
        this.CurrentMoods = new MoodModel (AgentPersonality);

        CheckTime = System.DateTime.Now;
        CheckTimeDecay = System.DateTime.Now;
    }
Example #8
0
 public double CalculateMood(MoodModel moodModel)
 {
     //calculate score need implementations
     return(moodModel.faceAttributes.emotion.happiness * 10);
 }