File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed
Fritz.StreamTools/Services Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Text ;
4
+ using System . Threading . Tasks ;
5
+ using Fritz . StreamLib . Core ;
6
+
7
+ namespace Fritz . Chatbot . Commands
8
+ {
9
+ public class SentimentCommand : IBasicCommand
10
+ {
11
+ public string Trigger => "sentiment" ;
12
+ public string Description => "Information about the sentiment analysis features of the chat room" ;
13
+ public TimeSpan ? Cooldown => TimeSpan . FromSeconds ( 30 ) ;
14
+
15
+ public async Task Execute ( IChatService chatService , string userName , ReadOnlyMemory < char > rhs )
16
+ {
17
+
18
+ var sb = new StringBuilder ( ) ;
19
+ sb . Append ( $ "The sentiment over the last minute is { SentimentSink . Sentiment1Minute . ToString ( "00.0%" ) } percent positive ") ;
20
+ sb . Append ( ( SentimentSink . Sentiment1Minute < SentimentSink . Sentiment5Minute ) ? "and trending upward (up arrow) " : "and trending downward (down arrow) " ) ;
21
+ sb . Append ( "compared to the last five minutes " ) ;
22
+ sb . Append ( $ "The most recent messages were { ( ( SentimentSink . SentimentInstant >= 0.5 ) ? "positive" : "negative" ) } (smiley face)") ;
23
+
24
+ await chatService . SendMessageAsync ( sb . ToString ( ) ) ;
25
+
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ public class SentimentSink
10
10
11
11
public static Queue < string > RecentChatMessages { get ; } = new Queue < string > ( ) ;
12
12
13
+ public static double SentimentInstant { get ; set ; }
14
+
15
+ public static double Sentiment1Minute { get ; set ; }
16
+
17
+ public static double Sentiment5Minute { get ; set ; }
18
+
13
19
}
14
20
15
21
}
Original file line number Diff line number Diff line change @@ -85,9 +85,14 @@ public async Task Run()
85
85
86
86
var now = DateTime . Now ;
87
87
_Observations . Add ( now , ( results . Documents . Count , avgScore ) ) ;
88
- _followerClient . UpdateSentiment ( avgScore ,
89
- CalculateSentimentOverLastMinutes ( 1 ) ,
90
- CalculateSentimentOverLastMinutes ( 5 ) ,
88
+
89
+ SentimentSink . SentimentInstant = avgScore ;
90
+ SentimentSink . Sentiment1Minute = CalculateSentimentOverLastMinutes ( 1 ) ;
91
+ SentimentSink . Sentiment5Minute = CalculateSentimentOverLastMinutes ( 5 ) ;
92
+
93
+ _followerClient . UpdateSentiment ( SentimentSink . SentimentInstant ,
94
+ SentimentSink . Sentiment1Minute ,
95
+ SentimentSink . Sentiment5Minute ,
91
96
CalculateSentimentOverLastMinutes ( ) ) ;
92
97
93
98
}
You can’t perform that action at this time.
0 commit comments