2 using PdfService.Models;
6 using System.Collections.Generic;
8 namespace PdfService.Utility
10 public static class TemplateGenerator
12 // calculates standard deviation for list
13 // from: https://stackoverflow.com/questions/3141692/standard-deviation-of-generic-list
14 private static float CalculateStdDev(IEnumerable<double> values)
17 if (values.Count() > 0)
20 double avg = values.Average();
21 //Perform the Sum of (value-avg)_2_2
22 double sum = values.Sum(d => Math.Pow(d - avg, 2));
24 ret = Math.Sqrt((sum) / (values.Count()-1));
29 public static string GetHTMLString(Term[] terms)
31 var sb = new StringBuilder();
32 sb.AppendFormat(@"<!doctype html>
35 <meta charset='utf-8'>
36 <meta name='viewport' content='initial-scale=1.0, user-scalable=no' />
39 <section class='hero is-info' style='padding: 3em 3em 0em 3em;'>
40 <div class='hero-body'>
41 <div class='container'>
43 Sentiment Analysis - Advanced Report
50 <div class='notification is-info' style='padding-left:5em; padding-right:5em'>
51 <table style='padding-left:2em'>
54 <img src='{6}' style='height:2em; width: auto;padding-right:2em;'/>
55 <img src='{5}' style='height:2em; width: auto;padding-right:2em;'/>
60 <div class='container' style='padding-left:5em; padding-right:5em'>
62 <h1 class='subtitle is-3'>Overall statistics</h1>
63 Amount of terms: <strong>{1}</strong><br/>
64 Mean sentiment value: <strong>{2:0.00}</strong><br/>
65 Standard deviation: <strong>{3:0.00}</strong><br/>
66 Date: <strong>{4}</strong><br/>
68 <h1 class='subtitle is-3'>Detail results:</h1>
70 <div class='notification'>
72 <span class='tag is-link is-danger' style='margin-right:0.5em'></span> Negative Sentiment Value: <strong>0-0.4</strong><br/>
73 <span class='tag is-link is-warning'style='margin-right:0.5em'></span> Neutral Sentiment Value: <strong>0.4-0.6</strong><br/>
74 <span class='tag is-link is-success'style='margin-right:0.5em'></span> Positive Sentiment Value: <strong>0.6-1.0</strong><br/>
77 ", terms.Select(i => i.Name).Aggregate((i, j) => i + ',' + ' ' + j),
79 terms.Select(i => i.Sentiment).Average(),
80 CalculateStdDev(terms.Select(i => (double)i.Sentiment)),
82 Path.Combine(Directory.GetCurrentDirectory(), "assets", "indico.png"),
83 Path.Combine(Directory.GetCurrentDirectory(), "assets", "twitter.png"));
85 foreach (Term term in terms)
88 if(term.Sentiment < 0.40)
90 else if(term.Sentiment < 0.60)
95 sb.AppendFormat(@"<div class='container' style='margin-top:3em;'>
96 <p class='subtitle is-4'>{0}</p>
97 <p style='margin-top:-1.0em; margin-left: 2em;'>Calculated sentiment: {3:0.00}</p> <br/>
98 <table class='table' style='width:100%; border: 0; margin-left: 2em;'>
100 <td style='width:2em;border: 0; box-shadow: none;padding-right:0.5em'>
101 <figure class='image is-16x16'>
104 <td valign='center' style='width:20em;border: 0; box-shadow: none;'><progress class='progress {2}' value='{1}' max='100'>{1}%</progress></td>
105 <td style='border: 0; box-shadow: none;padding-left:0.5em'><figure class='image is-16x16'>
111 </div>", term.Name, System.Math.Ceiling(term.Sentiment*100), color, term.Sentiment,
112 Path.Combine(Directory.GetCurrentDirectory(), "assets", "thumbs_down.png"),
113 Path.Combine(Directory.GetCurrentDirectory(), "assets", "thumbs_up.png"));
119 return sb.ToString();