adding sinceDate

This commit is contained in:
Andrew Davidson 2015-05-09 21:34:29 -04:00
parent 3ec4b4a790
commit 5598b2f615
2 changed files with 41 additions and 13 deletions

View file

@ -21,11 +21,13 @@
<div id="weeklyLineInfo"></div>
<div class="monthlyInfo">
<h3>Last 30 Days</h3>
<p id="since"></p>
<p id="monthlyPregreet"></p>
<p id="monthlyNoqueue"></p>
<p id="monthlyQuarantine"></p>
<p id="monthlySpam"></p>
<p id="monthlyHam"></p>
<p style="font-weight:bold;" id="monthlySpam"></p>
<p style="font-weight:bold;" id="monthlyHam"></p>
<p id="ratio"></p>
</div>
<script src="Chart.js"></script>
<script src="data.js"></script>
@ -50,6 +52,8 @@
document.getElementById('monthlyQuarantine').innerHTML = "Quarantined: " + data['monthlyQuarantine'];
document.getElementById('monthlySpam').innerHTML = "Total Spam: " + data['monthlySpam'];
document.getElementById('monthlyHam').innerHTML = "Total Ham: " + data['monthlyHam'];
document.getElementById('since').innerHTML = "Starting on " + data['since'];
document.getElementById('ratio').innerHTML = "Ratio: 1:" + (data['monthlySpam'] / data['monthlyHam']).toFixed(0);
</script>
</body>
</html>

View file

@ -85,16 +85,26 @@ func load (dataset DataMap, date string, str string, num int) ( DataMap ) {
func main() {
// Begin Arguments
sourceFile := flag.String("source", "/var/log/spam.log", "The path to the spam log")
outfile := flag.String("out", "data.js", "The path to the file you want to output.")
hamColor := flag.String("hamcolor","rgba(80,220,80,1)","The color of the ham graph.")
hamFill := flag.String("hamfill","rgba(80,220,80,0.2)","The fill color of the ham graph.")
quarantineColor := flag.String("quarantinecolor","rgba(220,80,80,1)","The line color of the quarantine graph.")
quarantineFill := flag.String("quarantinefill","rgba(220,80,80,0.2)","The fill color of the quarantine graph.")
noqueueColor := flag.String("noqueuecolor","rgba(220,150,80,1)","The line color of the noqueue graph.")
noqueueFill := flag.String("noqueuefill","rgba(220,150,80,0.2)","The fill color of the noqueue graph.")
pregreetColor := flag.String("pregreetcolor","rgba(220,200,80,1)","The line color of the pregreet graph.")
pregreetFill := flag.String("pregreetfill","rgba(220,200,80,0.2)","The fill color of the pregreet graph.")
sourceFile := flag.String("source", "/var/log/spam.log",
"The path to the spam log")
outfile := flag.String("out", "data.js",
"The path to the file you want to output.")
hamColor := flag.String("hamcolor","rgba(80,220,80,1)",
"The color of the ham graph.")
hamFill := flag.String("hamfill","rgba(80,220,80,0.2)",
"The fill color of the ham graph.")
quarantineColor := flag.String("quarantinecolor","rgba(220,80,80,1)",
"The line color of the quarantine graph.")
quarantineFill := flag.String("quarantinefill","rgba(220,80,80,0.2)",
"The fill color of the quarantine graph.")
noqueueColor := flag.String("noqueuecolor","rgba(220,150,80,1)",
"The line color of the noqueue graph.")
noqueueFill := flag.String("noqueuefill","rgba(220,150,80,0.2)",
"The fill color of the noqueue graph.")
pregreetColor := flag.String("pregreetcolor","rgba(220,200,80,1)",
"The line color of the pregreet graph.")
pregreetFill := flag.String("pregreetfill","rgba(220,200,80,0.2)",
"The fill color of the pregreet graph.")
flag.Parse()
// End Arguments
@ -107,6 +117,7 @@ func main() {
// Start semi-constants
aWeekAgo := time.Now().AddDate(0,0,-8)
aMonthAgo := time.Now().AddDate(0,0,-31)
dateFormat := "2006-01-02"
// End semi-constants
// Start temporary maps
@ -121,7 +132,6 @@ func main() {
return
} // if err != nil
dateFormat := "2006-01-02"
date, _ := time.Parse(dateFormat, val[0])
if date.After(aWeekAgo) {
@ -158,6 +168,16 @@ func main() {
monthlySpam := monthlyPregreet + monthlyNoqueue + monthlyQuarantine
sinceDate := time.Now().AddDate(10,0,0)
for k := range monthly {
date, _ := time.Parse(dateFormat, k)
if date.Before(sinceDate) {
sinceDate = date
} // if date.Before(since)
} // for k in monthly
var since string
since = sinceDate.Format(dateFormat)
var labels []string
for k := range weekly {
labels = append(labels, k)
@ -304,6 +324,10 @@ func main() {
buffer.WriteString("\tmonthlyHam: \"")
buffer.WriteString(strconv.Itoa(monthlyHam))
buffer.WriteString("\",\n")
buffer.WriteString("\tsince: \"")
buffer.WriteString(since)
buffer.WriteString("\"\n")
buffer.WriteString("};\n\n")