private PictureEmotionData Parser(List <object> list) { var pem = new PictureEmotionData(); var feceSubject = FaceRectangle.Subjects(); var emoSubject = EmotionScore.Subjects(); foreach (object obj in list) { var dic = obj as Dictionary <string, object>; Assert.IsNotNull(dic); var set = pem.AddSet(); var face = set.Key; var emo = set.Value; var fd = JsonParser <Dictionary <string, object> > .Parse(dic, "faceRectangle"); var ed = JsonParser <Dictionary <string, object> > .Parse(dic, "scores"); foreach (var fs in feceSubject) { face.Set(fs.Key, (int)JsonParser <System.Int64> .ParseObj(fd, fs.Value)); } foreach (var es in emoSubject) { emo.Set(es.Key, JsonParser <double> .ParseObj(ed, es.Value)); } Debug.Log("face.Get(FaceRectangle.VALUE.height)" + face.Get(FaceRectangle.VALUE.height)); Debug.Log("emo.Get(EmotionScore.VALUE.anger)" + emo.Get(EmotionScore.VALUE.anger)); } return(pem); }
private void ParseResults(Emotion[] results, WriteableBitmap bitmap) { if (results == null || results.Length == 0) { if (OnError != null) { OnError(this, "Fikk ikke et bilde som gav resultater. Prøv igjen!"); } return; } var scores = results[0].Scores; var properties = scores.GetType().GetTypeInfo().DeclaredProperties; var sortedProperties = properties.Select(s => new { Name = s.Name, Score = s.GetValue(scores) }).OrderByDescending(o => o.Score); var first = sortedProperties.First(); switch (first.Name) { case "Anger": AngerScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; case "Contempt": ContemptScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; case "Disgust": DisgustScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; case "Fear": FearScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; case "Happiness": HappinessScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; case "Neutral": NeutralScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; case "Sadness": SadnessScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; case "Surprise": SurpriseScore = new EmotionScore(first.Name, (float)first.Score) { Bitmap = bitmap }; break; } }
private void CaptureAndSend() { _Camera.cam_Start(); while (_togglePlay) { Stopwatch timer = Stopwatch.StartNew(); MemoryStream pic = _Camera.cam_TakePic(); sampleTime += _sampleRate.TotalMilliseconds; if (pic != null && pic.Length > 0) { EmotionScore score = _EmoClient.GetEmotion(pic, sampleTime).Result; //var score = _EmoClient.GetDummyEmotion(sampleTime, null).Result; //Update scores to 0 value in case it is null. Doing this so that execution doesn't break score.scores = score.scores ?? new Scores(); //use EmotionScore data to draw RuntimeVisualization _runtimeVisual.UpdateData(score, pic); } timer.Stop(); TimeSpan timeToSleep = _sampleRate - timer.Elapsed; timeToSleep = timeToSleep < TimeSpan.Zero ? TimeSpan.Zero : timeToSleep; Thread.Sleep(timeToSleep); } _Camera.cam_Stop(); }
public Task <EmotionScore> GetDummyEmotion(double time, MemoryStream stream = null) { double defVal = 0.5; Scores score = new Scores() { anger = defVal, contempt = defVal, disgust = defVal, fear = defVal, happiness = defVal, neutral = defVal, sadness = defVal, surprise = defVal, }; EmotionScore res = new EmotionScore() { timeStamp = time, startTime = DateTime.UtcNow, endTime = DateTime.UtcNow, executionId = this.ExecutionId, scores = score, }; return(Task.FromResult <EmotionScore>(res)); }
public async Task <List <EmotionScore> > GetScoresByExecutionId(int executionId) { string query = @"SELECT * FROM [emo].[EmotionScore] WHERE Id = @ExecutionId;"; List <EmotionScore> results = new List <EmotionScore>(); using (var reader = await this.ExecuteReaderAsync(query, false, "@ExecutionId", executionId)) { while (reader.Read()) { EmotionScore score = new EmotionScore(reader); results.Add(score); } } return(results); }
public void UpdateScore(EmotionScore emo) { //display the score in some way //Line.Points.Add(new DataPoint(testx++, emo.scores.happiness)); double pos = ModelUtility.ProcessScorePositive(emo); //double neg = ModelUtility.ProcessScoreNegative(emo); positive.Points.Add(new DataPoint(testx++, pos)); //negative.Points.Add(new DataPoint(testx++, neg)); if (testx >= _displaySpan) { positive.Points.RemoveAt(0); //negative.Points.RemoveAt(0); } MyModel.InvalidatePlot(true); }
public async Task <bool> FinishExecution(OrderedDictionary scores, int executionId) { //end execution string query1 = @"UPDATE [emo].[ExecutionInstance] SET EndTime = GETUTCDATE() WHERE Id = @ExecutionId;"; await ExecuteCommandAsync(query1, false, "@ExecutionId", executionId); string query2 = @"INSERT INTO [emo].[EmotionScore] (ExecutionId, Anger, Contempt, Disgust, Fear, Happiness, Neutral, Sadness, Surprise, StartTime, EndTime, TimeStamp) VALUES {0}"; List <string> values = new List <string>(); foreach (DictionaryEntry entry in scores) { string val = @"({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, '{9}', '{10}', {11})"; EmotionScore score = entry.Value as EmotionScore; val = string.Format(val, executionId, score.scores.anger, score.scores.contempt, score.scores.disgust, score.scores.fear, score.scores.happiness, score.scores.neutral, score.scores.sadness, score.scores.surprise, score.startTime, score.endTime, entry.Key); values.Add(val); } if (values.Count == 0) { return(false);; } var valuesString = String.Join(",", values); query2 = string.Format(query2, valuesString); await ExecuteCommandAsync(query2, false); return(true); }
//public async Task<List<EmotionScore>> GetScoresFilteredBy(int something) //{ // throw new NotImplementedException(); //} public async Task <List <List <EmotionScore> > > GetFullScoreHistory(VideoExecution vid) { string query = @" SELECT * FROM [emo].[EmotionScore] ES JOIN [emo].[ExecutionInstance] EI ON ES.ExecutionId = EI.Id WHERE FileName LIKE '%" + vid.FileName + @"%' ORDER BY [TimeStamp], [ExecutionId];"; List <List <EmotionScore> > results = new List <List <EmotionScore> >(); List <EmotionScore> scoreExe = null; using (var reader = await this.ExecuteReaderAsync(query, false, "@FileName", vid.FileName)) { int prevExe = 0; while (reader.Read()) { EmotionScore score = new EmotionScore(reader); if (score.executionId != prevExe) { if (prevExe != 0) { results.Add(scoreExe); } scoreExe = new List <EmotionScore>(); prevExe = score.executionId; } scoreExe.Add(score); } if (scoreExe != null && scoreExe.Count != 0) { results.Add(scoreExe); } } return(results); }
public void UpdateData(EmotionScore emo, MemoryStream cam) { Model.UpdateScore(emo); secondary.UpdateWebCamView(cam); }
public async Task StartStopExecution() { IDataLayer dbAccess = new SQLDataLayer(_connection); int vHeight = 200; int vWidth = 200; string vName = "unitTestName"; VideoExecution ve = new VideoExecution() { Height = vHeight, Width = vWidth, FileName = vName }; int executionId = await dbAccess.WithDataLayerAsync <int>(async db => await db.GetExecutionContext(ve)); var query1 = @"SELECT * FROM [emo].[ExecutionInstance] WHERE Id = @exeId;"; this.Open(); using (var reader = await ExecuteReaderAsync(query1, false, "@exeId", executionId)) { if (reader.Read()) { var fname = reader["Filename"] as string; var fwidth = Convert.ToInt32(reader["Width"]); var fheight = Convert.ToInt32(reader["Height"]); Assert.AreEqual(fname, vName); Assert.AreEqual(vHeight, fheight); Assert.AreEqual(vWidth, fwidth); } } this.Close(); double scoreValue = 0.5; DateTime now = DateTime.UtcNow; EmotionScore score = new EmotionScore() { startTime = now, endTime = now, scores = new Scores() { anger = scoreValue, contempt = scoreValue, disgust = scoreValue, fear = scoreValue, happiness = scoreValue, neutral = scoreValue, sadness = scoreValue, surprise = scoreValue }, executionId = executionId, }; OrderedDictionary od = new OrderedDictionary(); od.Add(now, score); var finish = await dbAccess.WithDataLayerAsync <bool>(async db => await db.FinishExecution(od, executionId)); Assert.AreEqual(finish, true); var query2 = @"SELECT * FROM [emo].[EmotionScore] WHERE ExecutionId = @exeId ORDER BY TimeStamp ASC;"; this.Open(); using (var reader = await this.ExecuteReaderAsync(query2, false, "@exeId", executionId)) { if (reader.Read()) { var start = Convert.ToDateTime(reader["StartTime"]); var end = Convert.ToDateTime(reader["EndTime"]); var time = Convert.ToDateTime(reader["TimeStamp"]); var angerScore = Convert.ToDouble(reader["Anger"]); Assert.AreEqual(angerScore, scoreValue); } } this.Close(); }
public void UpdateData(EmotionScore emo) { Model.PieViewModel.UpdateScore(emo); }
public void UpdateScore(EmotionScore emo) { if (MyModel.Series.Count > 0) { MyModel.Series.RemoveAt(0); } var seriesP1 = new PieSeries { StrokeThickness = 2.0, InsideLabelPosition = 0.6, AngleSpan = 360, StartAngle = 0, InsideLabelColor = OxyColors.Black, TextColor = OxyColors.DarkGray, Stroke = OxyColors.Gray }; if (emo != null) { seriesP1.Slices.Add(new PieSlice("Anger", emo.scores.anger) { IsExploded = true, Fill = OxyColors.Red }); seriesP1.Slices.Add(new PieSlice("Contempt", emo.scores.contempt) { IsExploded = true, Fill = OxyColors.MediumPurple }); seriesP1.Slices.Add(new PieSlice("Disgust", emo.scores.disgust) { IsExploded = true, Fill = OxyColors.Yellow }); seriesP1.Slices.Add(new PieSlice("Fear", emo.scores.fear) { IsExploded = true, Fill = OxyColors.Purple }); seriesP1.Slices.Add(new PieSlice("Happiness", emo.scores.happiness) { IsExploded = true, Fill = OxyColors.LightGreen }); seriesP1.Slices.Add(new PieSlice("Neutral", emo.scores.neutral) { IsExploded = true, Fill = OxyColors.SandyBrown }); seriesP1.Slices.Add(new PieSlice("Sadness", emo.scores.sadness) { IsExploded = true, Fill = OxyColors.DimGray }); seriesP1.Slices.Add(new PieSlice("Surprise", emo.scores.surprise) { IsExploded = true, Fill = OxyColors.Orange }); } else { seriesP1.Slices.Add(new PieSlice("No Data Available", 1) { IsExploded = false, Fill = OxyColors.Gray, }); } MyModel.Series.Add(seriesP1); MyModel.InvalidatePlot(true); }