Changed parameter to double and added progress bar
authoraic.eichhorner.1227328 <e1227328@student.tuwien.ac.at>
Fri, 23 Nov 2018 13:48:20 +0000 (14:48 +0100)
committeraic.eichhorner.1227328 <e1227328@student.tuwien.ac.at>
Fri, 23 Nov 2018 13:48:20 +0000 (14:48 +0100)
service-reporting/Controllers/PdfController.cs
service-reporting/Models/Term.cs [moved from service-reporting/Models/Tweet.cs with 69% similarity]
service-reporting/Utility/TemplateGenerator.cs
service-reporting/readme.md

index a47cbb1281898a0aca5a8390b6b496ac8e8bea86..912506740b59be169dbe0e5da384389288aa779d 100644 (file)
@@ -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") }
             };
  
similarity index 69%
rename from service-reporting/Models/Tweet.cs
rename to service-reporting/Models/Term.cs
index 6889d1453297de3c5d89479e4374381af0c4312d..bb6289036aa49bfa77c966bd8bc63d8120de2461 100644 (file)
@@ -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
index fa2ff9f0660fc6bab52f4694ce7ae3fec446ca37..5a7127399f646661aaf375b1ebddf2138f52dde9 100644 (file)
@@ -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
                                     </div>
                                 </div>
                                 </section>
-                                <div class='notification'>
-                                    Generated report only contains mocked data. Will be changed later.
-                                </div> 
-                                <div class='container' style='margin-left:3em'>
+                                <div class='container' style='margin-left:3em; margin-right:3em'>
 
                                 ");
  
-            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(@"<div class='container' style='margin-top:3em;'>  
                             <p class='title is-5'>{0}</p>
                     <div class='content'>
-                    {1}
+                    Sentiment Analysis Result:
+                        <div class='column'><progress class='progress {2}' value='{1}' max='100'>{1}%</progress></div>
+                    
                     </div>
-                </div>", tweet.Name, tweet.Sentiment);
+                </div>", term.Name, System.Math.Ceiling(term.Sentiment*100), color);
             }
  
             sb.Append(@" </div>
index 4e70534d72ab73128e01e045870330de2b8a5dbc..8530277787f01ee0cca264e883ab3b7bd423d5b7 100644 (file)
@@ -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