From 5598b2f6150f31d59d53afc5caaebe96a00f4f2b Mon Sep 17 00:00:00 2001 From: Andrew Davidson Date: Sat, 9 May 2015 21:34:29 -0400 Subject: [PATCH] adding sinceDate --- index.html | 8 ++++++-- spamalytics.go | 46 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 836b0a1..c212748 100644 --- a/index.html +++ b/index.html @@ -21,11 +21,13 @@

Last 30 Days

+

-

-

+

+

+

@@ -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); diff --git a/spamalytics.go b/spamalytics.go index 2866d79..754be0e 100644 --- a/spamalytics.go +++ b/spamalytics.go @@ -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")