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") }
};
// GET /generatePDF
[Route("generatePDF")]
[HttpPost]
- public ActionResult GeneratePdf([FromBody] Tweet[] tweets)
+ public ActionResult GeneratePdf([FromBody] Term[] terms)
{
// check parameters
if (!ModelState.IsValid)
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);
}
}
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
- PaperSize = PaperKind.A4,
+ PaperSize = PaperKind.A4Plus,
Margins = new MarginSettings { Top = 0, Left = 0, Right = 0 },
DocumentTitle = "PDF Report",
};
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") }
};
{
// 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
{
public static class TemplateGenerator
{
- public static string GetHTMLString(Tweet[] tweets)
+ public static string GetHTMLString(Term[] terms)
{
var sb = new StringBuilder();
sb.Append(@"
</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>
# 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