public Task <bool> InsertEmotion(ModEmotion emotion)
 {
     try
     {
         _apiKeysCollection.InsertOne(emotion);
         return(Task.FromResult(true));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(Task.FromResult(false));
     }
 }
示例#2
0
        public List <ModEmotion> JsonToEmotion(string json)
        {
            dynamic jsonResponse = JsonConvert.DeserializeObject(json);

            if (jsonResponse.Count == 0)
            {
                return(null);
            }

            List <ModEmotion> responseList = new List <ModEmotion>();

            for (int i = 0; i < jsonResponse.Count; i++)
            {
                var response = jsonResponse[i];

                var face   = response["faceAttributes"];
                var faceId = response["faceId"];

                JObject emotion = face["emotion"];

                double max = double.MinValue;
                string key = string.Empty;

                foreach (var child in emotion)
                {
                    JToken val  = child.Value;
                    float  valf = (float)val;
                    if (valf > max)
                    {
                        key = child.Key;
                        max = valf;
                    }
                }

                ModEmotion modEmotion = new ModEmotion()
                {
                    Date    = DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss"),
                    Details = emotion.ToString(),
                    Emotion = key,
                    Score   = max.ToString(),
                    FaceId  = faceId
                };
                responseList.Add(modEmotion);
            }

            return(responseList);
        }