From 9b2ff8f7959b0f1373b29acffd6a06f3b8fc9ba8 Mon Sep 17 00:00:00 2001 From: "aic.eichhorner.1227328" Date: Fri, 23 Nov 2018 14:48:20 +0100 Subject: [PATCH] Changed parameter to double and added progress bar --- .../Controllers/PdfController.cs | 22 +++++++++--------- .../Models/{Tweet.cs => Term.cs} | 6 ++--- .../Utility/TemplateGenerator.cs | 23 ++++++++++++------- service-reporting/readme.md | 8 +++---- 4 files changed, 33 insertions(+), 26 deletions(-) rename service-reporting/Models/{Tweet.cs => Term.cs} (69%) diff --git a/service-reporting/Controllers/PdfController.cs b/service-reporting/Controllers/PdfController.cs index a47cbb1..9125067 100644 --- a/service-reporting/Controllers/PdfController.cs +++ b/service-reporting/Controllers/PdfController.cs @@ -34,11 +34,11 @@ namespace PdfService.Controllers var objectSettings = new ObjectSettings { PagesCount = true, - HtmlContent = TemplateGenerator.GetHTMLString(new Tweet[]{ - new Tweet("Test", "Good"), - new Tweet("Test2", "Bad"), - new Tweet("Another Tweet", "Bad"), - new Tweet("Another bad Tweet", "Bad") + HtmlContent = TemplateGenerator.GetHTMLString(new Term[]{ + new Term("Good Term", 0.9), + new Term("Term 1", 0.5), + new Term("Another Term", 0.3), + new Term("Another bad Tweet", 0.1) }), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "bulma.min.css") } }; @@ -56,7 +56,7 @@ namespace PdfService.Controllers // GET /generatePDF [Route("generatePDF")] [HttpPost] - public ActionResult GeneratePdf([FromBody] Tweet[] tweets) + public ActionResult GeneratePdf([FromBody] Term[] terms) { // check parameters if (!ModelState.IsValid) @@ -64,9 +64,9 @@ namespace PdfService.Controllers return BadRequest(ModelState); } - // check for emptyString - foreach(Tweet tweet in tweets) { - if(tweet.Name.Length<1 || tweet.Sentiment.Length<1){ + // check parameter if they have correct form + foreach(Term term in terms) { + if(term.Name.Length<1 || term.Sentiment<0.0 || term.Sentiment>1.0){ return BadRequest(ModelState); } } @@ -75,7 +75,7 @@ namespace PdfService.Controllers { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, - PaperSize = PaperKind.A4, + PaperSize = PaperKind.A4Plus, Margins = new MarginSettings { Top = 0, Left = 0, Right = 0 }, DocumentTitle = "PDF Report", }; @@ -83,7 +83,7 @@ namespace PdfService.Controllers var objectSettings = new ObjectSettings { PagesCount = true, - HtmlContent = TemplateGenerator.GetHTMLString(tweets), + HtmlContent = TemplateGenerator.GetHTMLString(terms), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "bulma.min.css") } }; diff --git a/service-reporting/Models/Tweet.cs b/service-reporting/Models/Term.cs similarity index 69% rename from service-reporting/Models/Tweet.cs rename to service-reporting/Models/Term.cs index 6889d14..bb62890 100644 --- a/service-reporting/Models/Tweet.cs +++ b/service-reporting/Models/Term.cs @@ -3,13 +3,13 @@ namespace PdfService.Models { // represents the data got from sentiment analysis. // TODO: adapt to real data from sentiment analysis - public class Tweet + public class Term { - public Tweet(string Name, string Sentiment) { + public Term(string Name, double Sentiment) { this.Name = Name; this.Sentiment = Sentiment; } public string Name { get; set; } - public string Sentiment { get; set; } + public double Sentiment { get; set; } } } \ No newline at end of file diff --git a/service-reporting/Utility/TemplateGenerator.cs b/service-reporting/Utility/TemplateGenerator.cs index fa2ff9f..5a71273 100644 --- a/service-reporting/Utility/TemplateGenerator.cs +++ b/service-reporting/Utility/TemplateGenerator.cs @@ -5,7 +5,7 @@ namespace PdfService.Utility { public static class TemplateGenerator { - public static string GetHTMLString(Tweet[] tweets) + public static string GetHTMLString(Term[] terms) { var sb = new StringBuilder(); sb.Append(@" @@ -25,21 +25,28 @@ namespace PdfService.Utility -
- Generated report only contains mocked data. Will be changed later. -
-
+
"); - foreach (var tweet in tweets) + foreach (Term term in terms) { + string color = ""; + if(term.Sentiment < 0.33) + color = "is-danger"; + else if(term.Sentiment < 0.66) + color = "is-warning"; + else + color = "is-success"; + sb.AppendFormat(@"

{0}

- {1} + Sentiment Analysis Result: +
{1}%
+
-
", tweet.Name, tweet.Sentiment); +
", term.Name, System.Math.Ceiling(term.Sentiment*100), color); } sb.Append(@"
diff --git a/service-reporting/readme.md b/service-reporting/readme.md index 4e70534..8530277 100644 --- a/service-reporting/readme.md +++ b/service-reporting/readme.md @@ -1,17 +1,17 @@ # PDF Service -Provides an API interface to generate PDF reports for tweets and their sentiment analysis results. The service uses an .NET Core wrapper for the wkhtmltopdf library to generate pdf out of html code. +Provides an API interface to generate PDF reports for terms and their sentiment analysis results. The service uses an .NET Core wrapper for the wkhtmltopdf library to generate pdf out of html code. `GET`: `/` Shows a demo page - param: none - return: pdf file -`POST`: `/generatePDF/` Generates a pdf report for the given tweets -- param: Tweet[] as Content-Type: `application/json` +`POST`: `/generatePDF/` Generates a pdf report for the given terms +- param: Term[] as Content-Type: `application/json` - return: pdf file ### Tweet model -Tweet(string `Name`, string `Sentiment`) +Term(string `Name`, float `Sentiment`) ## run with docker -- 2.43.0