From 56e6abd6e9885809d6bac03342d7a06a2b46d7d9 Mon Sep 17 00:00:00 2001 From: Marcin Badurowicz Date: Fri, 3 Jan 2020 13:59:04 +0100 Subject: [PATCH 1/3] Add logging in that text the post problem was found --- src/PostAnalyzer.cs | 3 ++- src/PostProblems.cs | 3 ++- test/PostAnalyzerTests.cs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/PostAnalyzer.cs b/src/PostAnalyzer.cs index 811bda3..2cbe137 100644 --- a/src/PostAnalyzer.cs +++ b/src/PostAnalyzer.cs @@ -31,6 +31,7 @@ using Eleia.ML; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Linq; @@ -85,7 +86,7 @@ private NotFormattedCodeFound CheckForUnformattedCode(CoyoteApi.Post post) if (result.Prediction && result.Probability > codeDetectorTreshold) { - return new NotFormattedCodeFound { Probability = result.Probability }; + return new NotFormattedCodeFound { Probability = result.Probability, Paragraph = para }; } } diff --git a/src/PostProblems.cs b/src/PostProblems.cs index 286258e..aed62d1 100644 --- a/src/PostProblems.cs +++ b/src/PostProblems.cs @@ -38,6 +38,7 @@ namespace Eleia public abstract class PostProblems { public float Probability { get; set; } + public string Paragraph { get; set; } } /// @@ -47,7 +48,7 @@ public class NotFormattedCodeFound : PostProblems { public override string ToString() { - return $"Potentially not formatted code found (prob: {Probability})"; + return $"Potentially not formatted code found (prob: {Probability}) in: {Paragraph}"; } } } \ No newline at end of file diff --git a/test/PostAnalyzerTests.cs b/test/PostAnalyzerTests.cs index 306261d..c6d71dd 100644 --- a/test/PostAnalyzerTests.cs +++ b/test/PostAnalyzerTests.cs @@ -119,9 +119,10 @@ public void Analyze_PostWithUnformattedCodeThreshold097_UnformattedCodeFound() [Fact] public void NotFormattedCodeFoundToString_WithValue_ShouldReturnProbabilityInText() { - var pp = new NotFormattedCodeFound { Probability = 0.123f }; + var pp = new NotFormattedCodeFound { Probability = 0.123f, Paragraph = "lorem" }; Assert.Contains("123", pp.ToString()); + Assert.Contains("lorem", pp.ToString()); } } } \ No newline at end of file From 534f6c9ecba9b20b98e91f5862f31b26bc199832 Mon Sep 17 00:00:00 2001 From: Marcin Badurowicz Date: Fri, 3 Jan 2020 14:03:16 +0100 Subject: [PATCH 2/3] Remove showing post's text in the log --- src/Bot.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bot.cs b/src/Bot.cs index c1b2b6f..a65e14d 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -184,7 +184,7 @@ public async Task AnalyzePostAsync(Post post) if (problems.Count > 0) { - logger.LogInformation("Found problems in post {0}\n{1}\n{2}", post.id, post.url, post.text.Length < 50 ? post.text : post.text.Substring(0, 50)); + logger.LogInformation("Found problems in post {0}\n{1}", post.id, post.url); foreach (var item in problems) { logger.LogDebug(item.ToString()); From bf7b79384265afd4b705bfb7d361b8144ed40d69 Mon Sep 17 00:00:00 2001 From: Marcin Badurowicz Date: Fri, 3 Jan 2020 14:05:16 +0100 Subject: [PATCH 3/3] Fix not showing post URL when single post was analyzed --- src/CoyoteApi/CoyoteHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CoyoteApi/CoyoteHandler.cs b/src/CoyoteApi/CoyoteHandler.cs index caaefcb..967bd15 100644 --- a/src/CoyoteApi/CoyoteHandler.cs +++ b/src/CoyoteApi/CoyoteHandler.cs @@ -179,7 +179,8 @@ public async Task GetSinglePost(int postId) text = result.data.text, topic_id = result.data.topic_id, user = result.data.user, - user_name = result.data.user_name + user_name = result.data.user_name, + url = result.data.url }; return post;