public void AddFoundWordToCache(string word, EmotionData emotionData) { lock (_foundWordsLock) { _foundWords.TryAdd(word, emotionData); } }
public void PersistTweetEmotion(long tweetId, EmotionData tweetEmotion) { using (var dbConnection = new SqlConnection(_connectionString)) { var spParameters = new DynamicParameters(); spParameters.Add("@TweetId", tweetId); spParameters.Add("@Anger", tweetEmotion.Anger); spParameters.Add("@Anticipation", tweetEmotion.Anticipation); spParameters.Add("@Disgust", tweetEmotion.Disgust); spParameters.Add("@Fear", tweetEmotion.Fear); spParameters.Add("@Joy", tweetEmotion.Joy); spParameters.Add("@Negative", tweetEmotion.Negative); spParameters.Add("@Positive", tweetEmotion.Positive); spParameters.Add("@Sadness", tweetEmotion.Sadness); spParameters.Add("@Surprise", tweetEmotion.Surprise); spParameters.Add("@Trust", tweetEmotion.Trust); try { dbConnection.Execute("[v1].[PersistTweetSentiment]", spParameters, commandType: CommandType.StoredProcedure); } catch (SqlException e) when(e.Number == 2627) { _log.Warn($"Tweet with Id: {tweetId} has already been analysed & persisted."); } } }
private void OnGetEmotions(EmotionData emotions, string data) { if (emotions != null) { Log.Debug("ExampleAlchemyLanguage", "status: {0}", emotions.status); Log.Debug("ExampleAlchemyLanguage", "url: {0}", emotions.url); Log.Debug("ExampleAlchemyLanguage", "language: {0}", emotions.language); Log.Debug("ExampleAlchemyLanguage", "text: {0}", emotions.text); if (emotions.docEmotions == null) { Log.Debug("ExampleAlchemyLanguage", "No emotions found!"); } else { Log.Debug("ExampleAlchemyLanguage", "anger: {0}", emotions.docEmotions.anger); Log.Debug("ExampleAlchemyLanguage", "disgust: {0}", emotions.docEmotions.disgust); Log.Debug("ExampleAlchemyLanguage", "fear: {0}", emotions.docEmotions.fear); Log.Debug("ExampleAlchemyLanguage", "joy: {0}", emotions.docEmotions.joy); Log.Debug("ExampleAlchemyLanguage", "sadness: {0}", emotions.docEmotions.sadness); } } else { Log.Debug("ExampleAlchemyLanguage", "Failed to find Emotions!"); } }
private async void OnEmotionDataReceived(EmotionData data) => await WardAsync(async() => { await TelemetryService.Default.SendAsync(data); Emotion = data.Emotion; EmotionTimestamp = data.Timestamp; }, "Error sending emotion to telemetry service!");
public void UpdateEmotion(EmotionScores scores) { EmotionData topEmotion = EmotionServiceHelper.ScoresToEmotionData(scores).OrderByDescending(d => d.EmotionScore).First(); this.filledBar.Background = this.emotionToColorMapping[topEmotion.EmotionName]; this.emptySpaceRowDefinition.Height = new GridLength(1 - topEmotion.EmotionScore, Windows.UI.Xaml.GridUnitType.Star); this.filledSpaceRowDefinition.Height = new GridLength(topEmotion.EmotionScore, Windows.UI.Xaml.GridUnitType.Star); }
// This is the evaluated result of the sum of a set of gaussians. public EmotionSpectrum(EmotionData gaussians) { for (int i = 0; i < SAMPLE_COUNT; ++i) { float t = i / (float)SAMPLE_COUNT; samples[i] = gaussians.Evaluate(t * 2f * Mathf.PI); } }
private void FaceRectangleControl_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { DataContextChanged -= FaceRectangleControl_DataContextChanged; Unloaded -= FaceRectangleControl_Unloaded; PointerEntered -= FaceRectangleControl_PointerEntered; PointerExited -= FaceRectangleControl_PointerExited; emotionData = null; }
public static EmotionData get() { if (this._data == null) { this._data = new EmotionData(); } return(_data); }
/// <summary> /// 显示情绪数值 /// </summary> /// <param name="data"></param> void showEmotionData(EmotionData data) { Happiness.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Happiness, 2) }); Surprise.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Surprise, 2) }); Contempt.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Contempt, 2) }); Anger.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Anger, 2) }); Disgust.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Disgust, 2) }); Fear.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Fear, 2) }); Neutral.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Neutral, 2) }); Sadness.Values = new ChartValues <double>(new double[] { Math.Round(100 * data.Sadness, 2) }); }
public void UpdateEmotion(EmotionScores scores) { EmotionData topEmotion = EmotionServiceHelper.ScoresToEmotionData(scores).OrderByDescending(d => d.EmotionScore).First(); string label = "", emoji = ""; switch (topEmotion.EmotionName) { case "Anger": label = "Angry"; emoji = "\U0001f620"; break; case "Contempt": label = "Contemptuous"; emoji = "\U0001f612"; break; case "Disgust": label = "Disgusted"; emoji = "\U0001f627"; break; case "Fear": label = "Afraid"; emoji = "\U0001f628"; break; case "Happiness": label = "Happy"; emoji = "\U0001f60a"; break; case "Neutral": label = "Neutral"; emoji = "\U0001f614"; break; case "Sadness": label = "Sad"; emoji = "\U0001f622"; break; case "Surprise": label = "Surprised"; emoji = "\U0001f632"; break; default: break; } this.emotionEmoji.Text = emoji; this.emotionText.Text = label; }
private void RecieveEmotion(TCPMessageType tcpMessageType, object messageObj) { global::Debug.Log("Emotion: 受信"); EmotionData emotionData = TCPData <EmotionData> .Convert(messageObj); string spriteName = emotionData.spriteName; int iconSpritesIndex = emotionData.iconSpritesIndex; bool isOther = true; base.stateManager.uiControlPvP.ShowEmotion(iconSpritesIndex, spriteName, isOther); }
// This is the evaluated result of a single gaussian public EmotionSpectrum(EmotionVector vector) { EmotionData gaussians = new EmotionData(); gaussians.AddVector(vector); for (int i = 0; i < SAMPLE_COUNT; ++i) { float t = i / (float)SAMPLE_COUNT; samples[i] = gaussians.Evaluate(t * 2f * Mathf.PI); } }
public static string ToString(this EmotionData emotionData) { var str = new StringBuilder(); var properties = typeof(EmotionData).GetProperties(); foreach (var property in properties) { var propertyValue = (float)property.GetValue(emotionData); str.Append($"{property.Name}: {propertyValue}"); } return(str.ToString()); }
// Affective reaction should run for the wave time, at least once per game. public void runAffectiveReaction(int waveIndex, bool lastWave) { if (waveIndex < emotionMinimumWave) { Debug.Log("Reaction cannot occur that early"); return; } Debug.Log("Emotion update"); lastEmotionData = TCPServer.Emotion; //lastEmotionData = new EmotionData(); //lastEmotionData.heartBeat = 75; //lastEmotionData.emotionType = Emotions.STRESSED.ToString(); //lastEmotionData.certainty = 82; if (lastEmotionData == null) { Debug.Log("No emotion data yet. Returning."); return; } float chance = Random.Range(0.0f, 1.0f); Debug.Log("Chance of reaction: " + chance); if (chance > affectiveReactionChance && !lastWave) { Debug.Log("Chance above: " + affectiveReactionChance + ", applying FOCUS..."); applyFocusReaction(); affectiveReactionTriggered = false; return; } Debug.Log("Running affective reaction!"); affectiveReactionTriggered = true; lastReactionEmotion = lastEmotionData; if (isBored()) { Debug.Log("Applying STRESS..."); applyStressorReaction(); } else if (isFocused()) { Debug.Log("Applying FOCUS..."); applyFocusReaction(); } else if (isStressed()) { Debug.Log("Applying CALM..."); applyCalmReaction(); } }
public static void Invert(this EmotionData emotionData) { var properties = typeof(EmotionData).GetProperties(); foreach (var property in properties) { var propertyValue = (float)property.GetValue(emotionData); if (propertyValue > 0.5) { property.SetValue(emotionData, 1 - propertyValue); } } }
void PopulateList(List <EmotionData.EmotionStruct> list, EmotionData emotionData) { // Add structs to list of structs from emotionData // emotionData contains a struct with MonsterEmotions emotion, Sprite sprite, and AudioClip clipOfEmotion list.Add(emotionData.afraid); list.Add(emotionData.disgusted); list.Add(emotionData.happy); list.Add(emotionData.joyous); list.Add(emotionData.mad); list.Add(emotionData.sad); list.Add(emotionData.thoughtful); list.Add(emotionData.worried); }
private async Task ShareEmotion(EmotionData Data) { Chart chart = new BarChart(); chart = DayChart as BarChart; chart.IsAnimated = false; chart.Margin = 20; chart.LabelColor = SKColors.Purple; var bmp = new SKBitmap(500, 500); var canvas = new SKCanvas(bmp); var image = SKImage.FromPixels(bmp.PeekPixels()); chart.DrawContent(canvas, 500, 500); canvas.Save(); using (MemoryStream ms = new MemoryStream()) { image.Encode(SKEncodedImageFormat.Png, 4).AsStream().CopyTo(ms); var str = Convert.ToBase64String(ms.ToArray()); bytes = Convert.FromBase64String(str); } try { PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage); if (status != PermissionStatus.Granted) { var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage }); status = results[Permission.Storage]; } if (status != PermissionStatus.Granted) { return; } else { DependencyService.Get <IShare>() .ShareContent("", "AboutSelf", ImageSource.FromStream(() => new MemoryStream(bytes))); } } catch (Exception ex) { Debug.WriteLine(ex); } }
/// <summary> /// Starts capturing an image from the front camera, making webrequests /// </summary> /// <returns></returns> IEnumerator emotionCall() { bool running = true; while (running) { yield return(new WaitForSeconds(2)); if (!backCam.isPlaying) { running = false; _ShowAndroidToastMessage("Earl encountered a problem connecting to the front camera. Please restart the app."); Invoke("DoQuit", 1f); } byte[] bytes = generateBytes(); UnityWebRequest www = generateRequest(bytes); using (www) { yield return(www.SendWebRequest()); string downloadedJson = www.downloadHandler.text; if (www.isNetworkError) { Debug.Log("A network error occured"); } else if (verifyJSON(downloadedJson)) { string response = generateResponse(EmotionData.FromJson(downloadedJson)); curEmote = response; responseText.text = ("You look " + response + " about "); AddEmotionText(response);//Add text to the Emotion Panel getClassification(); if (response == "sad") { var eAndy = GameObject.Find("andyObject"); if (eAndy != null) { Animator anim = eAndy.GetComponent <Animator>(); anim.SetBool("isSad", true); anim.Play("Sad"); anim.SetBool("isSad", false); } } } } var emotes = ds.getEmotions(); ds.ePrintData(emotes); yield return(new WaitForSeconds(emoteLoopTime)); } }
public static EmotionData GetOverallEmotion(this IEnumerable <EmotionData> emotions) { var overallEmotion = new EmotionData(); foreach (var emotion in emotions) { var properties = typeof(EmotionData).GetProperties(); foreach (var property in properties) { property.SetValue(overallEmotion, (float)property.GetValue(overallEmotion) + (float)property.GetValue(emotion), null); } } return(overallEmotion); }
public void SetEmotion(EmotionType emotion) { if (this.currentEmotion != null) { if (this.currentEmotion.emotionData.emotionType == emotion) { // don't play again return; } // disable current this.currentEmotion.emotionData.SetActive(false, this.audioSource, this.spriteRenderer); } // enable new EmotionData data = this.emotionData.First(e => e.emotionType == emotion); this.currentEmotion = new PlayedEmotion(data); this.currentEmotion.emotionData.SetActive(true, this.audioSource, this.spriteRenderer); }
internal static pxcmStatus QueryAllEmotionDataINT(IntPtr emotion, Int32 fid, out EmotionData[] data) { Int32 data_size = PXCMEmotion_QueryEmotionSize(emotion); IntPtr data2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(EmotionData)) * data_size); pxcmStatus sts = PXCMEmotion_QueryAllEmotionData(emotion, fid, data2); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { data = new EmotionData[data_size]; for (int i = 0; i < data.Length; i++) { data[i] = new EmotionData(); Marshal.PtrToStructure(new IntPtr(data2.ToInt64() + i * Marshal.SizeOf(typeof(EmotionData))), data[i]); } } else { data = null; } Marshal.FreeHGlobal(data2); return sts; }
public bool TryGetEmotionFromDatabase(string word, out EmotionData emotionData) { List <EmotionData> resultList; using (var dbConnection = new SqlConnection(_connectionString)) { var spParameters = new DynamicParameters(); spParameters.Add("@Word", word); resultList = dbConnection.Query <EmotionData>("[dbo].[GetSentimentFromWord]", spParameters, commandType: CommandType.StoredProcedure).ToList(); } if (resultList.Count != 0) { emotionData = resultList.FirstOrDefault(); return(true); } else { emotionData = null; return(false); } }
private EmotionData MonthlyEmotions() { string connectionString = DependencyService.Get <IDataBaseAccess>().DataBasePath(); using (var db = new LiteDatabase(connectionString)) { var collection = db.GetCollection <Emotion>("emotions"); EmotionData emotionData = new EmotionData { Joy = collection.Count(x => x.Feeling == "joy" && x.Time.Month == DateTime.Now.Month && x.Time.Year == DateTime.Now.Year), Anger = collection.Count(x => x.Feeling == "anger" && x.Time.Month == DateTime.Now.Month && x.Time.Year == DateTime.Now.Year), Disgust = collection.Count(x => x.Feeling == "disgust" && x.Time.Month == DateTime.Now.Month && x.Time.Year == DateTime.Now.Year), Contempt = collection.Count(x => x.Feeling == "contempt" && x.Time.Month == DateTime.Now.Month && x.Time.Year == DateTime.Now.Year), Sadness = collection.Count(x => x.Feeling == "sadness" && x.Time.Month == DateTime.Now.Month && x.Time.Year == DateTime.Now.Year), Fear = collection.Count(x => x.Feeling == "fear" && x.Time.Month == DateTime.Now.Month && x.Time.Year == DateTime.Now.Year), Surprise = collection.Count(x => x.Feeling == "surprise" && x.Time.Month == DateTime.Now.Month && x.Time.Year == DateTime.Now.Year) }; return(emotionData); } }
internal static pxcmStatus QueryAllEmotionDataINT(IntPtr emotion, Int32 fid, out EmotionData[] data) { Int32 data_size = PXCMEmotion_QueryEmotionSize(emotion); IntPtr data2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(EmotionData)) * data_size); pxcmStatus sts = PXCMEmotion_QueryAllEmotionData(emotion, fid, data2); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { data = new EmotionData[data_size]; for (int i = 0; i < data.Length; i++) { data[i] = new EmotionData(); Marshal.PtrToStructure(new IntPtr(data2.ToInt64() + i * Marshal.SizeOf(typeof(EmotionData))), data[i]); } } else { data = null; } Marshal.FreeHGlobal(data2); return(sts); }
public bool TryGetWordFromCache(string word, out EmotionData emotionData) { emotionData = null; lock (_foundWords) { if (_foundWords.ContainsKey(word)) { emotionData = _foundWords[word].CloneJson(); return(true); } } lock (_unfoundWordsLock) { if (_unfoundWords.Contains(word)) { return(true); } } return(false); }
public void SendEmotion(UIButton button) { int index = 0; int iconSpritesIndex = 1; UITexture componentInChildren = button.transform.GetComponentInChildren <UITexture>(); if (componentInChildren == null) { return; } string name = componentInChildren.mainTexture.name; base.stateManager.uiControlPvP.ShowEmotion(index, name, false); SoundPlayer.PlayButtonEnter(); EmotionData message = new EmotionData { playerUserId = ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId, hashValue = Singleton <TCPUtil> .Instance.CreateHash(TCPMessageType.Emotion, ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId, TCPMessageType.None), spriteName = name, iconSpritesIndex = iconSpritesIndex }; base.SendMessageForSync(TCPMessageType.Emotion, message); }
void networkCode() { string data; // Data buffer for incoming data. byte[] bytes = new Byte[1024]; listener = new TcpListener(IPAddress.Any, 11000); try { listener.Start(); // Start listening for connections. while (keepWaiting) { // Program is suspended while waiting for an incoming connection. Debug.Log("Waiting for Connection"); handler = handler != null ? handler : listener.AcceptSocket(); Debug.Log("Connection established"); connectionEstablished = true; data = null; // An incoming connection needs to be processed. while (keepReading) { bytes = new byte[1024]; int bytesRec = handler.Receive(bytes); if (bytesRec <= 0) { keepReading = false; handler.Disconnect(true); break; } // TODO: HACK - Why 1 byte is broken? I should start from 0! data += Encoding.UTF8.GetString(bytes, 1, bytesRec); if (data.IndexOf("heartBeat") > -1) { break; } System.Threading.Thread.Sleep(100); } //Debug.Log("Original Data: " + data); String formattedData = Regex.Replace(data, "[^0-9a-zA-Z{}\",:]+", ""); if (formattedData.Substring(0, 1).Equals("\"")) { formattedData = formattedData.Remove(0, 1); } formattedData = ExtractJSON(formattedData); //Debug.Log("Formatted Data: " + formattedData); try { Emotion = JsonUtility.FromJson <EmotionData>(formattedData); } catch (Exception _e) { Debug.Log("Parsing error. Using last emotion."); } //Debug.Log("Data: " + Emotion); System.Threading.Thread.Sleep(100); } } catch (Exception e) { Debug.Log(e.ToString()); } }
internal static pxcmStatus QueryEmotionDataINT(IntPtr emotion, Int32 fid, Emotion eid, out EmotionData data) { data = new EmotionData(); return PXCMEmotion_QueryEmotionData(emotion, fid, eid, data); }
/// Get Emotion data of the specified face and emotion. /// fid The face ID, zero-based /// eid The emotion identifier /// data The EmotionData data structure, to be returned public pxcmStatus QueryEmotionData(Int32 fid, Emotion eid, out EmotionData data) { return QueryEmotionDataINT(instance, fid, eid, out data); }
/// Get all Emotion data of a specified face. /// fid The face ID, zero-based /// data The array of EmotionData data structures, to be returned public pxcmStatus QueryAllEmotionData(Int32 fid, out EmotionData[] data) { return QueryAllEmotionDataINT(instance, fid, out data); }
private void MainCanvas_Tapped(object sender, TappedRoutedEventArgs e) { if (emotions == null) { return; } double canvas_w = MainCanvas.ActualWidth; double canvas_h = MainCanvas.ActualHeight; double image_w = MainImage.ActualWidth; double image_h = MainImage.ActualHeight; double p = MainImage.ActualWidth / size_image.Width; double offset_canvas_x = (canvas_w - image_w) / 2; double offset_canvas_y = (canvas_h - image_h) / 2; int index = 0; //为了上传对应的face数据 foreach (var emotion in emotions) { index++; double offset_image_x = emotion.FaceRectangle.Left * p; double offset_image_y = emotion.FaceRectangle.Top * p; Rect rect = new Rect(); //矩形的宽高 rect.Width = emotion.FaceRectangle.Width * p + offset_image_x; rect.Height = emotion.FaceRectangle.Height * p + offset_image_y; //矩形的起始位置=canvas上的偏移量+image上的偏移量 rect.X = offset_canvas_x; rect.Y = offset_canvas_y; Point point = e.GetPosition(MainCanvas); if (rect.Contains(point)) { EmotionData data = new EmotionData() { Anger = emotion.Scores.Anger, Contempt = emotion.Scores.Contempt, Disgust = emotion.Scores.Disgust, Fear = emotion.Scores.Fear, Happiness = emotion.Scores.Happiness, Neutral = emotion.Scores.Neutral, Sadness = emotion.Scores.Sadness, Surprise = emotion.Scores.Surprise }; if (index > faceDatas.Count) { break; } EmotionDataPage edc = new EmotionDataPage(data, faceDatas[index]); edc.Width = MainCanvas.ActualWidth * 2 / 5; edc.Height = MainCanvas.ActualHeight / 2; EmotionPop.Child = edc; EmotionPop.VerticalOffset = point.Y; EmotionPop.HorizontalOffset = MainCanvas.ActualWidth / 8; EmotionPop.IsOpen = true; break; } } //if (emotions != null) //{ // var offset_h = 0.0; var offset_w = 0.0; // var p = 0.0; // var d = MainCanvas.ActualHeight / MainCanvas.ActualWidth; // var d2 = size_image.Height / size_image.Width; // if (d < d2) // { // offset_h = 0; // offset_w = (MainCanvas.ActualWidth - MainCanvas.ActualHeight / d2) / 2; // p = MainCanvas.ActualHeight / size_image.Height; // } // else // { // offset_w = 0; // offset_h = (MainCanvas.ActualHeight - MainCanvas.ActualWidth / d2) / 2; // p = MainCanvas.ActualWidth / size_image.Width; // } // foreach (var emotion in emotions) // { // Rect rect = new Rect(); // rect.Width = emotion.FaceRectangle.Width * p; // rect.Height = emotion.FaceRectangle.Height * p; // rect.X = emotion.FaceRectangle.Left * p + offset_w; // rect.Y = emotion.FaceRectangle.Top * p + offset_h; // Point point = e.GetPosition(MainCanvas); // if (rect.Contains(point)) // { // EmotionData data = new EmotionData() // { // Anger = emotion.Scores.Anger, // Contempt = emotion.Scores.Contempt, // Disgust = emotion.Scores.Disgust, // Fear = emotion.Scores.Fear, // Happiness = emotion.Scores.Happiness, // Neutral = emotion.Scores.Neutral, // Sadness = emotion.Scores.Sadness, // Surprise = emotion.Scores.Surprise // }; // EmotionDataPage edc = new EmotionDataPage(data); // edc.Width = MainCanvas.ActualWidth * 2 / 5; // edc.Height = MainCanvas.ActualHeight / 2; // EmotionPop.Child = edc; // EmotionPop.VerticalOffset = point.Y; // EmotionPop.HorizontalOffset = MainCanvas.ActualWidth / 8; // EmotionPop.IsOpen = true; // break; // } // } //} }
public void OnEmotionChanged(EmotionData obj) { mouth.sprite = obj.mouth; AudioController.instance.Play(obj.onChangeSound); }
public EmotionDataPage(EmotionData data) { this.InitializeComponent(); showEmotionData(data); }
public EmotionDataPage(EmotionData data, FaceData face) { this.InitializeComponent(); showFaceData(face); showEmotionData(data); }